Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Mostly modified and improved the functionality of sending reminder e-…
…mails in the wc_checkAlarms tool in cases of alarms
  • Loading branch information
weiher committed Aug 9, 2017
1 parent 230e5fb commit 4ef194f
Show file tree
Hide file tree
Showing 12 changed files with 157 additions and 66 deletions.
27 changes: 15 additions & 12 deletions EXAMPLES
Expand Up @@ -165,22 +165,25 @@ No time to take action specified. ...

webctrl/bin$ ./wc_checkAlarms -u wsdl -f SETTINGS -i 1 -t 1 -v
No password specified via -p. Please enter your WebCTRL login password now:
Appending alarm 2017-07-25 12:24:25 Geb.G KKUK Sekundr Pumpe Ansteuerung Strung to alarmsActive
Removing alarm 2017-07-25 12:24:37 Geb.G KKUK Sekundr Pumpe Ansteuerung Strung from alarmsActive
Appending alarm 2017-07-25 13:14:21 DI_Wasser_Sensor_Lichtschacht_TZ to alarmsActive
Appending alarm 2017-08-08 15:27:58 Geb.R Anlage 01 Sammelstrung to alarmsActive
No alarms in list alarmsChecked
(datetime.datetime(2017, 7, 25, 13, 14, 21), '/Fritz-Haber-Institut/Bauteil R/Meldungen/Geb.R Meldungen', 'Geb.R Wasser-Sensor Lichtschacht Technikzentrale Keller ausgelst!', 'DI_Wasser_Sensor_Lichtschacht_TZ', 'Nicht besttigt', 'Heizung, Lftung, Klimatechnik - Allgemein', 'Unnormal')
(datetime.datetime(2017, 8, 8, 15, 27, 58), u'/Fritz-Haber-Institut/Bauteil R/Lftung/Zuluftanlage/Geb.R Zuluftanlagex', u"Geb.R Anlage 01 Sammelstrung is in an alarm state of 'ON'.", u'Geb.R Anlage 01 Sammelstrung', u'Nicht besttigt', u'Heizung, Lftung, Klimatechnik - Allgemein', u'Unnormal')
Age: 0.0
Appending alarm 2017-07-25 12:24:25 Geb.G KKUK Sekundr Pumpe Ansteuerung Strung to alarmsActive
Removing alarm 2017-07-25 12:24:37 Geb.G KKUK Sekundr Pumpe Ansteuerung Strung from alarmsActive
a.reminderNotification= 0
a.firstNotification= False
-----------------------------------------------------------------------------------------
No alarms in list alarmsChecked
(datetime.datetime(2017, 7, 25, 13, 14, 21), '/Fritz-Haber-Institut/Bauteil R/Meldungen/Geb.R Meldungen', 'Geb.R Wasser-Sensor Lichtschacht Technikzentrale Keller ausgelst!', 'DI_Wasser_Sensor_Lichtschacht_TZ', 'Nicht besttigt', 'Heizung, Lftung, Klimatechnik - Allgemein', 'Unnormal')
(datetime.datetime(2017, 8, 8, 15, 27, 58), u'/Fritz-Haber-Institut/Bauteil R/Lftung/Zuluftanlage/Geb.R Zuluftanlagex', u"Geb.R Anlage 01 Sammelstrung is in an alarm state of 'ON'.", u'Geb.R Anlage 01 Sammelstrung', u'Nicht besttigt', u'Heizung, Lftung, Klimatechnik - Allgemein', u'Unnormal')
Age: 1.0
Sending an e-mail to weiher@fhi-berlin.mpg.de
Appending alarm 2017-07-25 12:24:25 Geb.G KKUK Sekundr Pumpe Ansteuerung Strung to alarmsActive
Removing alarm 2017-07-25 12:24:37 Geb.G KKUK Sekundr Pumpe Ansteuerung Strung from alarmsActive
a.reminderNotification= 1
a.firstNotification= True
-----------------------------------------------------------------------------------------
No alarms in list alarmsChecked
(datetime.datetime(2017, 7, 25, 13, 14, 21), '/Fritz-Haber-Institut/Bauteil R/Meldungen/Geb.R Meldungen', 'Geb.R Wasser-Sensor Lichtschacht Technikzentrale Keller ausgelst!', 'DI_Wasser_Sensor_Lichtschacht_TZ', 'Nicht besttigt', 'Heizung, Lftung, Klimatechnik - Allgemein', 'Unnormal')
(datetime.datetime(2017, 8, 8, 15, 27, 58), u'/Fritz-Haber-Institut/Bauteil R/Lftung/Zuluftanlage/Geb.R Zuluftanlagex', u"Geb.R Anlage 01 Sammelstrung is in an alarm state of 'ON'.", u'Geb.R Anlage 01 Sammelstrung', u'Nicht besttigt', u'Heizung, Lftung, Klimatechnik - Allgemein', u'Unnormal')
Age: 2.0
a.reminderNotification= 1
a.firstNotification= True
Sending an e-mail to weiher@fhi-berlin.mpg.de

