Пример #1
0
    def test_clear_observer(self, mock):
        observer = ObserverFactory.create()
        AlertFactory.create(identifier=observer.get_alert_identifier())
        Alert.clear(observer.value, observer=observer)

        assert Alert.objects.all().count() == 0
        assert mock.call_count == 1
Пример #2
0
    def test_clear(self, mock):
        observer = ObserverFactory.create()
        AlertFactory.create(observer=observer)
        Alert.clear(observer, observer.value)

        assert Alert.objects.all().count() == 0
        assert mock.call_count == 1
Пример #3
0
    def handle(self, *args, **options):
        for watchdog in Watchdog.objects.all():
            if watchdog.must_checked:
                if watchdog.max_age and watchdog.last_timestamp_delta > watchdog.max_age:
                    Alert.set(
                        watchdog.last_timestamp,
                        identifier='watchdog_outdated:{0}'.format(watchdog.pk),
                        title='OUTDATED: {0}'.format(watchdog.metric)
                    )
                    continue
                else:
                    Alert.clear(
                        watchdog.last_timestamp,
                        identifier='watchdog_outdated:{0}'.format(watchdog.pk),
                        title='OK: {0}'.format(watchdog.metric),
                        watchdog=watchdog
                    )

                watchdog.observer.compare(
                    watchdog.last_value, metric=watchdog.metric, watchdog=watchdog,
                    identifier='watchdog:{0}'.format(watchdog.pk))

            if watchdog.is_time_based and not watchdog.must_checked:
                Alert.clear(
                    'Time is outside the test interval',
                    observer=watchdog.observer,
                    identifier='watchdog:{0}'.format(watchdog.pk),
                    metric=watchdog.metric,
                    watchdog=watchdog,
                )

            for plan in watchdog.emergencyplan_set.all():
                if plan.is_active:
                    operator_class = Observer.operators[plan.disable_observer.operator]
                    if operator_class(plan.disable_observer).compare(watchdog.last_value):
                        plan.switch.mode = plan.disable_mode
                        plan.switch.save(update_fields=['mode'])
                        plan.is_active = False
                        plan.save()
                else:
                    operator_class = Observer.operators[plan.enable_observer.operator]
                    if operator_class(plan.enable_observer).compare(watchdog.last_value):
                        plan.switch.mode = plan.enable_mode
                        plan.switch.save(update_fields=['mode'])
                        plan.is_active = True
                        plan.save()
Пример #4
0
def check_watchdogs():
    all_clear = True
    for watchdog in Watchdog.objects.all():
        if watchdog.max_age and watchdog.last_timestamp_delta > watchdog.max_age:
            Alert.set(watchdog.last_timestamp,
                      identifier='watchdog:{0}'.format(watchdog.pk),
                      title='OUTDATED: {0}'.format(watchdog.metric))
            all_clear = False
            continue
        else:
            Alert.clear(watchdog.last_timestamp,
                        identifier='watchdog:{0}'.format(watchdog.pk),
                        title='OK: {0}'.format(watchdog.metric))

        compare_value = watchdog.last_value
        if not watchdog.observer.compare(compare_value):
            all_clear = False

    return all_clear
Пример #5
0
def check_watchdogs():
    all_clear = True
    for watchdog in Watchdog.objects.all():
        if watchdog.max_age and watchdog.last_timestamp_delta > watchdog.max_age:
            Alert.set(
                watchdog.last_timestamp,
                identifier='watchdog:{0}'.format(watchdog.pk),
                title='OUTDATED: {0}'.format(watchdog.metric)
            )
            all_clear = False
            continue
        else:
            Alert.clear(
                watchdog.last_timestamp,
                identifier='watchdog:{0}'.format(watchdog.pk),
                title='OK: {0}'.format(watchdog.metric)
            )

        compare_value = watchdog.last_value
        if not watchdog.observer.compare(compare_value):
            all_clear = False

    return all_clear
Пример #6
0
 def test_clear_observer_and_identifier_missing(self):
     with pytest.raises(ValueError):
         Alert.clear(2)
Пример #7
0
    def test_clear_identifier(self, mock):
        alert = AlertFactory.create()
        Alert.clear(identifier=alert.identifier)

        assert Alert.objects.all().count() == 0
        assert mock.call_count == 1