def process(self, input_data, topic=None, **kwargs): try: load = pickle.loads(input_data) pkt_id, pkt_data = int(load[0]), load[1] packet = self.packet_dict[pkt_id] decoded = tlm.Packet(packet, data=bytearray(pkt_data)) except Exception as e: log.error('TelemetryLimitMonitor: {}'.format(e)) log.error( 'TelemetryLimitMonitor received input_data that it is unable to process. Skipping input ...' ) return if packet.name in self.limit_dict: for field, defn in self.limit_dict[packet.name].iteritems(): v = decoded._getattr(field) if packet.name not in self.limit_trip_repeats.keys(): self.limit_trip_repeats[packet.name] = {} if field not in self.limit_trip_repeats[packet.name].keys(): self.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) self.limit_trip_repeats[packet.name][field] += 1 repeats = self.limit_trip_repeats[packet.name][field] if (repeats == self.notif_thrshld or (repeats > self.notif_thrshld and (repeats - self.notif_thrshld) % self.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) self.limit_trip_repeats[packet.name][field] += 1 repeats = self.limit_trip_repeats[packet.name][field] if (repeats == self.notif_thrshld or (repeats > self.notif_thrshld and (repeats - self.notif_thrshld) % self.notif_freq == 0)): notify.trigger_notification('limit-warn', msg) else: self.limit_trip_repeats[packet.name][field] = 0
def test_trigger_notification(send_email_mock, send_text_mock): ait.config._config['notifications'] = { 'email': { 'triggers': [ 'email-only-trigger', 'both-trigger' ] }, 'text': { 'triggers': [ 'text-only-trigger', 'both-trigger' ] } } notify.trigger_notification('email-only-trigger', 'foo') send_email_mock.assert_called() notify.trigger_notification('text-only-trigger', 'foo') send_text_mock.assert_called() send_email_mock.reset_mock() send_text_mock.reset_mock() notify.trigger_notification('both-trigger', 'foo') send_email_mock.assert_called() send_text_mock.assert_called()
def test_trigger_notification(send_email_mock, send_text_mock): ait.config._config["notifications"] = { "email": {"triggers": ["email-only-trigger", "both-trigger"]}, "text": {"triggers": ["text-only-trigger", "both-trigger"]}, } notify.trigger_notification("email-only-trigger", "foo") send_email_mock.assert_called() notify.trigger_notification("text-only-trigger", "foo") send_text_mock.assert_called() send_email_mock.reset_mock() send_text_mock.reset_mock() notify.trigger_notification("both-trigger", "foo") send_email_mock.assert_called() send_text_mock.assert_called()