示例#1
0
文件: tasks.py 项目: crudbug/canopsis
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
示例#2
0
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
示例#3
0
 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)
示例#4
0
 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)
示例#5
0
 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)
示例#6
0
 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)
示例#7
0
 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)
示例#8
0
 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)
示例#9
0
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
示例#10
0
文件: tasks.py 项目: crudbug/canopsis
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
示例#11
0
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
示例#12
0
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
示例#13
0
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