def _create_event_triggers(self):
        triggers = self._config["triggers"]
        sup_tr = triggers["support"]
        user_support = ev.Trigger(
            prob_check=pck.ProbCheck(sup_tr["get_called"]),
            node_check=dck.AnyDepCheck(dck.NeqCheck("run")),
            event_builder=ev.EventBuilder(
                "User complained for poor web service"))
        webs1 = ev.Trigger(
            node_check=dck.OrCheck(
                dck.EqCheck("stop"), dck.DepCheck(dck.EqCheck("off")),
                dck.DepCheck(dck.DepCheck(dck.EqCheck("off")))),
            prob_check=pck.NoProbCheck(),
            event_builder=ev.EventBuilder("Application is down"))
        webs2 = ev.Trigger(
            node_check=dck.EqCheck("slow"),
            prob_check=pck.NoProbCheck(),
            event_builder=ev.EventBuilder("Application is slow"))
        host = ev.Trigger(
            node_check=dck.OrCheck(dck.EqCheck("off"),
                                   dck.DepCheck(dck.EqCheck("off"))),
            prob_check=pck.NoProbCheck(),
            event_builder=ev.EventBuilder("Host is unreachable or down"))
        switch = ev.Trigger(
            node_check=dck.EqCheck("off"),
            prob_check=pck.NoProbCheck(),
            event_builder=ev.EventBuilder("Switch is unreachable or down"))

        return {
            "switch": switch,
            "host": host,
            "web_service": [webs1, webs2],
            "support": user_support
        }
Пример #2
0
    def _create_trigger(self, prob, state, event_msg):
        """Aux function to create an event trigger

        :param prob: float between 0 and 1 -- probability of the event
        being triggered
        :param state: str -- State where this event can be triggered
        :param event_msg: str -- message that will be sent for this event
        """
        return events.Trigger(prob_check=pck.ProbCheck(prob),
                              node_check=dck.EqCheck(state),
                              event_builder=events.EventBuilder(event_msg))
Пример #3
0
 def test_collect_events_should_be_populated_by_trigger(self):
     some_trigger = ev.Trigger(
         node_check=dck.EqCheck(0),
         prob_check=pck.NoProbCheck(),
         event_builder=ev.EventBuilder("test")
     )
     node = base.StateNode(0, None, some_trigger)
     events = []
     node.collect_events(1, datetime.datetime.now(),
                         markov_mocks.MockRequestBuilder(events))
     self.assertTrue(len(events) == 1)
     self.assertEqual(events[0]["event"].msg, "test", "a")
 def test_trigger_should_create_event_when_necessary(self):
     some_trigger = ev.Trigger(node_check=dck.EqCheck(0),
                               prob_check=pck.NoProbCheck(),
                               event_builder=ev.EventBuilder(""))
     events = []
     some_trigger.apply_on(DummyState(), 1, datetime.datetime.now(),
                           markov_mocks.MockRequestBuilder(events))
     self.assertEqual(len(events), 1)
     events = []
     some_trigger.apply_on(DummyState(1), 1, datetime.datetime.now(),
                           markov_mocks.MockRequestBuilder(events))
     self.assertEqual(len(events), 0)