首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如果预期的计划报告电子邮件尚未到达,则会收到警告

如果预期的计划报告电子邮件尚未到达,则会收到警告
EN

Stack Overflow用户
提问于 2011-01-14 16:41:22
回答 2查看 706关注 0票数 6

我(像大多数技术管理员一样,我猜)在我的收件箱里有相当多来自预定服务的状态信息。但是,当一个服务电子邮件失败时,显然不会发送任何电子邮件。所以我只是想要一个查看我收件箱的服务,告诉我“嘿,这个服务昨天没有发送电子邮件报告--有些地方不对劲!”

我想这个问题应该在某个地方解决了。也许Gmail (或其他电子邮件提供商)也有这样的服务,那就太好了。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2011-02-07 02:56:23

有一个像Nagios这样的集中式监控解决方案不是更好的选择吗?您可以这样配置,它只在服务错过其心跳、达到高水位线、耗尽燃料时发送通知?然后偏离第二个监控解决方案的路线,监控主要监控解决方案...

http://www.nagios.org/documentation

我不知道您描述的任何服务,但手动例程可能如下所示:

具有如下的文件夹/标记结构:

代码语言:javascript
复制
Services\Hourly-[NumberOfServices] (or add a folder per service)
Services\Daily-[NumberOfServicves]
Services\Weekly-[NumberOfServicves]
Services\Monthly-[NumberOfServicves]

具有接收邮件的规则,以筛选每个特定的服务通知,并根据其预期时间将其移动到正确的文件夹中。

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

在0:00叫醒,并检查是否有未读的邮件在您的每日文件夹。等等。

在0:00和星期六起床,检查你的Weekly文件夹中是否有未读的邮件。等等……

在每月一号的0:00起床,检查你的Weekly文件夹中是否有未读的邮件。等等等等。

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

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

代码语言:javascript
复制
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");
            }
}
票数 3
EN

Stack Overflow用户

发布于 2011-02-09 02:23:24

你提到了Gmail,所以你可能会对googlecl感兴趣,它为你提供了像Google Calendar和Docs这样的命令行控制。不幸的是,它们还不支持Gmail,但如果你的长期偏好是使用Gmail账户作为状态报告的中心,那么googlecl可能是你最好的选择。

在短期内,您可以使用Calendar、Blogger或Docs的命令立即尝试googlecl,所有这些都已经被支持。例如,这些命令将事件添加到Google Calendar:

代码语言:javascript
复制
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"

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

代码语言:javascript
复制
google calendar list --fields title,when,where --cal "commitments"
google calendar list -q party --cal ".*"

仔细想想,你甚至会发现Calendar、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“标签”的十个最新电子邮件:

代码语言:javascript
复制
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()

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

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/4689288

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档