Skip to content

Commit

Permalink
Issue #22 - Add telemetry limit monitoring and user notification support
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
MJJoyce committed Apr 23, 2018
1 parent aebae5b commit 939f608
Showing 1 changed file with 50 additions and 2 deletions.
52 changes: 50 additions & 2 deletions bliss/gui/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
import geventwebsocket

import bdb
import collections
from collections import defaultdict
import copy
import datetime
import json
Expand All @@ -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


Expand All @@ -89,6 +89,7 @@ class HTMLRoot:

App = bottle.Bottle()
Servers = [ ]
Monitor_Greenlet = None

bottle.debug(True)
bottle.TEMPLATE_PATH.append(HTMLRoot.User)
Expand Down Expand Up @@ -339,6 +340,8 @@ def cleanup():
for s in Servers:
s.stop()

cleanup_monitoring()


def startBrowser(url, name=None):
browser = None
Expand Down Expand Up @@ -367,6 +370,51 @@ 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():
global Monitor_Greenlet

if Monitor_Greenlet: Monitor_Greenlet.kill()


Sessions = SessionStore()


Expand Down

0 comments on commit 939f608

Please sign in to comment.