Example #1
0
    def test_simple_triggers(self):
        #
        # Config is not correct because of a wrong relative path
        # in the main config file
        #
        svc = self.sched.services.find_srv_by_name_and_hostname("test_host_0", "test_ok_0")
        code = '''r = self.get_name()'''.replace(r'\n', '\n').replace(r'\t', '\t')
        t = Trigger({'trigger_name': 'none', 'code_src': code})
        t.compile()
        r = t.eval(svc)
        print r

        code = '''self.output = "Moncul c'est du poulet" '''.replace(r'\n', '\n').replace(r'\t', '\t')
        t = Trigger({'trigger_name': 'none', 'code_src': code})
        t.compile()
        r = t.eval(svc)
        print "Service output", svc.output
        self.assertEqual("Moncul c'est du poulet", svc.output)

        code = '''self.output = "Moncul c'est du poulet2"
self.perf_data = "Moncul c'est du poulet3"
'''.replace(r'\n', '\n').replace(r'\t', '\t')
        t = Trigger({'trigger_name': 'none', 'code_src': code})
        t.compile()
        r = t.eval(svc)
        print "Service output", svc.output
        print "Service perf_data", svc.perf_data
        self.assertEqual("Moncul c'est du poulet2", svc.output)
        self.assertEqual("Moncul c'est du poulet3", svc.perf_data)
Example #2
0
 def setUp(self):
     from shinken.objects.trigger import Trigger
     self.item = Trigger()
Example #3
0
    def test_simple_triggers(self):
        #
        # Config is not correct because of a wrong relative path
        # in the main config file
        #
        svc = self.sched.services.find_srv_by_name_and_hostname("test_host_0", "test_ok_0")
        code = """r = self.get_name()""".replace(r"\n", "\n").replace(r"\t", "\t")
        t = Trigger({"trigger_name": "none", "code_src": code})
        t.compile()
        r = t.eval(svc)
        print r

        code = """self.output = "Moncul c'est du poulet" """.replace(r"\n", "\n").replace(r"\t", "\t")
        t = Trigger({"trigger_name": "none", "code_src": code})
        t.compile()
        r = t.eval(svc)
        print "Service output", svc.output
        self.assert_(svc.output == "Moncul c'est du poulet")

        code = """self.output = "Moncul c'est du poulet2"
self.perf_data = "Moncul c'est du poulet3"
""".replace(
            r"\n", "\n"
        ).replace(
            r"\t", "\t"
        )
        t = Trigger({"trigger_name": "none", "code_src": code})
        t.compile()
        r = t.eval(svc)
        print "Service output", svc.output
        print "Service perf_data", svc.perf_data
        self.assert_(svc.output == "Moncul c'est du poulet2")
        self.assert_(svc.perf_data == "Moncul c'est du poulet3")