-----------------------------------------------------------------------------------------
No alarms in list alarmsChecked
...
36 changes: 26 additions & 10 deletions Email.py
Expand Up @@ -6,31 +6,47 @@
from email.mime.text import MIMEText


def sendEmail (address, alarmDate, alarmLocation, alarmMessage, alarmSource):
def sendEmails (sourceAddress, addresses, alarmDate, alarmLocation, alarmMessage, alarmSource):

msg = MIMEMultipart()
msg['Subject'] = alarmMessage
msg['From'] = address
msg['To'] = address
msg['From'] = sourceAddress
msg['To'] = addresses
content = alarmMessage + '\n' + \
'Date: ' + str(alarmDate) + '\n' + \
'Location: ' + alarmLocation + '\n' + \
'Source: ' + alarmSource
msg.attach(MIMEText(content, 'plain'))

s = smtplib.SMTP('mail.fhi-berlin.mpg.de')
s.sendmail(address, address, msg.as_string())
s.sendmail(sourceAddress, addresses, msg.as_string())
s.quit()


def getMailAddress(currentHour, mailAddresses, timePeriods):
def getMailAddresses (currentHour, mailAddresses, timePeriods):

periods = timePeriods.split(',')
periods = timePeriods.split(';')

foundAPeriod = False
for n, period in enumerate(periods):
times = period.split('-')
if int(times[0]) <= currentHour < int(times[1]):
break
try:
times = period.split('-')
if int(times[0]) <= currentHour < int(times[1]):
foundAPeriod = True
break
except:
errorMessage = "ERROR: Something is wrong with the given period: " + period + " Please check it."
return errorMessage

if not foundAPeriod:
errorMessage = "ERROR: The current hour is not contained in any of the time periods specified in the SETTINGS file."
return errorMessage

try:
addresses = mailAddresses.split(';')
except IndexError:
errorMessage = "ERROR: There are no e-mails specified for the current time period, " + period + \
"Please check again the SETTINGS file"
return errorMessage

addresses = mailAddresses.replace(' ','').split(',')
return addresses[n]
14 changes: 12 additions & 2 deletions Environment.py
Expand Up @@ -6,12 +6,22 @@ def readSettings(file):
f = open(file, 'r')
settings = {}

keyEmails = ''
valueEmails = ''
for line in f:
if line.startswith('WC_'):
parts = line.replace(' ', '').replace('\n','').replace("'", "").split('=')
if line.startswith("WC_ALARMS_ALERT_EMAILS"):
# Concatenate all lines that contain the e-mail addresses (the key, we need only once)
parts = line.replace(" ", "").replace("\n","").replace("'", "").split("=")
keyEmails = parts[0]
valueEmails += parts[1]
elif line.startswith("WC_"):
parts = line.replace(" ", "").replace("\n","").replace("'", "").split("=")
key = parts[0]
value = parts[1]
settings[key] = value

# Finally add the key-value pair holding the e-mail addresses
settings[keyEmails] = valueEmails

f.close()
return settings
36 changes: 36 additions & 0 deletions README
Expand Up @@ -83,3 +83,39 @@ All required arguments (except the password for the WebCTRL login) need to be pa
The password cannot be given via the SETTINGS file. If the password is not specified via -p you will be prompted to
type it interactively. All optional arguments have default values which will be shown to you when using one of the tools.

More detailed explanation of the wc_checkAlarms tool
----------------------------------------------------

wc_checkAlarms checks for all alarms for a given node. For example, if '/trees/geographic' is chosen as node all alarms
in the FHI network are retrieved. The tool checks in an interval (-i option) for new alarms and the status of old
alarms. "Old alarms" are alarms that are already known to the tool but have not yet been acknowledged or solved. Once
an alarm is discovered in an "unnormal" state it is observed: Does it still exist? Has it changed its status? The
second parameter is the -t option: the time that needs to pass for an alarm until an action is taken, that is, until
an e-mail about this alarm is sent. This "take action interval" needs to be bigger than the check-for-new-alarms
interval. As it is done at the moment there will be two e-mails after an alarm has been discovered and while the alarm
remains unchecked. After these two e-mails there will be one e-mail every hour reminding of this alarm. The first two
e-mails go to a person lowest in the hierarchy. For every e-mail to follow the hierarchy increases until no more
increase is possible because no more hierarchies have been specified in the SETTINGS file. This could be a schema
for the setting of times and e-mails:

