From 5c3233ee87bb5b6dcbccc18fa5ed86972c0c1f91 Mon Sep 17 00:00:00 2001 From: Michael Joyce Date: Mon, 23 Apr 2018 12:39:45 -0700 Subject: [PATCH] Issue #22 - Add telemetry limit monitoring and user notification support Add `enable_monitoring` GUI function for toggling on telemetry limit monitoring via project's GUI initialization script. This Greenlet monitors all inbound telemetry that the GUI receives via a Session and sends limit notification triggers to the notification API when limit trips occur. --- bliss/gui/__init__.py | 50 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 48 insertions(+), 2 deletions(-) diff --git a/bliss/gui/__init__.py b/bliss/gui/__init__.py index 454bc4ee..e216e40b 100644 --- a/bliss/gui/__init__.py +++ b/bliss/gui/__init__.py @@ -44,7 +44,7 @@ import geventwebsocket import bdb -import collections +from collections import defaultdict import copy import datetime import json @@ -62,7 +62,7 @@ import bliss.core -from bliss.core import api, ccsds, cfg, cmd, dmc, evr, gds, limits, log, pcap, tlm +from bliss.core import api, ccsds, cfg, cmd, dmc, evr, gds, limits, log, notify, pcap, tlm from bliss.core import util @@ -89,6 +89,7 @@ class HTMLRoot: App = bottle.Bottle() Servers = [ ] +Monitor_Greenlet = None bottle.debug(True) bottle.TEMPLATE_PATH.append(HTMLRoot.User) @@ -339,6 +340,8 @@ def cleanup(): for s in Servers: s.stop() + cleanup_monitoring() + def startBrowser(url, name=None): browser = None @@ -367,6 +370,49 @@ def wait(): gevent.wait() +def enable_monitoring(): + global Monitor_Greenlet + + def telem_handler(session): + limit_dict = defaultdict(dict) + for k, v in limits.getDefaultDict().iteritems(): + packet, field = k.split('.') + limit_dict[packet][field] = v + + packet_dict = defaultdict(dict) + for k, v in tlm.getDefaultDict().iteritems(): + packet_dict[v.uid] = v + + while True: + if len(session.telemetry) > 0: + p = session.telemetry.popleft() + packet = packet_dict[p[0]] + decoded = tlm.Packet(packet, data=bytearray(p[1])) + + if packet.name in limit_dict: + for field, defn in limit_dict[packet.name].iteritems(): + v = decoded._getattr(field) + if defn.error(v): + msg = 'Field {} error out of limit with value {}'.format(field, v) + log.error(msg) + notify.trigger_notification('limit-error', msg) + raise gevent.GreenletExit() + elif defn.warn(v): + msg = 'Field {} warning out of limit with value {}'.format(field, v) + log.warn(msg) + notify.trigger_notification('limit-warn', msg) + raise gevent.GreenletExit() + + gevent.sleep(0) + + s = bliss.gui.Sessions.create() + Monitor_Greenlet = gevent.spawn(telem_handler, s) + + +def cleanup_monitoring(): + if Monitor_Greenlet: Monitor_Greenlet.kill() + + Sessions = SessionStore()