def test_isnot_stealthy(self): self.alarm['steps'].append({ '_t': 'stateinc', 't': 0, 'a': 'test', 'm': 'test', 'val': Check.CRITICAL }) self.alarm['state'] = { '_t': 'statedec', 't': 601, 'a': 'test', 'm': 'test', 'val': Check.OK } got = is_stealthy(self.manager, self.alarm) self.assertFalse(got)
def test_isnot_stealthy(self): self.alarm[AlarmField.steps.value].append({ '_t': 'stateinc', 't': 0, 'a': 'test', 'm': 'test', 'val': Check.CRITICAL }) self.alarm[AlarmField.state.value] = { '_t': 'statedec', 't': 601, 'a': 'test', 'm': 'test', 'val': Check.OK } got = is_stealthy(self.manager, self.alarm) self.assertFalse(got)
def test_is_stealthy(self): now = int(time()) self.alarm[AlarmField.steps.value].append({ '_t': 'stateinc', 't': now - 1, 'a': 'test', 'm': 'test', 'val': Check.CRITICAL }) self.alarm[AlarmField.state.value] = { '_t': 'statedec', 't': now, 'a': 'test', 'm': 'test', 'val': Check.OK } got = is_stealthy(self.manager, self.alarm) self.assertTrue(got)
def resolve_stealthy(self, alarms): """ Loop over all stealthy alarms, and check if it can be return to off status. :param alarms: a list of unresolved alarms :return: a list of unresolved alarms (excluding locally processed alarms) :deprecated: see canopsis.alarms """ self.logger.info("DEPRECATED: see the canopsis.alarms package instead.") for data_id in alarms: for docalarm in alarms[data_id]: docalarm[self.alerts_storage.DATA_ID] = data_id alarm = docalarm.get(self.alerts_storage.VALUE) # Only look at stealthy status if get_last_status(alarm) != STEALTHY: continue # Is the state stealthy still valid ? if is_stealthy(self, alarm): continue event = { 'timestamp': int(time()), # now 'output': 'automaticly resolved after stealthy shown time', 'connector': alarm['connector'], 'connector_name': alarm['connector_name'] } # Updating the alarm state alarm_new = self.change_of_status( docalarm, STEALTHY, OFF, event ) self.update_current_alarm(docalarm, alarm_new['value']) alarms[data_id].remove(docalarm) return alarms