コード例 #1
0
    def test_compound_partial_fail(self):
        m = MonitorNull()
        m2 = MonitorFail("fail1", {})
        m3 = MonitorFail("fail2", {})

        compound_monitor = CompoundMonitor("compound",
                                           {"monitors": ["m", "m2", "m3"]})
        monitors = {"m": m, "m2": m2, "m3": m3}
        compound_monitor.set_mon_refs(monitors)
        compound_monitor.post_config_setup()

        self.assertIn("m", compound_monitor.all_monitors,
                      "compound all_monitors not set")
        self.assertIn("m", compound_monitor.m, "compund m not set")

        m.run_test()
        m2.run_test()
        m3.run_test()

        result = compound_monitor.run_test()
        # should be ok because not all have failed
        self.assertEqual(result, True,
                         "compound monitor should not have failed")
        self.assertEqual(
            compound_monitor.virtual_fail_count(),
            0,
            "compound monitor should not report fail count",
        )
        self.assertEqual(
            compound_monitor.get_result(),
            "2 of 3 services failed. Fail after: 3",
            "compound monitor did not report failures properly",
        )
コード例 #2
0
    def test_compound_no_fail(self):
        m = MonitorNull()
        m2 = MonitorNull()

        compound_monitor = CompoundMonitor("compound",
                                           {"monitors": ["m", "m2"]})
        monitors = {"m": m, "m2": m2}
        compound_monitor.set_mon_refs(monitors)
        compound_monitor.post_config_setup()

        self.assertIn("m", compound_monitor.all_monitors,
                      "compound all_monitors not set")
        self.assertIn("m", compound_monitor.m, "compund m not set")

        m.run_test()
        m2.run_test()

        result = compound_monitor.run_test()
        # should be ok because not all have failed
        self.assertEqual(result, True,
                         "compound monitor should not have failed")
        self.assertEqual(
            compound_monitor.virtual_fail_count(),
            0,
            "compound monitor should not report fail count",
        )
        self.assertEqual(
            compound_monitor.get_result(),
            "All 2 services OK",
            "compound monitor did not report status properly",
        )
コード例 #3
0
 def test_file_nonutc_iso_nonutctz(self):
     temp_logfile = tempfile.mkstemp()[1]
     file_logger = FileLogger({
         "filename": temp_logfile,
         "buffered": False,
         "dateformat": "iso8601",
         "tz": "Europe/Warsaw",
     })
     monitor = MonitorNull()
     monitor.run_test()
     file_logger.save_result2("null", monitor)
     self.assertTrue(os.path.exists(temp_logfile))
     with open(temp_logfile, "r") as fh:
         self.assertEqual(
             fh.readline().strip(),
             "2020-04-18 13:00:00+02:00 simplemonitor starting",
         )
         self.assertEqual(
             fh.readline().strip(),
             "2020-04-18 13:00:00+02:00 null: ok (0.000s)",
         )
     try:
         os.unlink(temp_logfile)
     except PermissionError:
         # Windows won't remove a file which is in use
         pass
コード例 #4
0
ファイル: test_main.py プロジェクト: mrgfisher/simplemonitor
 def test_no_failed(self):
     s = simplemonitor.SimpleMonitor("tests/monitor-empty.ini")
     m1 = MonitorNull("null1", config_options={})
     m2 = MonitorNull("null2", config_options={})
     s.add_monitor("null1", m1)
     s.add_monitor("null2", m2)
     m2.reset_dependencies()
     m1.run_test()
     failed = s._failed_monitors()
     self.assertListEqual([], failed)
コード例 #5
0
 def _write_html(logger_options: dict = None) -> str:
     if logger_options is None:
         logger_options = {}
     with patch.object(socket, "gethostname", return_value="fake_hostname.local"):
         temp_htmlfile = tempfile.mkstemp()[1]
         logger_options.update({"filename": temp_htmlfile})
         html_logger = HTMLLogger(logger_options)
         monitor1 = MonitorNull()
         monitor2 = MonitorFail("fail", {})
         monitor1.run_test()
         monitor2.run_test()
         html_logger.start_batch()
         html_logger.save_result2("null", monitor1)
         html_logger.save_result2("fail", monitor2)
         html_logger.end_batch()
     return temp_htmlfile
コード例 #6
0
 def test_file_nonutc(self):
     temp_logfile = tempfile.mkstemp()[1]
     file_logger = FileLogger({"filename": temp_logfile, "buffered": False})
     monitor = MonitorNull()
     monitor.run_test()
     file_logger.save_result2("null", monitor)
     self.assertTrue(os.path.exists(temp_logfile))
     ts = str(int(time.time()))
     with open(temp_logfile, "r") as fh:
         self.assertEqual(fh.readline().strip(),
                          "{} simplemonitor starting".format(ts))
         self.assertEqual(fh.readline().strip(),
                          "{} null: ok (0.000s)".format(ts))
     try:
         os.unlink(temp_logfile)
     except PermissionError:
         # Windows won't remove a file which is in use
         pass
コード例 #7
0
    def test_html_logger(self):
        config_options = {
            "folder": "test_html",
            "copy_resources": True,
            "filename": "status.html",
        }
        test_logger = HTMLLogger(config_options)
        monitor = MonitorNull()
        monitor.run_test()
        test_logger.start_batch()
        test_logger.save_result2("test", monitor)
        test_logger.process_batch()
        test_logger.end_batch()

        self.assertTrue(
            os.path.exists(os.path.join("test_html", "status.html")),
            "status.html was not created",
        )
        self.assertTrue(
            os.path.exists(os.path.join("test_html", "style.css")),
            "style.css was not copied",
        )