def test_alerting_receive_high(self): analyzer = LogAnalyzer("1") analyzer.analyze_alert(["log1", "log2"]) # now becomes alerting and average 2 with 1 count msg = analyzer.analyze_alert(["log1", "log2"]) self.assertEqual(msg, "") self.assertTrue(analyzer.alerting)
def test_alerting_receive_low(self): analyzer = LogAnalyzer("1") analyzer.analyze_alert(["log1", "log2"]) # now becomes alerting and average 2 with 1 count analyzer.analyze_alert([]) msg = analyzer.analyze_alert([]) # (2 / 3) < 1 recover_msg_prefix = "Traffic recovered" self.assertEqual(msg[:len(recover_msg_prefix)], recover_msg_prefix) self.assertFalse(analyzer.alerting)
def test_alerting_receive_low(self): analyzer = LogAnalyzer("1") analyzer.analyze_alert(["log1", "log2"]) # now becomes alerting and average 2 with 1 count analyzer.analyze_alert([]) msg = analyzer.analyze_alert([]) # (2 / 3) < 1 recover_msg_prefix = "Traffic recovered" self.assertEqual(msg[:len(recover_msg_prefix)], recover_msg_prefix ) self.assertFalse(analyzer.alerting)
def logmonitor(stdscr, *args, **kwargs): # init reader = LogReader(sys.argv[1]) publisher = LogPublisher(reader) analyzer = LogAnalyzer(sys.argv[2]) display = LogDisplay(stdscr, analyzer) publisher.add_subscriber(LogSubscriber(10, display.refresh_most_hits)) publisher.add_subscriber(LogSubscriber(1, display.refresh_alert)) # publish event every one second while True: time.sleep(1) publisher.publish() # deinit reader.close()
def test_notalerting_receive_low(self): analyzer = LogAnalyzer("1") msg = analyzer.analyze_alert([]) self.assertEqual(msg, "") self.assertFalse(analyzer.alerting)
def test_notalerting_receive_high(self): analyzer = LogAnalyzer("1") msg = analyzer.analyze_alert(["log1", "log2"]) self.assertEqual(msg[:4], "High") self.assertTrue(analyzer.alerting)