Skip to content

Commit

Permalink
Issue #92 - Update limit monitoring with checks for lowering repeat n…
Browse files Browse the repository at this point in the history
…otifications

Implements new limit trip notification 'threshold' config.
Notification only sent once per any number of consecutive
limit trips, and only after limit trip 'threshold' (required
number of consecutive tripping packets) has been met.
  • Loading branch information
aywaldron committed Dec 4, 2018
1 parent f9066bf commit 9c43ca8
Showing 1 changed file with 16 additions and 18 deletions.
34 changes: 16 additions & 18 deletions ait/gui/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,11 +389,11 @@ def telem_handler(session):
for k, v in tlm.getDefaultDict().iteritems():
packet_dict[v.uid] = v

notif_thrshld = cfg.AitConfig.get('notifications.options.threshold')

log.info('Starting telemetry limit monitoring')
try:
limit_trip_repeat = 0
prev_v = None
prev_defn = None
limit_trip_repeats = {}
while True:
if len(session.telemetry) > 0:
p = session.telemetry.popleft()
Expand All @@ -404,34 +404,32 @@ def telem_handler(session):
for field, defn in limit_dict[packet.name].iteritems():
v = decoded._getattr(field)

if type(v) is evr.EVRDefn:
v = v.name
if packet.name not in limit_trip_repeats.keys():
limit_trip_repeats[packet.name] = {}

if field not in limit_trip_repeats[packet.name].keys():
limit_trip_repeats[packet.name][field] = 0

if defn.error(v):
msg = 'Field {} error out of limit with value {}'.format(field, v)
log.error(msg)

if limit_trip_repeat < 30 and v == prev_v and defn == prev_defn:
limit_trip_repeat += 1
else:
limit_trip_repeat = 0
notify.trigger_notification('limit-error', msg)
limit_trip_repeats[packet.name][field] += 1

prev_v = v
prev_defn = defn
if limit_trip_repeats[packet.name][field] == notif_thrshld:
notify.trigger_notification('limit-error', msg)

elif defn.warn(v):
msg = 'Field {} warning out of limit with value {}'.format(field, v)
log.warn(msg)

if limit_trip_repeat < 30 and v == prev_v and defn == prev_defn:
limit_trip_repeat += 1
else:
limit_trip_repeat = 0
limit_trip_repeats[packet.name][field] += 1

if limit_trip_repeats[packet.name][field] == notif_thrshld:
notify.trigger_notification('limit-warn', msg)

prev_v = v
prev_defn = defn
else:
limit_trip_repeats[packet.name][field] = 0

gevent.sleep(0)
finally:
Expand Down

0 comments on commit 9c43ca8

Please sign in to comment.