Esempio n. 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)
Esempio n. 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")
Esempio n. 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"])
Esempio n. 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",
     )
Esempio n. 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)))
Esempio n. 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",
     )
Esempio n. 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)))
Esempio n. 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",
     )
Esempio n. 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",
     )
Esempio n. 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())
Esempio n. 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, [])
Esempio n. 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",
     )
Esempio n. 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())
Esempio n. 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, [])
Esempio n. 15
0
 def test_allowed_today(self):
     a = alerter.Alerter({"days": "1"})
     self.assertTrue(a._allowed_today())
Esempio n. 16
0
 def test_allowed_today_tz(self):
     a = alerter.Alerter({"days": "1", "times_tz": "+05:00"})
     self.assertTrue(a._allowed_today())
Esempio n. 17
0
 def test_times_always(self):
     a = alerter.Alerter({"times_type": "always"})
     self.assertEqual(a._describe_times(), "(always)")
Esempio n. 18
0
 def test_allowed_default(self):
     a = alerter.Alerter({})
     self.assertTrue(a._allowed_today())
Esempio n. 19
0
 def test_allowed_always(self):
     a = alerter.Alerter({})
     self.assertTrue(a._allowed_time())
Esempio n. 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"
Esempio n. 21
0
 def test_dryrun(self):
     config_options = {"dry_run": "1"}
     a = alerter.Alerter(config_options)
     self.assertEqual(a._dry_run, True)
Esempio n. 22
0
 def test_days(self):
     config_options = {"days": "0,1,4"}
     a = alerter.Alerter(config_options)
     self.assertEqual(a._days, [0, 1, 4])
Esempio n. 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))
Esempio n. 24
0
 def test_groups(self):
     config_options = {"groups": "a,b,c"}
     a = alerter.Alerter(config_options)
     self.assertEqual(["a", "b", "c"], a.groups)
Esempio n. 25
0
 def test_delay(self):
     config_options = {"delay": "1"}
     a = alerter.Alerter(config_options)
     self.assertEqual(a._delay_notification, True)
Esempio n. 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)
Esempio n. 27
0
 def test_oohrecovery(self):
     config_otions = {"ooh_recovery": "1"}
     a = alerter.Alerter(config_otions)
     self.assertEqual(a._ooh_recovery, True)
Esempio n. 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)
Esempio n. 29
0
 def test_limit(self):
     config_options = {"limit": "5"}
     a = alerter.Alerter(config_options)
     self.assertEqual(a._limit, 5)
Esempio n. 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)