当前位置: 首页>>代码示例>>Python>>正文


Python LogChecker.get_message方法代码示例

本文整理汇总了Python中check_log_ng.LogChecker.get_message方法的典型用法代码示例。如果您正苦于以下问题:Python LogChecker.get_message方法的具体用法?Python LogChecker.get_message怎么用?Python LogChecker.get_message使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在check_log_ng.LogChecker的用法示例。


在下文中一共展示了LogChecker.get_message方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_scantime_within_scantime

# 需要导入模块: from check_log_ng import LogChecker [as 别名]
# 或者: from check_log_ng.LogChecker import get_message [as 别名]
    def test_scantime_within_scantime(self):
        """--scantime option within scantime.
        """
        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": 2,
            "expiration": 691200
        }
        log = LogChecker(initial_data)

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

        # The first ERROR message should be older than scantime. Therefore, don't scan it.
        log.check_log_multi(self.logfile_pattern, self.seekdir, remove_seekfile=False)

        self.assertEqual(log.get_state(), LogChecker.STATE_WARNING)
        self.assertEqual(log.get_message(), 'WARNING: Found 1 lines (limit=1/0): Dec  5 12:34:59 hostname test: ERROR at %s' % self.logfile1)
开发者ID:bpineau,项目名称:check_log_ng,代码行数:35,代码来源:test_check_log_ng.py

示例2: test_replace_pipe_symbol

# 需要导入模块: from check_log_ng import LogChecker [as 别名]
# 或者: from check_log_ng.LogChecker import get_message [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

示例3: test_format

# 需要导入模块: from check_log_ng import LogChecker [as 别名]
# 或者: from check_log_ng.LogChecker import get_message [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

示例4: test_scantime_without_scantime

# 需要导入模块: from check_log_ng import LogChecker [as 别名]
# 或者: from check_log_ng.LogChecker import get_message [as 别名]
    def test_scantime_without_scantime(self):
        """--scantime option without scantime.
        """
        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": 2,
            "expiration": 691200
        }
        log = LogChecker(initial_data)

        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()

        time.sleep(4)
        log.check_log_multi(self.logfile_pattern, self.seekdir, remove_seekfile=False)

        self.assertEqual(log.get_state(), LogChecker.STATE_OK)
        self.assertEqual(log.get_message(), 'OK - No matches found.')
开发者ID:bpineau,项目名称:check_log_ng,代码行数:35,代码来源:test_check_log_ng.py

示例5: test_negpattern_with_multiple_lines

# 需要导入模块: from check_log_ng import LogChecker [as 别名]
# 或者: from check_log_ng.LogChecker import get_message [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

示例6: test_criticalpattern_with_case_sensitive

# 需要导入模块: from check_log_ng import LogChecker [as 别名]
# 或者: from check_log_ng.LogChecker import get_message [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

示例7: test_seekfile_tag

# 需要导入模块: from check_log_ng import LogChecker [as 别名]
# 或者: from check_log_ng.LogChecker import get_message [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

示例8: test_remove_seekfile_within_expiration

# 需要导入模块: from check_log_ng import LogChecker [as 别名]
# 或者: from check_log_ng.LogChecker import get_message [as 别名]
    def test_remove_seekfile_within_expiration(self):
        """--expiration and --remove-seekfile options
        """
        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": 2,
            "expiration": 10
        }
        log = LogChecker(initial_data)

        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()

        log.check_log_multi(self.logfile_pattern, self.seekdir, remove_seekfile=True)
        log.clear_state()
        time.sleep(4)

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

        # seek file of logfile1 should be purged.
        log.check_log_multi(self.logfile_pattern, self.seekdir, remove_seekfile=True)

        self.assertEqual(log.get_state(), LogChecker.STATE_WARNING)
        self.assertEqual(log.get_message(), 'WARNING: Found 1 lines (limit=1/0): Dec  5 12:34:59 hostname test: ERROR at %s' % self.logfile2)
        self.assertTrue(os.path.exists(self.seekfile1))
        self.assertTrue(os.path.exists(self.seekfile2))
开发者ID:bpineau,项目名称:check_log_ng,代码行数:48,代码来源:test_check_log_ng.py

示例9: test_logfile_with_filename

