Commit de58b952 authored by kpetersn's avatar kpetersn
Browse files

Added alived-notify on Oct 24, 2014

parent e8f1d00b
import os
import sys
import urllib
import xml.etree.ElementTree as ET
email_dict = {
def sendEmail(ioc, state, time_str, engineer):
global email_dict
# Alive web page
alive_url = ""
# 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
def main(args):
# Alive XML page
alive_xml_url = ""
# Parse args
name, ip, state, mess = args
# Get the XLM file
f = urllib.urlopen(alive_xml_url)
except IOError:
print "Couldn't open URL"
# Failure
return False
# Read XML from URL"
xml_string =
# Close URL
#!print xml_string
# Parse the XML string
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
# Send the email
sendEmail(name, state, time_str, engineer)
# Success
return True
if __name__ == '__main__':
if len(sys.argv) != 5:
print "Usage: <iocname> <ip> <status> <user_args>"
#!print sys.argv
Supports Markdown
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