【问题标题】:Get a warning if an expected schedule report email hasnt arrived [closed]如果预期的时间表报告电子邮件尚未到达,则会收到警告[关闭]
【发布时间】:2011-01-14 08:41:21
【问题描述】:

我(就像我猜的大多数技术管理员一样)在我的收件箱中有很多来自预定服务的状态信息。但是,当一封服务电子邮件失败时,显然没有发送电子邮件。所以我只是想要一个服务查看我的收件箱说“嘿,这个服务昨天没有发送电子邮件报告 - 出了点问题!”。

我猜这个问题应该在某个地方解决。也许 Gmail(或其他一些电子邮件提供商)有这种服务,那会很棒。

【问题讨论】:

    标签: reporting-services gmail scheduling


    【解决方案1】:

    拥有像 Nagios 这样的集中式监控解决方案不是更好的选择,您将其配置为仅在服务错过其心跳、达到高水位线、耗尽燃料时才发送通知?然后是监控主监控解决方案的第二个监控解决方案....

    http://www.nagios.org/documentation

    我不知道您描述的任何服务,但手动例程可能是这样的:

    有一个这样的文件夹/标签结构:

    Services\Hourly-[NumberOfServices] (or add a folder per service)
    Services\Daily-[NumberOfServicves]
    Services\Weekly-[NumberOfServicves]
    Services\Monthly-[NumberOfServicves]
    

    为收到的邮件制定规则以过滤每个特定的服务通知,并根据其预期时间将其移动到正确的文件夹。

    每小时唤醒并检查您的每小时文件夹中是否有未读邮件。未读的数量应该与文件夹中提到的 NumberOfServices 相同。阅读/处理它们并确保将它们全部标记为已读。任何未通过电子邮件发送的服务都很容易被发现。

    0:00 起床,检查您的每日文件夹中是否有未读邮件。等等等等。

    在 0:00 和周六醒来,检查您的每周文件夹中是否有未读邮件。等等……

    每月第一天 0:00 起床,检查您的每周文件夹中是否有未读邮件。等等等等……

    我的建议是减少服务产生的噪音。

    如果您仍然觉得需要服务,我只能提供一个非常基本的.Net 实现,大致基于上述过程并与 gmail 一起使用... 这也可以移植到 powershell...

    static void Main(string[] args)
            {
                var resolver = new XmlUrlResolver
                {
                    Credentials = new NetworkCredential("yourgoolgeaccount", "yourpassword")
                };
    
                var settings = new XmlReaderSettings();
    
                settings.XmlResolver = resolver;
    
                var xr = XmlReader
                    .Create("https://mail.google.com/mail/feed/atom/[name of your filter]"
                    , settings);
    
                var navigator = new XPathDocument(xr).CreateNavigator();
    
                var ns = new XmlNamespaceManager(new NameTable());
                ns.AddNamespace("fd", "http://purl.org/atom/ns#");
    
                var fullcountNode =  navigator.SelectSingleNode(
                    "/fd:feed/fd:fullcount"
                    , ns);
    
                Console.WriteLine(fullcountNode.Value);
    
                int fullcount = Int32.Parse(fullcountNode.Value);
                int expectCount = 10;
    
                if (expectCount > fullcount)
                {
                    Console.WriteLine("*** NOT EVERY ONE REPORTED BACK");
                }
    }
    

    【讨论】:

    • 非常有趣,谢谢。我自己也喜欢 gmail atom 阅读器。会试一试。 Nagios 似乎有点复杂(?)
    • @joeriks 好吧,您的要求和工具之间总是需要权衡取舍,但我在 30 分钟内就在 debian vpc 上启动并运行了 nagios,并在一小时内让我的整个团队向我的整个团队发送垃圾邮件。 .
    【解决方案2】:

    您提到了 Gmail,因此您可能对 googlecl 感兴趣,它为您提供了诸如 Google 日历和文档之类的命令行控件。不幸的是,他们还不支持 Gmail,但如果您长期偏好使用 Gmail 帐户作为状态报告的中心,那么 googlecl 可能是您的最佳选择。

    在短期内,您现在可以使用日历、Blogger 或 Docs 的命令试用 googlecl,所有这些命令都已受支持。例如,这些命令将事件添加到 Google 日历:

    google calendar add --cal server1 "I'm still alive at 13:45 today"
    google calendar add "Server 1 is still alive at 2011-02-08 19:43"
    

    ...这些命令查询日历:

    google calendar list --fields title,when,where --cal "commitments"
    google calendar list -q party --cal ".*"
    

    想一想,您甚至可能会发现日历、Blogger 或 Docs 比 Gmail 更适合用于跟踪状态更新。例如,电子表格或日历格式应该更容易生成给定服务何时启动或停止的图形表示。

    您仍然需要编写一个使用 googlecl 来查询日历(或博客、文档或其他任何内容)的小程序,但是一旦您有简单的命令行可供使用,剩下的就应该很简单了。以下是有关 googlecl 的更多信息的链接:

    http://code.google.com/p/googlecl/

    如果您真的想使用 Gmail 并立即使用,他们提供了 IMAP 界面。使用 IMAP,您可以执行许多简单的操作,例如确定是否存在包含指定主题行的消息。这是了解详细信息的好地方:

    http://mail.google.com/support/bin/answer.py?hl=en&answer=75725

    这是一个使用 IMAP 和 Python 列出具有给定 Gmail“标签”的最近的十封电子邮件的快速示例:

    
    
    import getpass, imaplib
    # These gmail_* utilties are from https://github.com/drewbuschhorn/gmail_imap                                                                                                   
    import gmail_mailboxes, gmail_messages, gmail_message
    
    # Update these next lines manually, or turn them into parms or somesuch.                                                                                                        
    gmail_account_name = "your_user_name@gmail.com" # Your full gmail address.                                                                                                      
    mailbox_name = "StatusReports" # Use Gmail "labels" to tag the relevant msgs.                                                                                                   
    
    class gmail_imap:
        def __init__ (self, username, password):
            self.imap_server = imaplib.IMAP4_SSL("imap.gmail.com",993)
            self.username = username
            self.password = password
            self.loggedIn = False
            self.mailboxes = gmail_mailboxes.gmail_mailboxes(self)
            self.messages = gmail_messages.gmail_messages(self)
        def login (self):
            self.imap_server.login(self.username,self.password)
            self.loggedIn = True
        def logout (self):
            self.imap_server.close()
            self.imap_server.logout()
            self.loggedIn = False
    
    # Right now this prints a summary of the most-recent ten (or so) messages                                                                                                       
    # which have been labelled in Gmail with the string found in mailbox_name.                                                                                                      
    # It won't work unless you've used Gmail settings to allow IMAP access.                                                                                                         
    if __name__ == '__main__':
        gmail = gmail_imap(gmail_account_name,getpass.getpass())
        gmail.messages.process(mailbox_name)
        for next in gmail.messages: 
          message = gmail.messages.getMessage(next.uid)
          # This is a good point in the code to insert some kind of search                                                                                                          
          # of gmail.messages.  Instead of unconditionally printing every                                                                                                           
          # entry (which is what the code below does), issue some sort of                                                                                                           
          # warning if the expected email (message.From and message.Subject)                                                                                                        
          # did not arrive within the expected time frame (message.date).                                                                                                           
          print message.date, message.From, message.Subject
        gmail.logout()
    

    如代码 cmets 中所述,如果该邮箱中的最新消息不包含预期消息,您可以对其进行调整以发出某种警告。然后只需每天(或您需要的任何时间段)运行 Python 程序一次,以查看是否从未收到预期的电子邮件。

    【讨论】:

    • 好的。我喜欢使用电子表格进行漂亮的视觉表示的想法——谷歌电子表格 API 很好。我也许可以在工作表的第一列中设置规则,并让服务在某处运行,每天在列中填写状态。如果状态总和不符合预期,另一个服务会报告。但是 - 我真的希望有一个现成的解决方案。
    猜你喜欢
    • 2018-08-02
    • 1970-01-01
    • 2022-07-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-16
    • 1970-01-01
    相关资源
    最近更新 更多