move files into function-specific directories
[monitor.git] / commands / mail.py
1 #!/usr/bin/python
2
3 import time
4 import sys
5 import os
6
7
8 def argv_to_dict(argv):
9         """
10                 NOTE: very bare-bones, no error checking, will fail easily.
11         """
12         d = {}
13         prev=None
14         for a in argv:
15                 if "--" in a:
16                         prev = a[2:]
17                 else:
18                         d[prev] = a
19         return d
20
21 if __name__ == '__main__':
22         f = open("/tmp/myopsmail", 'a')
23         f.write("mail %s %s\n" % (time.time(), " ".join(sys.argv[1:])))
24         f.close()
25
26         d = argv_to_dict(sys.argv[1:])
27         command_line="""/usr/bin/printf "%%b" "***** MyOpsNagios %(hostnotificationnumber)s *****\\n\\nNotification Type: %(notificationtype)s\\nHost: %(hostname)s\\nState: %(hoststate)s\\nAddress: %(hostaddress)s\\nInfo: %(hostoutput)s\\n\\nDate/Time: %(longdatetime)s\\n" | /bin/mail -S replyto=monitor@planet-lab.org -s "** %(notificationtype)s Host Alert: %(hostname)s is %(hoststate)s **" %(contactemail)s""" % d
28         os.system(command_line)
29
30