# 需要导入模块: from check_log_ng import LogChecker [as 别名]
# 或者: from check_log_ng.LogChecker import get_message [as 别名]
    def test_logfile_with_filename(self):
        """--logfile option with multiple filenames
        """
        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.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()

        time.sleep(1)

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

        logfile_pattern = "%s %s" % (self.logfile1, self.logfile2)
        log.check_log_multi(logfile_pattern, self.seekdir, remove_seekfile=False)

        self.assertEqual(log.get_state(), LogChecker.STATE_WARNING)
        self.assertEqual(log.get_message(), 'WARNING: Found 2 lines (limit=1/0): Dec  5 12:34:56 hostname test: ERROR at %s,Dec  5 12:34:59 hostname test: ERROR at %s' % (self.logfile1, self.logfile2))
开发者ID:bpineau,项目名称:check_log_ng,代码行数:44,代码来源:test_check_log_ng.py

示例10: test_trace_inode_without_expiration

# 需要导入模块: from check_log_ng import LogChecker [as 别名]
# 或者: from check_log_ng.LogChecker import get_message [as 别名]
    def test_trace_inode_without_expiration(self):
        """--trace_inode, --expiration and --remove-seekfile options
        """
        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": True,
            "multiline": False,
            "scantime": 2,
            "expiration": 3
        }
        log = LogChecker(initial_data)

        # create logfile
        f = open(self.logfile, 'a')
        f.write("Dec  5 12:34:50 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()

        # log rotation
        os.rename(self.logfile, self.logfile1)

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

        # do check_log_multi, and create seekfile and seekfile1
        log.check_log_multi(self.logfile_pattern, self.seekdir, remove_seekfile=True)
        log.clear_state()
        seekfile_1 = LogChecker.get_seekfile(self.logfile_pattern, self.seekdir, self.logfile, trace_inode=True)
        seekfile1_1 = LogChecker.get_seekfile(self.logfile_pattern, self.seekdir, self.logfile1, trace_inode=True)
        time.sleep(4)

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

        # log rotation, purge old logfile2
        os.rename(self.logfile1, self.logfile2)
        os.rename(self.logfile, self.logfile1)

        # seek file of old logfile1 should be purged.
        log.check_log_multi(self.logfile_pattern, self.seekdir, remove_seekfile=True)
        seekfile1_2 = LogChecker.get_seekfile(self.logfile_pattern, self.seekdir, self.logfile1, trace_inode=True)

        self.assertEqual(log.get_state(), LogChecker.STATE_WARNING)
        self.assertEqual(log.get_message(), 'WARNING: Found 1 lines (limit=1/0): Dec  5 12:34:59 hostname test: ERROR at %s' % self.logfile1)
        self.assertEqual(seekfile_1, seekfile1_2)
        self.assertFalse(os.path.exists(seekfile1_1))
        self.assertTrue(os.path.exists(seekfile1_2))
开发者ID:bpineau,项目名称:check_log_ng,代码行数:70,代码来源:test_check_log_ng.py

示例11: test_trace_inode

# 需要导入模块: from check_log_ng import LogChecker [as 别名]
# 或者: from check_log_ng.LogChecker import get_message [as 别名]
    def test_trace_inode(self):
        """--trace_inode
        """
        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": True,
            "multiline": False,
            "scantime": 86400,
            "expiration": 691200
        }
        log = LogChecker(initial_data)

        # create logfile
        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()

        # create seekfile of logfile
        log.check_log_multi(self.logfile_pattern, self.seekdir, remove_seekfile=False)
        log.clear_state()
        seekfile_1 = LogChecker.get_seekfile(self.logfile_pattern, self.seekdir, self.logfile, trace_inode=True)

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

        # log rotation
        os.rename(self.logfile, self.logfile1)

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

        # create seekfile of logfile
        log.check_log_multi(self.logfile_pattern, self.seekdir, remove_seekfile=False)
        seekfile_2 = LogChecker.get_seekfile(self.logfile_pattern, self.seekdir, self.logfile, trace_inode=True)
        seekfile1_2 = LogChecker.get_seekfile(self.logfile_pattern, self.seekdir, self.logfile1, trace_inode=True)

        self.assertEqual(log.get_state(), LogChecker.STATE_WARNING)
        self.assertEqual(log.get_message(), 'WARNING: Found 1 lines (limit=1/0): Dec  5 12:34:55 hostname test: ERROR at %s' % self.logfile1)
        self.assertEqual(seekfile_1, seekfile1_2)
        self.assertTrue(os.path.exists(seekfile_2))
        self.assertTrue(os.path.exists(seekfile1_2))
开发者ID:bpineau,项目名称:check_log_ng,代码行数:63,代码来源:test_check_log_ng.py


注:本文中的check_log_ng.LogChecker.get_message方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。