コード例 #1
0
    def test_persist_option_populates_cache_info_and_persisted_sections(
        self,
        hostname,
        store,
        logger,
        monkeypatch,
    ):
        time_time = 1000
        time_delta = 50
        monkeypatch.setattr(time, "time", lambda: time_time)

        raw_data = b"\n".join((
            b"<<<section:persist(%i)>>>" % (time_time + time_delta),
            b"first line",
            b"second line",
        ))

        ahs = AgentParser(hostname, store, False, logger).parse(raw_data)

        assert ahs.sections == {
            SectionName("section"): [["first", "line"], ["second", "line"]]
        }
        assert ahs.cache_info == {
            SectionName("section"): (time_time, time_delta)
        }
        assert ahs.piggybacked_raw_data == {}
        assert ahs.persisted_sections == {
            SectionName("section"): (1000, 1050, [["first", "line"],
                                                  ["second", "line"]]),
        }
コード例 #2
0
    def test_piggyback_populates_piggyback_raw_data(
        self,
        hostname,
        store,
        logger,
        monkeypatch,
    ):
        time_time = 1000
        monkeypatch.setattr(time, "time", lambda: time_time)
        monkeypatch.setattr(config.HostConfig, "check_mk_check_interval", 10)

        raw_data = AgentRawData(b"\n".join((
            b"<<<<piggyback header>>>>",  # <- space is OK
            b"<<<section>>>",
            b"first line",
            b"second line",
            b"<<<<>>>>",  # <- omitting this line makes no difference
            b"<<<<piggyback_other>>>>",
            b"<<<other_section>>>",
            b"first line",
            b"second line",
            b"<<<<>>>>",
            b"<<<<../b:l*a../>>>>",
            b"<<<section>>>",
            b"first line",
            b"<<<</b_l-u/>>>>",
            b"<<<section>>>",
            b"first line",
        )))

        ahs = AgentParser(hostname, store, False, logger).parse(raw_data)

        assert ahs.sections == {}
        assert ahs.cache_info == {}
        assert ahs.piggybacked_raw_data == {
            "piggyback_header": [
                b"<<<section:cached(1000,900)>>>",
                b"first line",
                b"second line",
            ],
            "piggyback_other": [
                b"<<<other_section:cached(1000,900)>>>",
                b"first line",
                b"second line",
            ],
            ".._b_l_a.._": [
                b"<<<section:cached(1000,900)>>>",
                b"first line",
            ],
            "_b_l-u_": [
                b"<<<section:cached(1000,900)>>>",
                b"first line",
            ],
        }
        assert ahs.persisted_sections == PersistedSections[SNMPSectionContent](
            {})
コード例 #3
0
ファイル: test_agent.py プロジェクト: chill-uk/checkmk
    def test_raw_section_populates_sections(self, hostname, logger):
        raw_data = b"\n".join((
            b"<<<a_section>>>",
            b"first line",
            b"second line",
            b"<<<another_section>>>",
            b"first line",
            b"second line",
        ))

        ahs = AgentParser(hostname, Path(""),
                          logger).parse(Result.OK(raw_data)).ok

        assert ahs.sections == {
            SectionName("a_section"): [["first", "line"], ["second", "line"]],
            SectionName("another_section"): [["first", "line"],
                                             ["second", "line"]],
        }
        assert ahs.cache_info == {}
        assert ahs.piggybacked_raw_data == {}
        assert ahs.persisted_sections == {}
コード例 #4
0
    def test_raw_section_populates_sections(self, hostname, logger, store):
        raw_data = b"\n".join((
            b"<<<a_section>>>",
            b"first line",
            b"second line",
            b"<<<>>>",  # to be skipped
            b"<<<another_section>>>",
            b"first line",
            b"second line",
            b"<<<>>>",  # to be skipped
        ))

        ahs = AgentParser(hostname, store, False, logger).parse(raw_data)

        assert ahs.sections == {
            SectionName("a_section"): [["first", "line"], ["second", "line"]],
            SectionName("another_section"): [["first", "line"],
                                             ["second", "line"]],
        }
        assert ahs.cache_info == {}
        assert ahs.piggybacked_raw_data == {}
        assert ahs.persisted_sections == {}
コード例 #5
0
 def test_section_header_options(self, headerline, section_name,
                                 section_options):
     parsed_name, parsed_options = AgentParser._parse_section_header(
         headerline)
     assert parsed_name == section_name
     assert parsed_options == section_options
コード例 #6
0
ファイル: test_agent.py プロジェクト: arusa/checkmk
 def parser(self, hostname, store, logger):
     return AgentParser(hostname, store, logger)