示例#1
0
def test_cluster_received_no_data() -> None:
    assert utils.cluster_received_no_data([
        HostKey(HostName("node1"), HostAddress("1.2.3.4"), SourceType.HOST),
        HostKey(HostName("node2"), HostAddress("1.2.3.4"), SourceType.HOST),
    ]) == (
        3,
        "Clustered service received no monitoring data (configured nodes: node1, node2)",
        [],
    )
示例#2
0
 def fetcher(self, file_cache: NoCache) -> PiggybackFetcher:
     return PiggybackFetcher(
         file_cache,
         hostname=HostName("host"),
         address=HostAddress("1.2.3.4"),
         time_settings=[],
     )
示例#3
0
def test_get_section_kwargs(
        required_sections: List[str],
        expected_result: Dict[str, Dict[str, str]]) -> None:

    node_sections = AgentHostSections(
        sections={
            SectionName("one"): NODE_1,
            SectionName("two"): NODE_1,
            SectionName("three"): NODE_1,
        })

    host_key = HostKey(HostName("node1"), HostAddress("127.0.0.1"),
                       SourceType.HOST)

    parsed_sections_broker = ParsedSectionsBroker({
        host_key: (
            ParsedSectionsResolver(section_plugins=[
                SECTION_ONE, SECTION_TWO, SECTION_THREE, SECTION_FOUR
            ]),
            SectionsParser(host_sections=node_sections),
        ),
    })

    kwargs = get_section_kwargs(
        parsed_sections_broker,
        host_key,
        [ParsedSectionName(n) for n in required_sections],
    )

    assert expected_result == kwargs
示例#4
0
def test_get_section_cluster_kwargs(required_sections: Sequence[str],
                                    expected_result: Dict[str, Any]) -> None:

    node1_sections = HostSections[AgentRawDataSection](
        sections={
            SectionName("one"): NODE_1,
            SectionName("two"): NODE_1,
            SectionName("three"): NODE_1,
        })

    node2_sections = HostSections[AgentRawDataSection](
        sections={
            SectionName("two"): NODE_2,
            SectionName("three"): NODE_2,
        })

    parsed_sections_broker = ParsedSectionsBroker({
        HostKey(HostName("node1"), HostAddress("127.0.0.1"), SourceType.HOST):
        (
            ParsedSectionsResolver(section_plugins=[
                SECTION_ONE, SECTION_TWO, SECTION_THREE, SECTION_FOUR
            ], ),
            SectionsParser(host_sections=node1_sections,
                           host_name=HostName("node1")),
        ),
        HostKey(HostName("node2"), HostAddress("127.0.0.1"), SourceType.HOST):
        (
            ParsedSectionsResolver(section_plugins=[
                SECTION_ONE, SECTION_TWO, SECTION_THREE, SECTION_FOUR
            ], ),
            SectionsParser(host_sections=node2_sections,
                           host_name=HostName("node2")),
        ),
    })

    kwargs = get_section_cluster_kwargs(
        parsed_sections_broker,
        [
            HostKey(HostName("node1"), HostAddress("127.0.0.1"),
                    SourceType.HOST),
            HostKey(HostName("node2"), HostAddress("127.0.0.1"),
                    SourceType.HOST),
        ],
        [ParsedSectionName(n) for n in required_sections],
    )

    assert expected_result == kwargs
示例#5
0
文件: misc.py 项目: petrows/checkmk
def normalize_ip_addresses(ip_addresses: Union[str, Sequence[str]]) -> List[HostAddress]:
    """Expand 10.0.0.{1,2,3}."""
    if isinstance(ip_addresses, str):
        ip_addresses = ip_addresses.split()

    expanded = [HostAddress(word) for word in ip_addresses if '{' not in word]
    for word in ip_addresses:
        if word in expanded:
            continue

        try:
            prefix, tmp = word.split('{')
            curly, suffix = tmp.split('}')
        except ValueError:
            raise MKGeneralException(f"could not expand {word!r}")
        expanded.extend(HostAddress(f"{prefix}{i}{suffix}") for i in curly.split(','))

    return expanded
示例#6
0
def test_get_parsed_section(node_sections: AgentHostSections,
                            expected_result: Mapping) -> None:

    parsed_sections_broker = ParsedSectionsBroker({
        HostKey(HostName("node1"), HostAddress("127.0.0.1"), SourceType.HOST):
        (
            ParsedSectionsResolver(section_plugins=[
                SECTION_ONE, SECTION_TWO, SECTION_THREE, SECTION_FOUR
            ], ),
            SectionsParser(host_sections=node_sections),
        ),
    })

    content = parsed_sections_broker.get_parsed_section(
        HostKey(HostName("node1"), HostAddress("127.0.0.1"), SourceType.HOST),
        ParsedSectionName("parsed"),
    )

    assert expected_result == content
示例#7
0
    def deserialize(self, raw: bytes) -> Mapping[IPLookupCacheId, HostAddress]:
        loaded_object = self._dim_serializer.deserialize(raw)
        assert isinstance(loaded_object, dict)

        return {
            (HostName(k), socket.AF_INET)  # old pre IPv6 style
            if isinstance(k, str) else (HostName(k[0]), {
                4: socket.AF_INET,
                6: socket.AF_INET6
            }[k[1]]): HostAddress(v)
            for k, v in loaded_object.items()
        }
示例#8
0
def fixture_snmp_config() -> SNMPHostConfig:
    return SNMPHostConfig(
        is_ipv6_primary=False,
        hostname=HostName("bob"),
        ipaddress=HostAddress("1.2.3.4"),
        credentials="public",
        port=42,
        is_bulkwalk_host=False,
        is_snmpv2or3_without_bulkwalk_host=False,
        bulk_walk_size_of=0,
        timing={},
        oid_range_limits={},
        snmpv3_contexts=[],
        character_encoding=None,
        is_usewalk_host=False,
        snmp_backend=SNMPBackendEnum.CLASSIC,
    )
# Copyright (C) 2019 tribe29 GmbH - License: GNU General Public License v2
# This file is part of Checkmk (https://checkmk.com). It is subject to the terms and
# conditions defined in the file COPYING, which is part of this source code package.

import pytest
from _pytest.monkeypatch import MonkeyPatch

from tests.testlib.base import Scenario

from cmk.utils.type_defs import HostAddress, HostName, result

from cmk.core_helpers.agent import AgentRawDataSection
from cmk.core_helpers.host_sections import HostSections

from cmk.base.sources.piggyback import PiggybackSource


@pytest.mark.parametrize("ipaddress", [None, HostAddress("127.0.0.1")])
def test_attribute_defaults(monkeypatch: MonkeyPatch, ipaddress: HostAddress) -> None:
    hostname = HostName("testhost")
    ts = Scenario()
    ts.add_host(hostname)
    ts.apply(monkeypatch)

    source = PiggybackSource(hostname, ipaddress)
    assert source.hostname == hostname
    assert source.ipaddress == ipaddress
    assert source.description.startswith("Process piggyback data from")
    assert not source.summarize(result.OK(HostSections[AgentRawDataSection]()))
    assert source.id == "piggyback"