Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get a warning if an expected schedule report email hasnt arrived [closed]

I (like most tech admins I guess) have quite a lot of status infos from scheduled services in my inbox. However when one service email fails there's obviously no email sent. So I simply want a service looking at my inbox saying "Hey this service did not send an email report yesterday - somethings wrong!".

This one should be solved somewhere I guess. Perhaps Gmail (or some other email provider) has a service of this kind, that would be great.

like image 337
joeriks Avatar asked Jan 14 '11 08:01

joeriks


2 Answers

Wouldn't it be a better option to have a centralized monitoring solution like Nagios that you configure in such way that it only send out notifications when a service misses its heartbeat, reaches highwatermarks, run out of fuel? And then off course of a second monitoring solution that monitors the main monitoring solution....

http://www.nagios.org/documentation

I'm not aware of any service you describe but a manual routine might go like this:

Have a folder/tag structure like this:

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

Have rules for incoming mail to filter each specific service notification and move it to the right folder based on its expected timing.

Wakeup every hour and check if there are unread messages in your Hourly folder. The number of unread should be the same as the NumberOfServices mentioned in the folder. Read/Process them and make sure to all mark them as Read. Any service that didn't e-mailed get's spotted easily.

Wakeup at 0:00 and check if there are unread messages in your Daily folder. etc etc..

Wakeup at 0:00 and Saturday and check if there are unread messages in your Weekly folder. etc.....

Wakeup at 0:00 on the first of the month and check if there are unread messages in your Weekly folder. etc etc etc...

My advice would be to cut down the noise generated by the services.

If you still feel you need a service I can only provide a very very basic .Net implementation roughly based on the above process and works with gmail... This is also portable to 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");
            }
}
like image 57
rene Avatar answered Nov 06 '22 20:11

rene


You mentioned Gmail, so you may be interested in googlecl, which gives you command-line controls for things like Google Calendar and Docs. Unfortunately they do not yet support Gmail, but if your long-term preference is to use a Gmail account as the hub of your status reports, then googlecl may be your best option.

In the short run, you can try out googlecl right now using the commands for Calendar, Blogger, or Docs, all of which are already supported. For example, these commands add events to Google Calendar:

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 these commands query the calendar:

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

Come to think of it, you may even find that Calendar, Blogger, or Docs are a more appropriate place than Gmail for tracking status updates. For example, a spreadsheet or calendar format should make it easier to generate a graphical representation of when a given service was up or down.

You still need to write a little program which uses googlecl to query the calendar (or blog, or docs, or whatever), but once you have simple command lines at your disposal, the rest should be pretty straightforward. Here's a link to further information about googlecl:

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

If you really want to use Gmail, and use it right now, they offer an IMAP interface. Using IMAP, you can perform numerous simple operations, such as determining if a message exists which contains a specified subject line. Here's one good place to learn about the details:

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

Here's a quick example that uses IMAP and Python to list the ten most-recent emails which have a given Gmail "Label":



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 = "[email protected]" # 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()

As noted in the code comments, you could adapt it to issue some sort of warning if the most-recent messages in that mailbox do not contain an expected message. Then just run the Python program once per day (or whatever time period you require) to see if the expected email message was never received.

like image 21
willdye Avatar answered Nov 06 '22 20:11

willdye