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.
#!/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`
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"
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
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
'''
print "getSiteNodes: %s" % exc
return nodelist
+
def getPersons(filter=None, fields=None):
api = xmlrpclib.Server(auth.server, verbose=False, allow_none=True)
persons = []