def newest_alarm(self): entry = self.newest_alarm_entry() if not entry: return None alarm = Alarm() alarm.from_dictionary(entry) return alarm
def newest_n_alarms(self,count): alarms = [] configs = self.newest_n_alarm_entries(count) for config in configs: alarm = Alarm() alarm.from_dictionary(config) alarms.append(alarm) return alarms
def poll_alarms(self): if not self._running: return ret_alarms = [] new_alarms = self.h_alarms.get_new_alarms() if new_alarms: for rsp in new_alarms: if rsp.is_critical(): al_type = 'Critical' else: al_type = 'Non-Critical' a = Alarm(id=rsp.unitnum(), type=al_type, source=rsp.unitnum(), data=rsp.message(), state=rsp.code(), timestamp=rsp.time()) ret_alarms.append(a) if self.generatebogus: # Generate bogus alarms roughly 1/16 of the time roll = self.rand.randint(1, 16) if roll == 16: how_many = 1 do_multiple = self.rand.randint(0, 1) if do_multiple: how_many = self.rand.randint(1, 10) if self.debug: print '%f: Generating %d random alarm(s).' % (time.time(), how_many) for i in range(0, how_many): is_not_crit = self.rand.randint(0, 4) if is_not_crit == 0: al_type = 'Critical' else: al_type = 'Non-Critical' a = Alarm(id='test_%.2d' % (i + 1), type=al_type, source=1, data='This is test alarm #%d.' % (i + 1), state=i, timestamp=time.time()) ret_alarms.append(a) if ret_alarms: ae = NewAlarmsEvent(self, ret_alarms) self.parent.event_generate(ae) # While we are at it, acknowledge any critical alarms. self.h_alarms.ack_critical_alarms() self.sid = scheduler.after(15, self.poll_alarms)
def _poll_alarms(self): # thread while 1: ideal_alarms = [] cpc_alarms = self._cpc_uhp_node.get_alarms() for cpc_alarm in cpc_alarms: if not isinstance(cpc_alarm, CpcAlarm): # could be None or Exception continue src = '%s:%s:%s,%s:%s' % (cpc_alarm.device_name, str(cpc_alarm.item), \ cpc_alarm.item_num, str(cpc_alarm.obj), \ cpc_alarm.obj_num) tm_tuple = (cpc_alarm.orig_date[0], cpc_alarm.orig_date[1], cpc_alarm.orig_date[2], \ cpc_alarm.orig_time[0], cpc_alarm.orig_time[1], 0, 0, 0, -1) tm_sec = time.mktime(tm_tuple) state = 'Not acked' if cpc_alarm.ack_date >= cpc_alarm.orig_date: state = 'Acked' type = 'Alarm' if cpc_alarm.type == 0: type = 'Notice' i = cpc_alarm.text.find('\x00') data = cpc_alarm.text[:i] ideal_alarm = Alarm(id=cpc_alarm.id, type=type, source=src, timestamp=tm_sec, data=data, state=state) ideal_alarms.append(ideal_alarm) msglog.log('mpx',msglog.types.INFO,'CPC Alarm: %s' % ideal_alarm.as_list()) # legal protection in case CPC eqpt fails or Costco doesn't see alarm if len(ideal_alarms) > 0: ae = NewAlarmsEvent(self, ideal_alarms) self.parent.event_generate(ae) for i in range(30): if self._go == 0: return time.sleep(1.0) return
def poll_alarms(self): if not self._running: return if debug > 1: print '%f: In poll_alarms().' % time.time() alarms = self.get_alarms() ret_alarms = [] for x in alarms: if not x in self.old_alarms: if debug: print 'Found a new alarm: %s' % str(x) # Note: @fixme: At some point we will probably do some filtering # on the "alarms" we get back from the BCU because apparently # they may include some event type information for which we # don't want to create an Alarm Event. FredD apparently # has the information for differentiating between events # and real alarms from a BCU. # Note: x looks like: # {'priority': '', 'ack': 'No', 'from': 'BCU-01', 'SN': 0, # 'date': 1068221677.0, 'type': 'Watchdog Timeout', # 'detail': '' # } a = Alarm(id=x['SN'], type=x['type'], source=x['from'], timestamp=x['date'], data=x['detail'], priority=x['priority'], acked=x['ack']) if debug: print 'Got new alarm: %s.' % str(a) ret_alarms.append(a) else: if debug: print 'Ignoring alarm, it has already been raised reported' if ret_alarms: self.parent.put_alarms(ret_alarms) # Note: @fixme: old_alarms should be a PDO so that we don't resend alarms # that have already been seen every time we start up. For now this # behavior may actually be useful for testing but probably will # not be a "feature" in the real world. self.old_alarms = alarms self.sid = scheduler.after(15, self.poll_alarms)
def test_alarm_1(self): a = Alarm(id=1, type='Non-Critical', source='1', data='Alarm generated by test_alarm_1', state=68, timestamp=time.time()) e = NewAlarmsEvent(self, [ a, ]) self.event_generate(e) alarm_text = self.accept_one_alarm(10) # Assert that "N/A" is not in the alarm text. if alarm_text.find('N/A') != -1: self.fail( "Alarm Message %r contains failed conversion text (%r)." % (alarm_text, "N/A")) return