Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Once the take-action time is reached in wc_checkAlarms there will be …
…only three reminder e-mails in the take-action time interval, so, spamming of alarm e-mails is prevented; not yet successfully implemented a solution to recognize and remove 'zombi alarms', alarms that are acknowledged/solved and deleted right away without the tool noticing it.
  • Loading branch information
weiher committed Aug 4, 2017
1 parent 4c9acce commit 49b4c7b
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 4 deletions.
6 changes: 5 additions & 1 deletion alarm.py
Expand Up @@ -5,11 +5,15 @@ class alarm:

def __init__(self, date, age, standort, message, quelle, bestaetigtVon, kategorie, status):
self.date = date
#self.time = time
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.firstNotification = False
self.reminderNotification = 0
41 changes: 38 additions & 3 deletions wc_checkAlarms.py
Expand Up @@ -125,7 +125,7 @@ def main(args):
sys.exit(1)
checkForNewAlarmsInterval = interval

takeActionDefault = 10.0
takeActionDefault = 20.0
errorMessage = "No time to take action specified. Provide one via '-a my_takeAction' or {..., 'takeAction':'my_takeAction', ...} " \
"or WC_ALARMS_TAKEACTION=my_takeAction. Using a default now: " + str(takeActionDefault) + " minutes"
try:
Expand Down Expand Up @@ -240,6 +240,7 @@ def main(args):
# the check/solution to a prior alarm with status e.g. 'unnormal':
removedAlarm = False
for a in alarmsActive:

if a.quelle == quelle:
# Remove alarm from running and do not append to checked
removedAlarm = True
Expand All @@ -258,11 +259,16 @@ def main(args):
# This alarm is already known; move on to the next alarm
alarmAlreadyKnown = True
# Observe the age of the alarm, i.e, increase the age by the time interval in which new alarms are caught
#a.oldAge = a.age
a.age += checkForNewAlarmsInterval
a.stillActive = True
if not alarmAlreadyKnown:
if verbosity: print('Appending alarm ' + str(date) + ' ' + quelle + ' to alarmsActive')
age = 0.0
alarmsActive.append(alarm(date, age, standort, message, quelle, bestaetigtVon, kategorie, status))
#alarmsActive.append(alarm(date, age, standort, message, quelle, bestaetigtVon, kategorie, status))
a = alarm(date, age, standort, message, quelle, bestaetigtVon, kategorie, status)
a.stillActive = True
alarmsActive.append(a)

if verbosity:
if alarmsChecked:
Expand All @@ -273,18 +279,47 @@ def main(args):

if alarmsActive:
for a in alarmsActive:

# Remove "Zombi alarms":
#if a.age == a.oldAge:
if not a.stillActive:
print("This alarm seems to have been solved and deleted so we're removing it from the list of active alarms:")
print(a)
alarmsActive.remove(a)
continue

if verbosity:
print(a.date, a.standort, a.message, a.quelle, a.bestaetigtVon, a.kategorie, a.status)
print 'Age: ' + str(a.age)
print 'a.reminderNotification= ' + str(a.reminderNotification)
print 'a.firstNotification= ' + str(a.firstNotification)

numberOfReminders = 3
if not a.firstNotification:
# The first notification mail about an alarm
a.firstNotification = True
a.reminderNotification = 0

# Check the age of the still active alarms and take action in case of, for example, the age is greater than e.g. 20 min
if a.age >= takeActionTime:
#if a.age >= takeActionTime:
if a.age >= takeActionTime and (a.age % takeActionTime == 0) and a.reminderNotification < numberOfReminders+1:
currentHour = datetime.datetime.now().hour
mailAddress = getMailAddress(currentHour, settings['WC_ALARMS_ALERT_EMAIL'], settings['WC_ALARMS_ALERT_PERIODS'])
if verbosity: print 'Sending an e-mail to ' + mailAddress
sendEmail(mailAddress, a.date, a.standort, a.message, a.quelle)

if a.firstNotification and (a.age % takeActionTime == 0) and 0 <= a.reminderNotification < numberOfReminders + 1:
# Only send a small amount of reminder mails about an alarm because we don't want the recipient to get spamed
a.reminderNotification += 1

for a in alarmsActive:
a.stillActive = False

else:
if verbosity: print('No alarms in list alarmsActive')

if verbosity: print('-----------------------------------------------------------------------------------------')

# sleep for n minutes
sleep(checkForNewAlarmsInterval*60)

Expand Down

0 comments on commit 49b4c7b

Please sign in to comment.