Commit de58b952 authored by kpetersn's avatar kpetersn
Browse files

Added alived-notify on Oct 24, 2014

parent e8f1d00b
#!/APSshare/epd/rh6-x86_64/bin/python
import os
import sys
import urllib
import xml.etree.ElementTree as ET
#
email_dict = {
'Peterson':'kmpeters@anl.gov',
'Arms':'dohnarms@anl.gov',
'Kirchman':'jkirchman@aps.anl.gov',
'klang':'klang@aps.anl.gov',
'Goetze':'goetze@aps.anl.gov',
'Sluiter':'sluiter@aps.anl.gov',
'Sullivan':'sullivan@aps.anl.gov',
'WALSH':'twalsh@anl.gov'
}
def sendEmail(ioc, state, time_str, engineer):
global email_dict
# Alive web page
alive_url = "http://bcda.xray.aps.anl.gov/cgi-bin/ioc_alive.cgi"
# Kevin prefers different terminology
ioc_state = {'BOOT':'UP', 'FAIL':'DOWN'}[state]
# Build email
recipient = email_dict[engineer]
subject = "%s is %s" % (ioc, ioc_state)
message = "Snapshot time: %s\n\n" % time_str
message += "%s info:\n%s?ioc=%s\n\n" % (ioc, alive_url, ioc)
message += "%s IOCs:\n%s?eng=%s\n" % (engineer, alive_url, engineer)
# Build command
email_command = "echo \"%s\" | mailx -s \"%s\" %s" % (message, subject, recipient)
# Send email
os.system(email_command)
def main(args):
# Alive XML page
alive_xml_url = "http://bcda.xray.aps.anl.gov/cgi-bin/alivexml.cgi"
# Parse args
name, ip, state, mess = args
# Get the XLM file
try:
f = urllib.urlopen(alive_xml_url)
except IOError:
print "Couldn't open URL"
# Failure
return False
# Read XML from URL"
xml_string = f.read()
# Close URL
f.close()
#!print xml_string
# Parse the XML string
try:
root = ET.fromstring(xml_string)
except ET.ParseError:
print "Invalid XML file"
# Failure
return False
# Get the date and time
time_elem = root.find('time')
time_str = time_elem.text
engineer = ""
for ioc in root.findall('IOC'):
# Find ioc whose state has changed
if name == ioc.get('name'):
# Find ENGINEER env var
for env in ioc.findall('env'):
if env.get('name') == 'ENGINEER':
engineer = env.text
# No break is needed here, since ENGINEER only appears once for each IOC element
# Break the loop; the desired IOC has been found
break
# Send the email
sendEmail(name, state, time_str, engineer)
# Success
return True
if __name__ == '__main__':
if len(sys.argv) != 5:
print "Usage: an_hook.py <iocname> <ip> <status> <user_args>"
#!print sys.argv
else:
main(sys.argv[1:])
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment