當前位置: 首頁>>代碼示例>>Python>>正文


Python LogChecker.check_log方法代碼示例

本文整理匯總了Python中check_log_ng.LogChecker.check_log方法的典型用法代碼示例。如果您正苦於以下問題:Python LogChecker.check_log方法的具體用法?Python LogChecker.check_log怎麽用?Python LogChecker.check_log使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在check_log_ng.LogChecker的用法示例。


在下文中一共展示了LogChecker.check_log方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_replace_pipe_symbol

# 需要導入模塊: from check_log_ng import LogChecker [as 別名]
# 或者: from check_log_ng.LogChecker import check_log [as 別名]
    def test_replace_pipe_symbol(self):
        """replace pipe symbol
        """
        initial_data = {
            "logformat": self.logformat_syslog,
            "pattern_list": ["ERROR"],
            "critical_pattern_list": [],
            "negpattern_list": [],
            "critical_negpattern_list": [],
            "case_insensitive": False,
            "warning": 1,
            "critical": 0,
            "nodiff_warn": False,
            "nodiff_crit": False,
            "trace_inode": False,
            "multiline": False,
            "scantime": 86400,
            "expiration": 691200
        }
        log = LogChecker(initial_data)

        f = open(self.logfile, 'a')
        f.write("Dec | 5 12:34:56 hostname noop: NOOP\n")
        f.write("Dec | 5 12:34:56 hostname test: ERROR\n")
        f.write("Dec | 5 12:34:57 hostname noop: NOOP\n")
        f.flush()
        f.close()

        log.check_log(self.logfile, self.seekfile)

        self.assertEqual(log.get_state(), LogChecker.STATE_WARNING)
        self.assertEqual(log.get_message(), 'WARNING: Found 1 lines (limit=1/0): Dec (pipe) 5 12:34:56 hostname test: ERROR at %s' % self.logfile)
開發者ID:bpineau,項目名稱:check_log_ng,代碼行數:34,代碼來源:test_check_log_ng.py

示例2: test_format

# 需要導入模塊: from check_log_ng import LogChecker [as 別名]
# 或者: from check_log_ng.LogChecker import check_log [as 別名]
    def test_format(self):
        """--format option
        """
        initial_data = {
            "logformat": "^(\[%a %b %d %T %Y\] \[\S+\]) (.*)$",
            "pattern_list": ["ERROR"],
            "critical_pattern_list": [],
            "negpattern_list": [],
            "critical_negpattern_list": [],
            "case_insensitive": False,
            "warning": 1,
            "critical": 0,
            "nodiff_warn": False,
            "nodiff_crit": False,
            "trace_inode": False,
            "multiline": False,
            "scantime": 86400,
            "expiration": 691200
        }
        log = LogChecker(initial_data)

        f = open(self.logfile, 'a')
        f.write("[Thu Dec 05 12:34:56 2013] [error] NOOP\n")
        f.write("[Thu Dec 05 12:34:56 2013] [error] ERROR\n")
        f.write("[Thu Dec 05 12:34:57 2013] [error] NOOP\n")
        f.flush()
        f.close()

        log.check_log(self.logfile, self.seekfile)

        self.assertEqual(log.get_state(), LogChecker.STATE_WARNING)
        self.assertEqual(log.get_message(), "WARNING: Found 1 lines (limit=1/0): [Thu Dec 05 12:34:56 2013] [error] ERROR at %s" % self.logfile)
開發者ID:bpineau,項目名稱:check_log_ng,代碼行數:34,代碼來源:test_check_log_ng.py

示例3: test_criticalpattern_with_case_sensitive

# 需要導入模塊: from check_log_ng import LogChecker [as 別名]
# 或者: from check_log_ng.LogChecker import check_log [as 別名]
    def test_criticalpattern_with_case_sensitive(self):
        """--criticalpattern and --case-insensitive options
        """
        initial_data = {
            "logformat": self.logformat_syslog,
            "pattern_list": [],
            "critical_pattern_list": ["error"],
            "negpattern_list": [],
            "critical_negpattern_list": [],
            "case_insensitive": True,
            "warning": 1,
            "critical": 0,
            "nodiff_warn": False,
            "nodiff_crit": False,
            "trace_inode": False,
            "multiline": False,
            "scantime": 86400,
            "expiration": 691200
        }
        log = LogChecker(initial_data)

        f = open(self.logfile, 'a')
        f.write("Dec  5 12:34:56 hostname noop: NOOP\n")
        f.write("Dec  5 12:34:56 hostname test: ERROR\n")
        f.write("Dec  5 12:34:57 hostname noop: NOOP\n")
        f.flush()
        f.close()

        log.check_log(self.logfile, self.seekfile)

        self.assertEqual(log.get_state(), LogChecker.STATE_CRITICAL)
        self.assertEqual(log.get_message(), 'CRITICAL: Critical Found 1 lines: Dec  5 12:34:56 hostname test: ERROR at %s' % self.logfile)
開發者ID:bpineau,項目名稱:check_log_ng,代碼行數:34,代碼來源:test_check_log_ng.py

示例4: test_negpattern_with_multiple_lines

# 需要導入模塊: from check_log_ng import LogChecker [as 別名]
# 或者: from check_log_ng.LogChecker import check_log [as 別名]
    def test_negpattern_with_multiple_lines(self):
        """--negpattern options with multiple lines
        """
        initial_data = {
            "logformat": self.logformat_syslog,
            "pattern_list": ["ERROR"],
            "critical_pattern_list": [],
            "negpattern_list": ["IGNORE"],
            "critical_negpattern_list": [],
            "case_insensitive": False,
            "warning": 1,
            "critical": 0,
            "nodiff_warn": False,
            "nodiff_crit": False,
            "trace_inode": False,
            "multiline": True,
            "scantime": 86400,
            "expiration": 691200
        }
        log = LogChecker(initial_data)

        f = open(self.logfile, 'a')
        f.write("Dec  5 12:34:56 hostname test: ERROR\n")
        f.write("Dec  5 12:34:56 hostname test: ERROR IGNORE\n")
        f.flush()
        f.close()

        log.check_log(self.logfile, self.seekfile)

        self.assertEqual(log.get_state(), LogChecker.STATE_OK)
        self.assertEqual(log.get_message(), 'OK - No matches found.')
開發者ID:bpineau,項目名稱:check_log_ng,代碼行數:33,代碼來源:test_check_log_ng.py

示例5: test_seekfile_tag

# 需要導入模塊: from check_log_ng import LogChecker [as 別名]
# 或者: from check_log_ng.LogChecker import check_log [as 別名]
    def test_seekfile_tag(self):
        """--seekfile-tag
        """
        initial_data = {
            "logformat": self.logformat_syslog,
            "pattern_list": ["ERROR"],
            "critical_pattern_list": [],
            "negpattern_list": [],
            "critical_negpattern_list": [],
            "case_insensitive": False,
            "warning": 1,
            "critical": 0,
            "nodiff_warn": False,
            "nodiff_crit": False,
            "trace_inode": False,
            "multiline": False,
            "scantime": 86400,
            "expiration": 691200
        }
        log = LogChecker(initial_data)

        # create new logfiles
        f = open(self.logfile, 'a')
        f.write("Dec  5 12:34:51 hostname noop: NOOP\n")
        f.write("Dec  5 12:34:51 hostname test: ERROR\n")
        f.write("Dec  5 12:34:52 hostname noop: NOOP\n")
        f.flush()
        f.close()

        f = open(self.logfile1, 'a')
        f.write("Dec  5 12:34:56 hostname noop: NOOP\n")
        f.write("Dec  5 12:34:56 hostname test: ERROR\n")
        f.write("Dec  5 12:34:57 hostname noop: NOOP\n")
        f.flush()
        f.close()

        f = open(self.logfile2, 'a')
        f.write("Dec  5 12:34:58 hostname noop: NOOP\n")
        f.write("Dec  5 12:34:59 hostname noop: NOOP\n")
        f.flush()
        f.close()

        # create seekfile of logfile
        seekfile_1 = LogChecker.get_seekfile(self.logfile_pattern, self.seekdir, self.logfile, seekfile_tag=self.tag1)
        seekfile_2 = LogChecker.get_seekfile(self.logfile_pattern, self.seekdir, self.logfile, seekfile_tag=self.tag1)
        seekfile_3 = LogChecker.get_seekfile(self.logfile_pattern, self.seekdir, self.logfile, seekfile_tag=self.tag2)
        log.check_log(self.logfile, seekfile_3)
        log.clear_state()
        log.check_log_multi(self.logfile_pattern, self.seekdir, seekfile_tag=self.tag2)

        self.assertEqual(log.get_state(), LogChecker.STATE_WARNING)
        self.assertEqual(log.get_message(), 'WARNING: Found 1 lines (limit=1/0): Dec  5 12:34:56 hostname test: ERROR at %s' % self.logfile1)
        self.assertEqual(seekfile_1, seekfile_2)
        self.assertNotEquals(seekfile_1, seekfile_3)
        self.assertTrue(seekfile_1.find(self.tag1))
        self.assertTrue(os.path.exists(seekfile_3))
開發者ID:erokatyo,項目名稱:check_log_ng,代碼行數:58,代碼來源:test_check_log_ng.py


注:本文中的check_log_ng.LogChecker.check_log方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。