def restore(manager, alarm, author, message, event): """ Called when an alarm is restored by a user. """ step = { '_t': 'uncancel', 't': event['timestamp'], 'a': author, 'm': message } canceled = alarm['canceled'] alarm['canceled'] = None alarm['steps'].append(step) status = None if manager.restore_event: status = get_last_status(alarm, ts=canceled['t']) else: status = compute_status(manager, alarm) return alarm, status
def restore(manager, alarm, author, message, event): """ Called when an alarm is restored by a user. """ step = { '_t': 'uncancel', 't': event['timestamp'], 'a': author, 'm': message, 'role': event.get('role', None) } canceled = alarm[AlarmField.canceled.value] alarm[AlarmField.canceled.value] = None alarm[AlarmField.steps.value].append(step) status = None if manager.restore_event: status = get_previous_step(alarm, ['statusinc', 'statusdec'], ts=canceled['t']) if status is not None: status = status['val'] else: # This is not supposed to happen since a restored alarm # should have a status before its cancelation status = OFF else: status = compute_status(manager, alarm) return alarm, status
def test_is_canceled(self): self.alarm['canceled'] = { '_t': 'cancel', 't': 0, 'a': 'test', 'm': 'test' } got = compute_status(self.manager, self.alarm) self.assertEqual(got, CANCELED)
def test_is_canceled(self): self.alarm[AlarmField.canceled.value] = { '_t': 'cancel', 't': 0, 'a': 'test', 'm': 'test' } got = compute_status(self.manager, self.alarm) self.assertEqual(got, CANCELED)
def test_is_off(self): self.alarm['state'] = { '_t': 'statedec', 't': 0, 'a': 'test', 'm': 'test', 'val': Check.OK } got = compute_status(self.manager, self.alarm) self.assertEqual(got, OFF)
def test_is_ongoing(self): self.alarm['state'] = { '_t': 'stateinc', 't': 0, 'a': 'test', 'm': 'test', 'val': Check.CRITICAL } got = compute_status(self.manager, self.alarm) self.assertEqual(got, ONGOING)
def test_is_off(self): self.alarm[AlarmField.state.value] = { '_t': 'statedec', 't': 0, 'a': 'test', 'm': 'test', 'val': Check.OK } got = compute_status(self.manager, self.alarm) self.assertEqual(got, OFF)
def test_is_ongoing(self): self.alarm[AlarmField.state.value] = { '_t': 'stateinc', 't': 0, 'a': 'test', 'm': 'test', 'val': Check.CRITICAL } got = compute_status(self.manager, self.alarm) self.assertEqual(got, ONGOING)
def state_decrease(manager, alarm, state, event): """ Called when the system detects a state decrease on an alarm. """ step = { '_t': 'statedec', 't': event['timestamp'], 'a': event.get("author", DEFAULT_AUTHOR), 'm': event['output'], 'val': state } if alarm[AlarmField.state.value] is None or not is_keeped_state(alarm): alarm[AlarmField.state.value] = step alarm[AlarmField.steps.value].append(step) status = compute_status(manager, alarm) return alarm, status
def state_decrease(manager, alarm, state, event): """ Called when the system detect a state decrease on an alarm. """ step = { '_t': 'statedec', 't': event['timestamp'], 'a': '{0}.{1}'.format(event['connector'], event['connector_name']), 'm': event['output'], 'val': state } if alarm['state'] is None or alarm['state']['_t'] != 'changestate': alarm['state'] = step status = compute_status(manager, alarm) alarm['steps'].append(step) return alarm, status
def state_decrease(manager, alarm, state, event): """ Called when the system detects a state decrease on an alarm. """ step = { '_t': 'statedec', 't': event['timestamp'], 'a': '{0}.{1}'.format(event['connector'], event['connector_name']), 'm': event['output'], 'val': state } if alarm[AlarmField.state.value] is None or not is_keeped_state(alarm): alarm[AlarmField.state.value] = step alarm[AlarmField.steps.value].append(step) status = compute_status(manager, alarm) return alarm, status
def restore(manager, alarm, author, message, event): """ Called when an alarm is restored by a user. """ step = { '_t': 'uncancel', 't': event['timestamp'], 'a': author, 'm': message } canceled = alarm[AlarmField.canceled.value] alarm[AlarmField.canceled.value] = None alarm[AlarmField.steps.value].append(step) status = None if manager.restore_event: status = get_previous_step( alarm, ['statusinc', 'statusdec'], ts=canceled['t'] ) if status is not None: status = status['val'] else: # This is not supposed to happen since a restored alarm # should have a status before its cancelation status = OFF else: status = compute_status(manager, alarm) return alarm, status