def test_element_and_event_suppressor(self):
     """
     Test ElementAndEvent suppression
     :return:
     """
     e_and_e_suppressor = factories.EventAndElementSuppressorFactory(event=self.event, element="foo")
     S = SuppressorPipeLine()
     self.assertTrue(S.is_suppressed(incident=self.incident))
     self.assertTrue(S.is_element_and_event_suppressed)
 def test_element_suppressor(self):
     """
     Test element suppression
     :return:
     """
     element_suppressor = factories.ElementSuppressorFactory.create(element="foo")
     S = SuppressorPipeLine()
     self.assertTrue(S.is_suppressed(incident=self.incident))
     self.assertTrue(S.is_element_suppressed)
 def test_element_suppressor(self):
     """
     Test element suppression
     :return:
     """
     element_suppressor = factories.ElementSuppressorFactory.create(element='foo')
     S = SuppressorPipeLine()
     self.assertTrue(S.is_suppressed(incident=self.incident))
     self.assertTrue(S.is_element_suppressed)
 def test_element_and_event_suppressor(self):
     """
     Test ElementAndEvent suppression
     :return:
     """
     e_and_e_suppressor = factories.EventAndElementSuppressorFactory(event=self.event, element='foo')
     S = SuppressorPipeLine()
     self.assertTrue(S.is_suppressed(incident=self.incident))
     self.assertTrue(S.is_element_and_event_suppressed)
    def test_element_suppressor_with_time_limits(self):
        """
        Test element suppression with time constraints
        :return:
        """

        now = timezone.now()
        hour_ago = now + timedelta(hours=-1)
        two_hours_ago = now + timedelta(hours=-1)
        hour_ahead = now + timedelta(hours=1)
        two_hours_ahead = now + timedelta(hours=2)

        # with proper time constraints
        e1 = factories.EventFactory.create()
        i1 = factories.IncidentFactory.create(event=e1, element='e1foo')
        factories.ElementSuppressorFactory.create(element='e1foo', start_time=hour_ago, end_time=hour_ahead)
        S = SuppressorPipeLine()
        self.assertTrue(S.is_suppressed(incident=i1))
        self.assertTrue(S.is_element_suppressed)
        # expired time constraints
        e2 = factories.EventFactory.create()
        i2 = factories.IncidentFactory.create(event=e2, element='e2foo')
        factories.ElementSuppressorFactory.create(element='e2foo', start_time=two_hours_ago, end_time=hour_ago)
        S = SuppressorPipeLine()
        self.assertFalse(S.is_suppressed(incident=i2))
        self.assertFalse(S.is_element_suppressed)
        # with time constraints in future
        e3 = factories.EventFactory.create()
        i3 = factories.IncidentFactory.create(event=e3, element='e3foo')
        factories.ElementSuppressorFactory.create(element='e3foo', start_time=hour_ahead, end_time=two_hours_ahead)
        S = SuppressorPipeLine()
        self.assertFalse(S.is_suppressed(incident=i3))
        self.assertFalse(S.is_element_suppressed)
예제 #6
0
 def test_is_suppressed(self):
     """
     Expect false if incident is not suppressed
     :return:
     """
     self.assertFalse(
         SuppressorPipeLine().is_suppressed(incident=self.incident))
예제 #7
0
    def begin(self):
        """
        If incident is suppressed, do nothing.
        Else execute EventActions
        """

        # Log if incident is already suppressed
        if self.incident.is_suppressed:
            incidentauditlog(incident=self.incident,
                             message='IncidentID:%s is suppressed' %
                             self.incident.id)

        # Check suppression pipeline
        elif SuppressorPipeLine().is_suppressed(incident=self.incident):
            self.incident.suppressed()
            incidentauditlog(
                incident=self.incident,
                message=
                'IncidentID:%s found in suppression pipline, it is now suppressed.'
                % self.incident.id)

        # Process incident normally
        else:
            for event_action in EventAction.objects.filter(
                    event=self.incident.event, isEnabled=True):
                if self.check_incident_threshold(event_action):
                    self.execute_plugin(event_action)