WC_ALARMS_ALERT_PERIODS = '8-16; 16-22; 22-8'
WC_ALARMS_ALERT_EMAILS = 'person1@hierarchy1.de, person2@hierarchy1.de, ... # person1@hierarchy2.de, ... #
person1@hierarchy3.de, person2@hierarchy3.de, ...;'
WC_ALARMS_ALERT_EMAILS = 'person1@hierarchy1.de, person2@hierarchy1.de, ... # person1@hierarchy2.de, ... #
person1@hierarchy3.de, person2@hierarchy3.de, ...;'
WC_ALARMS_ALERT_EMAILS = 'person1@hierarchy1.de, person2@hierarchy1.de, ... # person1@hierarchy2.de, ... #
person1@hierarchy3.de, person2@hierarchy3.de, ...'

A day is divided up into three time periods - all seperated by a colon(!). You can divide up the day in as many periods
as you like and the times do not necessarily need to be in chronologial order. WC_ALARMS_ALERT_EMAILS specifies the
e-mail addresses per time period (seperated by a colon) and per hierarchy within one time period (seperated by a '#').
More than one person will get a notification if you provide a comma-seperated list of e-mail addresses. You can
specifiy as many WC_ALARMS_ALERT_EMAILS as you like. Within the programm all WC_ALARMS_ALERT_EMAILS lines will be
concatenated. You could also make it really simpel. With the following setting the same person(s) will receive an
e-mail at any time of the day:

WC_ALARMS_ALERT_PERIODS = '0-24'
WC_ALARMS_ALERT_EMAILS = 'person1@hierarchy1.de, person2@hierarchy1.de, ...'

ATTENTION: You should specify as many WC_ALARMS_ALERT_EMAILS lines as there are time periods in
WC_ALARMS_ALERT_PERIODS as exemplified above.
16 changes: 9 additions & 7 deletions SETTINGS
Expand Up @@ -4,17 +4,19 @@ WC_NODE = '#km_speicher_fel'
WC_URL = 'https://webctrl.rz-berlin.mpg.de'
WC_VERBOSITY =

# wc_checkAlarms
WC_ALARMS_ALERT_EMAIL = 'weiher@fhi-berlin.mpg.de,weiher@fhi-berlin.mpg.de,weiher@fhi-berlin.mpg.de'
WC_ALARMS_ALERT_PERIODS = '8-16,16-22,22-8'
WC_ALARMS_INTERVAL =
WC_ALARMS_TAKEACTION =

# wc_getReport
WC_REPORT_TYPE = '~point-list-report'

# wc_getTrend
WC_TREND_STIME =
WC_TREND_ETIME =
WC_TREND_LIMIT =
WC_TREND_MAXREC =
WC_TREND_MAXREC =

# wc_checkAlarms
WC_ALARMS_INTERVAL =
WC_ALARMS_TAKEACTION =
WC_ALARMS_ALERT_PERIODS = '8-16;16-22; 22-8'
WC_ALARMS_ALERT_EMAILS = 'weiher@fhi-berlin.mpg.de # weiher@fhi-berlin.mpg.de # weiher@fhi-berlin.mpg.de;'
WC_ALARMS_ALERT_EMAILS = 'weiher@fhi-berlin.mpg.de # weiher@fhi-berlin.mpg.de # weiher@fhi-berlin.mpg.de;'
WC_ALARMS_ALERT_EMAILS = 'weiher@fhi-berlin.mpg.de # weiher@fhi-berlin.mpg.de'
4 changes: 2 additions & 2 deletions alarm.py
Expand Up @@ -6,14 +6,14 @@ class alarm:
def __init__(self, date, age, standort, message, quelle, bestaetigtVon, kategorie, status):
self.date = date
self.age = age
#self.oldAge = None
self.stillActive = False
self.standort = standort
self.message = message
self.quelle = quelle
self.bestaetigtVon = bestaetigtVon
self.kategorie = kategorie
self.status = status

self.stillActive = False
self.firstNotification = False
self.reminderNotification = 0
self.notificationHierarchy = 0

0 comments on commit 4ef194f

Please sign in to comment.