From: Stephen Soltesz Date: Tue, 14 Oct 2008 19:06:59 +0000 (+0000) Subject: Changes emails sent from tech- and pi- aliases to the actual registered email X-Git-Tag: Monitor-1.0-11~3 X-Git-Url: http://git.onelab.eu/?a=commitdiff_plain;h=5ff2eaddf7644ac7ffddfe536ba9e50aa7529273;hp=a03201adf84a720dcf1b527465d0fc93d3841bc7;p=monitor.git Changes emails sent from tech- and pi- aliases to the actual registered email addresses of the users. added functions for fetching these addresses to plc.py added a check to create act_all db if it does not already exist in automate-default.sh script. --- diff --git a/automate-default.sh b/automate-default.sh index 1aaeb59..8e7be9c 100755 --- a/automate-default.sh +++ b/automate-default.sh @@ -1,7 +1,10 @@ #!/bin/bash # NOTE: Must be an absolute path to guarantee it is read. -source /usr/share/monitor-server/monitorconfig.py +INSTALLPATH=/usr/share/monitor-server/ +# Generate an 'sh' style file full of variables in monitor.conf +$INSTALLPATH/shconfig.py > $INSTALLPATH/monitorconfig.sh +source $INSTALLPATH/monitorconfig.sh cd ${MONITOR_SCRIPT_ROOT} set -e DATE=`date +%Y-%m-%d-%T` @@ -29,6 +32,15 @@ if [ -f $MONITOR_PID ] ; then fi echo $$ > $MONITOR_PID +# SETUP act_all database if it's not there. +if [ ! -f ${MONITOR_SCRIPT_ROOT}/actallsetup.flag ]; then + if ! python -c 'import database; database.dbLoad("act_all")' 2>/dev/null ; then + python -c 'import database; database.dbDump("act_all", {})' 2>/dev/null ; then + touch ${MONITOR_SCRIPT_ROOT}/actallsetup.flag + fi +fi + + AGENT=`ps ax | grep ssh-agent | grep -v grep` if [ -z "$AGENT" ] ; then echo "starting ssh agent" diff --git a/monitor_policy.py b/monitor_policy.py index f7c3edb..45242ea 100644 --- a/monitor_policy.py +++ b/monitor_policy.py @@ -937,18 +937,22 @@ class Action: if ADMIN & roles: contacts += [config.email] if TECH & roles: - contacts += [TECHEMAIL % loginbase] + #contacts += [TECHEMAIL % loginbase] + contacts += plc.getTechEmails(loginbase) if PI & roles: - contacts += [PIEMAIL % loginbase] + #contacts += [PIEMAIL % loginbase] + contacts += plc.getPIEmails(loginbase) if USER & roles: + contacts += plc.getSliceUserEmails(loginbase) slices = plc.slices(loginbase) if len(slices) >= 1: - for slice in slices: - contacts += [SLICEMAIL % slice] print "SLIC: %20s : %d slices" % (loginbase, len(slices)) else: print "SLIC: %20s : 0 slices" % loginbase + unique_contacts = set(contacts) + contacts = [ c for c in unique_contacts ] # convert back into list + try: subject = message[0] % args body = message[1] % args diff --git a/plc.py b/plc.py index 783efbc..db14f50 100644 --- a/plc.py +++ b/plc.py @@ -67,6 +67,50 @@ def getAPI(url): def getAuthAPI(): return PLC(auth.auth, auth.server) + +def getTechEmails(loginbase): + """ + For the given site, return all user email addresses that have the 'tech' role. + """ + api = getAuthAPI() + # get site details. + s = api.GetSites(loginbase)[0] + # get people at site + p = api.GetPersons(s['person_ids'])[0] + # pull out those with the right role. + emails = [ person['email'] for person in filter(lambda x: 'tech' in x['roles'], p) ] + return emails + +def getPIEmails(loginbase): + """ + For the given site, return all user email addresses that have the 'tech' role. + """ + api = getAuthAPI() + # get site details. + s = api.GetSites(loginbase)[0] + # get people at site + p = api.GetPersons(s['person_ids'])[0] + # pull out those with the right role. + emails = [ person['email'] for person in filter(lambda x: 'pi' in x['roles'], p) ] + return emails + +def getSliceUserEmails(loginbase): + """ + For the given site, return all user email addresses that have the 'tech' role. + """ + #api = getAuthAPI() + # get site details. + s = api.GetSites(loginbase)[0] + # get people at site + slices = api.GetSlices(s['slice_ids']) + people = [] + for slice in slices: + people += api.GetPersons(slice['person_ids']) + # pull out those with the right role. + emails = [ person['email'] for person in filter(lambda x: 'pi' in x['roles'], people) ] + unique_emails = [ x for x in set(emails) ] + return unique_emails + ''' Returns list of nodes in dbg as reported by PLC ''' @@ -138,6 +182,7 @@ def getSiteNodes(loginbase, fields=None): print "getSiteNodes: %s" % exc return nodelist + def getPersons(filter=None, fields=None): api = xmlrpclib.Server(auth.server, verbose=False, allow_none=True) persons = []