3 from nagiosobjects import *
9 def getContactsAndContactGroupsFor(lb, type, email_list, testing=True):
11 if len(email_list) == 0:
12 cg1 = ContactGroup(contactgroup_name="%s-%s" % (lb,type),
13 alias="%s-%s" % (lb,type))
19 for person in email_list:
22 person="soltesz+%s%s%s@cs.princeton.edu" % ( lb, type, count )
23 c1 = Contact(contact_name=person.replace("+", ""),
24 host_notifications_enabled=1,
25 service_notifications_enabled=1,
26 host_notification_period="24x7",
27 service_notification_period="24x7",
28 host_notification_options="d,r,s",
29 service_notification_options="c,w,r",
30 host_notification_commands="monitor-notify-host-by-email",
31 service_notification_commands="monitor-notify-service-by-email",
34 contact_list.append(c1)
35 person_list.append(person.replace("+",""))
37 cg1 = ContactGroup(contactgroup_name="%s-%s" % (lb,type),
38 alias="%s-%s" % (lb,type),
39 members=",".join(person_list))
41 contact_list.append(cg1)
46 print Command(command_name="monitor-notify-host-by-email",
47 command_line="""/usr/share/monitor/nagios/actions/mail.py --host 1 --servicenotificationnumber $SERVICENOTIFICATIONNUMBER$ --hostnotificationnumber $HOSTNOTIFICATIONNUMBER$ --notificationtype $NOTIFICATIONTYPE$ --hostname $HOSTNAME$ --hoststate $HOSTSTATE$ --hostaddress $HOSTADDRESS$ --hostoutput "$HOSTOUTPUT$" --longdatetime "$LONGDATETIME$" --notificationitype $NOTIFICATIONTYPE$ --contactemail $CONTACTEMAIL$""").toString()
49 print Command(command_name="monitor-notify-service-by-email",
50 command_line="""/usr/share/monitor/nagios/actions/mail.py --service 1 --servicenotificationnumber $SERVICENOTIFICATIONNUMBER$ --hostnotificationnumber $HOSTNOTIFICATIONNUMBER$ --notificationtype $NOTIFICATIONTYPE$ --hostname $HOSTNAME$ --hoststate $HOSTSTATE$ --hostaddress $HOSTADDRESS$ --hostoutput "$HOSTOUTPUT$" --longdatetime "$LONGDATETIME$" --notificationitype $NOTIFICATIONTYPE$ --servicedesc $SERVICEDESC$ --hostalias $HOSTALIAS$ --contactemail $CONTACTEMAIL$ --servicestate "$SERVICESTATE$" --serviceoutput "$SERVICEOUTPUT$" --contactgroupname $CONTACTGROUPNAME$ """).toString()
53 l_sites = plc.api.GetSites({'peer_id' : None})
54 #l_sites = plc.api.GetSites({'login_base' : ['asu', 'gmu', 'gt']})
55 #l_sites = plc.api.GetSites([10243, 22, 10247, 138, 139, 10050, 10257,
56 # 18, 20, 21, 10134, 24, 10138, 10141, 30, 31,
57 # 33, 10279, 41, 29, 10193, 10064, 81, 10194,
58 # 10067, 87, 10208, 10001, 233, 157, 10100, 10107])
64 for index,site in enumerate(l_sites):
65 shortname = site['abbreviated_name']
66 lb = site['login_base']
67 print >>sys.stderr, "Collecting emails for %s (%s/%s)" % (lb, index, len(l_sites))
69 # NOTE: do duplcate groups create duplicate emails?
70 cl1 = getContactsAndContactGroupsFor(lb, "techs", plc.getTechEmails(lb), test_emails)
71 cl2 = getContactsAndContactGroupsFor(lb, "pis", plc.getPIEmails(lb), test_emails)
72 # NOTE: slice users will change often.
73 cl3 = getContactsAndContactGroupsFor(lb, "sliceusers", plc.getSliceUserEmails(lb), test_emails)
75 for c in [cl1,cl2,cl3]: