Пример #1
0
 def test_times_broken(self):
     config_options = {
         "times_type": "fake",
         "time_lower": "10:00",
         "time_upper": "11:00",
     }
     with self.assertRaises(util.AlerterConfigurationError):
         alerter.Alerter(config_options)
Пример #2
0
 def test_times_only_times(self):
     a = alerter.Alerter({
         "times_type": "only",
         "time_lower": "09:00",
         "time_upper": "10:00"
     })
     self.assertEqual(a._describe_times(),
                      "only between 09:00 and 10:00 (local) on any day")
Пример #3
0
 def test_should_not_alert_ooh(self):
     config = {
         "times_type": "only",
         "time_lower": "10:00",
         "time_upper": "11:00"
     }
     a = alerter.Alerter(config)
     m = monitor.MonitorFail("fail", {})
     m.run_test()
     with freeze_time("2020-03-10 09:00"):
         # out of hours on the right day; shouldn't alert
         self.assertEqual(a.should_alert(m), alerter.AlertType.NONE)
         self.assertEqual(a._ooh_failures, ["fail"])
     a = alerter.Alerter(config)
     with freeze_time("2020-03-10 12:00"):
         self.assertEqual(a.should_alert(m), alerter.AlertType.NONE)
         self.assertEqual(a._ooh_failures, ["fail"])
Пример #4
0
 def test_should_alert_unavailable(self):
     a = alerter.Alerter(None)
     a.available = False
     m = monitor.MonitorNull()
     self.assertEqual(
         a.should_alert(m),
         alerter.AlertType.NONE,
         "Alerter did not handle being unavailable",
     )
Пример #5
0
 def test_times_not(self):
     config_options = {
         "times_type": "not",
         "time_lower": "10:00",
         "time_upper": "11:00",
     }
     a = alerter.Alerter(config_options)
     self.assertEqual(a._times_type, alerter.AlertTimeFilter.NOT)
     self.assertEqual(a._time_info,
                      (datetime.time(10, 00), datetime.time(11, 00)))
Пример #6
0
 def test_times_not_time(self):
     a = alerter.Alerter({
         "times_type": "not",
         "time_lower": "09:00",
         "time_upper": "10:00"
     })
     self.assertEqual(
         a._describe_times(),
         "any time except between 09:00 and 10:00 (local) on any day",
     )
Пример #7
0
 def test_times_only(self):
     config_options = {
         "times_type": "only",
         "time_lower": "10:00",
         "time_upper": "11:00",
     }
     a = alerter.Alerter(config_options)
     self.assertEqual(a.times_type, "only")
     self.assertEqual(a.time_info,
                      (datetime.time(10, 00), datetime.time(11, 00)))
Пример #8
0
 def test_times_not_days(self):
     a = alerter.Alerter({
         "times_type": "not",
         "time_lower": "09:00",
         "time_upper": "10:00",
         "days": "3,4,5,6",
     })
     self.assertEqual(
         a._describe_times(),
         "any time except between 09:00 and 10:00 (local) on Thu, Fri, Sat, Sun",
     )
Пример #9
0
 def test_times_only_days(self):
     a = alerter.Alerter({
         "times_type": "only",
         "time_lower": "09:00",
         "time_upper": "10:00",
         "days": "0,1,2",
     })
     self.assertEqual(
         a._describe_times(),
         "only between 09:00 and 10:00 (local) on Mon, Tue, Wed",
     )
Пример #10
0
 def test_allowed_not(self):
     a = alerter.Alerter({
         "times_type": "not",
         "time_lower": "10:00",
         "time_upper": "11:00"
     })
     with freeze_time("09:00", tz_offset=-self.utcoffset):
         self.assertTrue(a._allowed_time())
     with freeze_time("10:30", tz_offset=-self.utcoffset):
         self.assertFalse(a._allowed_time())
     with freeze_time("12:00", tz_offset=-self.utcoffset):
         self.assertTrue(a._allowed_time())
Пример #11
0
 def test_should_alert_ooh(self):
     config = {
         "times_type": "only",
         "time_lower": "10:00",
         "time_upper": "11:00"
     }
     a = alerter.Alerter(config)
     m = monitor.MonitorFail("fail", {})
     m.run_test()
     with freeze_time("2020-03-10 10:30"):
         self.assertEqual(a.should_alert(m), alerter.AlertType.FAILURE)
         self.assertEqual(a._ooh_failures, [])
Пример #12
0
 def test_dependencies(self):
     config_options = {"depend": "a,b,c"}
     a = alerter.Alerter(config_options)
     self.assertEqual(a.dependencies, ["a", "b", "c"],
                      "Alerter did not store dependencies")
     self.assertEqual(a.check_dependencies(["d", "e"]), True,
                      "Alerter thinks a dependency failed")
     self.assertEqual(
         a.check_dependencies(["a"]),
         False,
         "Alerter did not notice a dependency failed",
     )
Пример #13
0
 def test_allowed_not_tz(self):
     a = alerter.Alerter({
         "times_type": "not",
         "time_lower": "15:00",
         "time_upper": "16:00",
         "times_tz": "+05:00",
     })
     with freeze_time("09:00"):
         self.assertTrue(a._allowed_time())
     with freeze_time("10:30"):
         self.assertFalse(a._allowed_time())
     with freeze_time("12:00"):
         self.assertTrue(a._allowed_time())
Пример #14
0
    def test_should_alert_catchup(self):
        config = {
            "delay": 1,
            "times_type": "only",
            "time_lower": "10:00",
            "time_upper": "11:00",
        }
        a = alerter.Alerter(config)
        a.support_catchup = True
        m = monitor.MonitorFail("fail", {})
        m.run_test()
        with freeze_time("2020-03-10 09:00"):
            self.assertEqual(a.should_alert(m), alerter.AlertType.NONE)
            self.assertEqual(a._ooh_failures, ["fail"])

        with freeze_time("2020-03-10 10:30"):
            self.assertEqual(a.should_alert(m), alerter.AlertType.CATCHUP)
            self.assertEqual(a._ooh_failures, [])
Пример #15
0
 def test_allowed_today(self):
     a = alerter.Alerter({"days": "1"})
     self.assertTrue(a._allowed_today())
Пример #16
0
 def test_allowed_today_tz(self):
     a = alerter.Alerter({"days": "1", "times_tz": "+05:00"})
     self.assertTrue(a._allowed_today())
Пример #17
0
 def test_times_always(self):
     a = alerter.Alerter({"times_type": "always"})
     self.assertEqual(a._describe_times(), "(always)")
Пример #18
0
 def test_allowed_default(self):
     a = alerter.Alerter({})
     self.assertTrue(a._allowed_today())
Пример #19
0
 def test_allowed_always(self):
     a = alerter.Alerter({})
     self.assertTrue(a._allowed_time())
Пример #20
0
 def setUp(self):
     self.test_alerter = alerter.Alerter()
     self.freeze_time_value = "2020-03-10 09:00"
     self.expected_time_string = "2020-03-10 09:00:00+00:00"
Пример #21
0
 def test_dryrun(self):
     config_options = {"dry_run": "1"}
     a = alerter.Alerter(config_options)
     self.assertEqual(a._dry_run, True)
Пример #22
0
 def test_days(self):
     config_options = {"days": "0,1,4"}
     a = alerter.Alerter(config_options)
     self.assertEqual(a._days, [0, 1, 4])
Пример #23
0
 def test_times_always(self):
     config_options = {"times_type": "always"}
     a = alerter.Alerter(config_options)
     self.assertEqual(a._times_type, alerter.AlertTimeFilter.ALWAYS)
     self.assertEqual(a._time_info, (None, None))
Пример #24
0
 def test_groups(self):
     config_options = {"groups": "a,b,c"}
     a = alerter.Alerter(config_options)
     self.assertEqual(["a", "b", "c"], a.groups)
Пример #25
0
 def test_delay(self):
     config_options = {"delay": "1"}
     a = alerter.Alerter(config_options)
     self.assertEqual(a._delay_notification, True)
Пример #26
0
 def test_skip_group_monitor(self):
     a = alerter.Alerter()
     m = monitor.MonitorFail("fail", {"group": "test"})
     m.run_test()
     self.assertEqual(a.should_alert(m), alerter.AlertType.NONE)
Пример #27
0
 def test_oohrecovery(self):
     config_otions = {"ooh_recovery": "1"}
     a = alerter.Alerter(config_otions)
     self.assertEqual(a._ooh_recovery, True)
Пример #28
0
 def test_groups_all_match(self):
     a = alerter.Alerter({"groups": "_all"})
     m = monitor.MonitorFail("fail", {"group": "test1"})
     m.run_test()
     self.assertEqual(a.should_alert(m), alerter.AlertType.FAILURE)
Пример #29
0
 def test_limit(self):
     config_options = {"limit": "5"}
     a = alerter.Alerter(config_options)
     self.assertEqual(a._limit, 5)
Пример #30
0
 def test_disabled_monitor_no_alert(self):
     a = alerter.Alerter()
     m = monitor.MonitorFail("fail", {"enabled": 0})
     m.run_test()
     self.assertEqual(a.should_alert(m), alerter.AlertType.NONE)