Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/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
# The following line only works if the number of args is exactly four
#!name, ip, state, mess = args
# The following lines allow Dohn to add arguments without breaking the script
name = args[0]
ip = args[1]
state = args[2]
mess = args[3]
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# 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: