Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #92: Update monitoring with notification throttling #93

Merged
merged 10 commits into from
Dec 11, 2018
Prev Previous commit
Next Next commit
Issue #92 - Small refactoring of enable_monitoring function
aywaldron committed Dec 4, 2018

Verified

This commit was signed with the committer’s verified signature.
seunghwak Seunghwa Kang
commit 6dc359adf7cf2ea1bc7099a17b97c8c2a46db6e2
20 changes: 11 additions & 9 deletions ait/gui/__init__.py
Original file line number Diff line number Diff line change
@@ -389,9 +389,9 @@ def telem_handler(session):
for k, v in tlm.getDefaultDict().iteritems():
packet_dict[v.uid] = v

notif_thrshld = cfg.AitConfig().get('notifications.options.threshold')
if cfg.AitConfig().get('notifications.options.frequency'):
notif_freq = cfg.AitConfig().get('notifications.options.frequency')
notif_thrshld = ait.config.get('notifications.options.threshold')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's go ahead and set sane defaults here. Otherwise the behavior could end up being a bit off. For instance, as is the notif_thrshld variable ends up set as None if my config doesn't have a value for notifications.options.threshold and I enable monitoring.

You can do this with a one line for both of these values

notif_thrshld = ait.config.get('notifications.options.threshold', 1)
notif_freq = ait.config.get('notifications.options.frequency', float('inf'))

if ait.config.get('notifications.options.frequency'):
notif_freq = ait.config.get('notifications.options.frequency')
else:
notif_freq = float('inf')

@@ -419,21 +419,23 @@ def telem_handler(session):
log.error(msg)

limit_trip_repeats[packet.name][field] += 1
repeats = limit_trip_repeats[packet.name][field]

if (limit_trip_repeats[packet.name][field] == notif_thrshld or
(limit_trip_repeats[packet.name][field] - notif_thrshld)
% notif_freq == 0):
if (repeats == notif_thrshld or
(repeats > notif_thrshld and
(repeats - notif_thrshld) % notif_freq == 0)):
notify.trigger_notification('limit-error', msg)

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

limit_trip_repeats[packet.name][field] += 1
repeats = limit_trip_repeats[packet.name][field]

if (limit_trip_repeats[packet.name][field] == notif_thrshld or
(limit_trip_repeats[packet.name][field] - notif_thrshld)
% notif_freq == 0):
if (repeats == notif_thrshld or
(repeats > notif_thrshld and
(repeats - notif_thrshld) % notif_freq == 0)):
notify.trigger_notification('limit-warn', msg)

else: