def inventory_kube_node( section_kube_node_info: Optional[NodeInfo], section_kube_node_kubelet: Optional[KubeletInfo], ) -> InventoryResult: if section_kube_node_info is None or section_kube_node_kubelet is None: return yield Attributes( path=["software", "applications", "kube", "node"], inventory_attributes={ "name": section_kube_node_info.name, "operating_system": section_kube_node_info.operating_system, "os_image": section_kube_node_info.os_image, "kernel_version": section_kube_node_info.kernel_version, "architecture": section_kube_node_info.architecture, "container_runtime_version": section_kube_node_info.container_runtime_version, "kubelet_version": section_kube_node_kubelet.version, "kube_proxy_version": section_kube_node_kubelet.proxy_version, }, ) for label in section_kube_node_info.labels.values(): yield TableRow( path=["software", "applications", "kube", "labels"], key_columns={"label_name": label.name}, inventory_columns={"label_value": label.value}, ) for address in section_kube_node_info.addresses: yield TableRow( path=["software", "applications", "kube", "network"], key_columns={"ip": address.address}, inventory_columns={"address_type": address.type_}, )
def test_inv_docker_node_images(): parsed = [line.split("\0") for line in AGENT_OUTPUT.split("\n")] plugin = agent_based_register.get_inventory_plugin(InventoryPluginName('docker_node_images')) assert plugin assert list(plugin.inventory_function(parsed)) == [ TableRow( path=['software', 'applications', 'docker', 'containers'], key_columns={ 'id': '891a6f6a1c28', 'image': 'b2bf42ca5d8f', 'name': '/relaxed_shaw', 'creation': '2021-02-12T12:15:28.230110819Z', 'labels': 'another_container_label: 2, container: label, image_label_command_line: 1, image_label_dockerfile: 2', 'status': 'running' }, inventory_columns={}, status_columns={}), TableRow(path=['software', 'applications', 'docker', 'images'], key_columns={'id': 'b2bf42ca5d8f'}, inventory_columns={ 'repotags': 'hello:world', 'repodigests': '', 'creation': '2021-02-12T11:29:33.063968737Z', 'size': 1231733, 'labels': 'image_label_command_line: 1, image_label_dockerfile: 2' }, status_columns={}), TableRow(path=['software', 'applications', 'docker', 'images'], key_columns={'id': 'b2bf42ca5d8f'}, inventory_columns={}, status_columns={'amount_containers': 1}), ]
def test_inventory() -> None: assert list(cap.inventory_checkmk_agent_plugins(_SECTION)) == [ TableRow( path=["software", "applications", "checkmk-agent", "plugins"], key_columns={"name": "mk_filestats.py"}, inventory_columns={ "version": "2.1.0i1", "cache_interval": None }, ), TableRow( path=["software", "applications", "checkmk-agent", "plugins"], key_columns={"name": "zorp"}, inventory_columns={ "version": "2.1.0i1", "cache_interval": 123 }, ), TableRow( path=["software", "applications", "checkmk-agent", "local_checks"], key_columns={"name": "sync_local_check.sh"}, inventory_columns={ "version": "3.14.15", "cache_interval": None }, ), ]
def _containers_to_table( container_specs: ContainerSpecs, container_statuses: Optional[PodContainers]) -> Iterable[TableRow]: if container_statuses is not None: for name, container_spec in container_specs.containers.items(): container_status = container_statuses.containers[name] yield TableRow( path=["software", "applications", "kube", "containers"], key_columns={"name": name}, inventory_columns={ "image_pull_policy": container_spec.image_pull_policy, "ready": "yes" if container_status.ready else "no", "restart_count": container_status.restart_count, "image": container_status.image, "image_id": container_status.image_id, "container_id": container_status.container_id, }, ) else: for name, container_spec in container_specs.containers.items(): yield TableRow( path=["software", "applications", "kube", "containers"], key_columns={"name": name}, inventory_columns={ "image_pull_policy": container_spec.image_pull_policy, "ready": "no", }, )
def inventory_kube_deployment( section_kube_deployment_info: Optional[DeploymentInfo], section_kube_deployment_strategy: Optional[DeploymentStrategy], ) -> InventoryResult: if section_kube_deployment_info is None or section_kube_deployment_strategy is None: return selector = section_kube_deployment_info.selector yield Attributes( path=["software", "applications", "kube", "deployment"], inventory_attributes={ "name": section_kube_deployment_info.name, "namespace": section_kube_deployment_info.namespace, "strategy": strategy_text(section_kube_deployment_strategy.strategy), "match_labels": match_labels_to_str(selector.match_labels), "match_expressions": match_expressions_to_str(selector.match_expressions), }, ) for label in section_kube_deployment_info.labels.values(): yield TableRow( path=["software", "applications", "kube", "labels"], key_columns={"label_name": label.name}, inventory_columns={"label_value": label.value}, )
def test_inventory(): yielded_inventory = list(inventory_oracle_tablespaces(Section)) assert yielded_inventory == [ TableRow( path=["software", "applications", "oracle", "tablespaces"], key_columns={ "sid": "CLUSTER", "name": "FOO" }, inventory_columns={ "version": "", "type": "TEMPORARY", "autoextensible": "YES" }, status_columns={ "current_size": 37748736000, "max_size": 41943040000, "used_size": 22271754240, "num_increments": 20, "increment_size": 4194304000, "free_space": 21768437760, }, ) ]
def inventory_esx_vsphere_clusters(section: Section) -> InventoryResult: for cluster_name, cluster_data in section.items(): yield TableRow( path=["software", "applications", "vmwareesx"], key_columns={ "cluster": cluster_name, "datacenter": cluster_data["datacenter"], "hostsystems": cluster_data["hostsystems"], "vms": cluster_data["vms"], }, )
def test_inv_docker_node_images_labels_null(): plugin = agent_based_register.get_inventory_plugin( InventoryPluginName('docker_node_images')) assert plugin assert list(plugin.inventory_function(AGENT_OUTPUT_NULL_LABELS_ST)) == [ TableRow(path=['software', 'applications', 'docker', 'images'], key_columns={'id': '666620a54926'}, inventory_columns={ 'repotags': 'plantuml:latest', 'repodigests': '', 'creation': '2021-02-25T08:42:22.47977742Z', 'size': 389770065, 'labels': '' }, status_columns={}), TableRow(path=['software', 'applications', 'docker', 'images'], key_columns={'id': '666620a54926'}, inventory_columns={}, status_columns={'amount_containers': 0}), ]
def test_inventory_lnx_if_no_bonding() -> None: assert [ e for e in lnx_if.inventory_lnx_if( lnx_if.parse_lnx_if([ ["[start_iplink]"], [ "1:", "wlp3s0:", "<BROADCAST,MULTICAST>", "mtu", "1500", "qdisc", "fq_codel", "state", "UP", "mode", "DORMANT", "group", "default", "qlen", "1000", ], [ "link/ether", "AA:AA:AA:AA:AA:AA", "brd", "BB:BB:BB:BB:BB:BB" ], ["[end_iplink]"], [ "wlp3s0", "130923553 201184 0 0 0 0 0 16078 23586281 142684 0 0 0 0 0 0" ], ]), None, ) if isinstance(e, TableRow) ] == [ TableRow( path=["networking", "interfaces"], key_columns={ "index": 1, "description": "wlp3s0", "alias": "wlp3s0", }, inventory_columns={ "speed": 0, "phys_address": "AA:AA:AA:AA:AA:AA", "oper_status": 2, "port_type": 6, "available": True, }, status_columns={}, ), ]
def test_inv_docker_node_images(fix_register): parsed = [line.split("\0") for line in AGENT_OUTPUT.split("\n")] plugin = fix_register.inventory_plugins[InventoryPluginName( "docker_node_images")] assert list(plugin.inventory_function(parsed)) == [ TableRow( path=["software", "applications", "docker", "containers"], key_columns={ "id": "891a6f6a1c28", "image": "b2bf42ca5d8f", "name": "/relaxed_shaw", "creation": "2021-02-12T12:15:28.230110819Z", "labels": "another_container_label: 2, container: label, image_label_command_line: 1, image_label_dockerfile: 2", "status": "running", }, inventory_columns={}, status_columns={}, ), TableRow( path=["software", "applications", "docker", "images"], key_columns={"id": "b2bf42ca5d8f"}, inventory_columns={ "repotags": "hello:world", "repodigests": "", "creation": "2021-02-12T11:29:33.063968737Z", "size": 1231733, "labels": "image_label_command_line: 1, image_label_dockerfile: 2", }, status_columns={}, ), TableRow( path=["software", "applications", "docker", "images"], key_columns={"id": "b2bf42ca5d8f"}, inventory_columns={}, status_columns={"amount_containers": 1}, ), ]
def test_inventory_fortisandbox_software(): assert sort_inventory_result( inventory_fortisandbox_software(SECTION)) == sort_inventory_result([ TableRow( path=["software", "applications", "fortinet", "fortisandbox"], key_columns={"name": "Tracer engine"}, inventory_columns={ "version": "5.2.50534", }, ), TableRow( path=["software", "applications", "fortinet", "fortisandbox"], key_columns={"name": "Rating engine"}, inventory_columns={ "version": "2.4.20034", }, ), TableRow( path=["software", "applications", "fortinet", "fortisandbox"], key_columns={"name": "System tools"}, inventory_columns={ "version": "3.2.279", }, ), TableRow( path=["software", "applications", "fortinet", "fortisandbox"], key_columns={"name": "Sniffer"}, inventory_columns={ "version": "4.478", }, ), TableRow( path=["software", "applications", "fortinet", "fortisandbox"], key_columns={"name": "Network alerts signature database"}, inventory_columns={ "version": "14.613", }, ), ])
def test_inventory_win() -> None: assert list(cap.inventory_checkmk_agent_plugins(_section( _OsType.win))) == [ TableRow( path=["software", "applications", "checkmk-agent", "plugins"], key_columns={"name": "zorp"}, inventory_columns={ "version": "2.1.0i1", "cache_interval": None }, ), TableRow( path=[ "software", "applications", "checkmk-agent", "local_checks" ], key_columns={"name": "sync_local_check.sh"}, inventory_columns={ "version": "3.14.15", "cache_interval": None }, ), ]
def test_inventory_fortisandbox_software(): assert list(inventory_fortisandbox_software(SECTION)) == [ TableRow( path=["software", "applications", "fortinet", "fortisandbox"], key_columns={'name': 'Tracer engine'}, inventory_columns={ 'version': '5.2.50534', }, ), TableRow( path=["software", "applications", "fortinet", "fortisandbox"], key_columns={'name': 'Rating engine'}, inventory_columns={ 'version': '2.4.20034', }, ), TableRow( path=["software", "applications", "fortinet", "fortisandbox"], key_columns={'name': 'System tools'}, inventory_columns={ 'version': '3.2.279', }, ), TableRow( path=["software", "applications", "fortinet", "fortisandbox"], key_columns={'name': 'Sniffer'}, inventory_columns={ 'version': '4.478', }, ), TableRow( path=["software", "applications", "fortinet", "fortisandbox"], key_columns={'name': 'Network alerts signature database'}, inventory_columns={ 'version': '14.613', }, ), ]
def test_inv_docker_node_images_labels_null(fix_register): plugin = fix_register.inventory_plugins[InventoryPluginName( "docker_node_images")] assert list(plugin.inventory_function(AGENT_OUTPUT_NULL_LABELS_ST)) == [ TableRow( path=["software", "applications", "docker", "images"], key_columns={"id": "666620a54926"}, inventory_columns={ "repotags": "plantuml:latest", "repodigests": "", "creation": "2021-02-25T08:42:22.47977742Z", "size": 389770065, "labels": "", }, status_columns={}, ), TableRow( path=["software", "applications", "docker", "images"], key_columns={"id": "666620a54926"}, inventory_columns={}, status_columns={"amount_containers": 0}, ), ]
def test_inv_docker_container_network(info): plugin = agent_based_register.get_inventory_plugin( InventoryPluginName('docker_container_network')) assert plugin assert list(plugin.inventory_function(info)) == [ TableRow( path=['software', 'applications', 'docker', 'container', 'networks'], key_columns={ 'name': 'bridge', 'network_id': '8f2baa1938b7957f876c1f5aa6767b86395b6971f349793bd7fae12eae6b83f0', 'ip_address': '172.17.0.2', 'ip_prefixlen': 16, 'gateway': '172.17.0.1', 'mac_address': '02:42:ac:11:00:02' }, inventory_columns={}, status_columns={}) ]
def inventory_kube_deployment( section_kube_deployment_info: Optional[DeploymentInfo], section_kube_deployment_spec: Optional[DeploymentSpec], ) -> InventoryResult: if section_kube_deployment_info is None or section_kube_deployment_spec is None: return yield Attributes( path=["software", "applications", "kube", "deployment"], inventory_attributes={ "name": section_kube_deployment_info.name, "namespace": section_kube_deployment_info.namespace, "strategy": strategy_text(section_kube_deployment_spec.strategy), }, ) for label in section_kube_deployment_info.labels.values(): yield TableRow( path=["software", "applications", "kube", "labels"], key_columns={"label_name": label.name}, inventory_columns={"label_value": label.value}, )
def test_inventory_docker_node_images_labels_null(): assert list( inventory_docker_node_images( parse_docker_node_images(AGENT_OUTPUT_NULL_LABELS_ST))) == [ TableRow( path=["software", "applications", "docker", "images"], key_columns={ "id": "666620a54926", }, inventory_columns={ "repotags": "plantuml:latest", "repodigests": "", "creation": "2021-02-25T08:42:22.47977742Z", "size": 389770065, "labels": "", }, status_columns={ "amount_containers": 0, }, ), ]
def labels_to_table(labels: Labels) -> Iterator[TableRow]: """Populate table of labels. This function is intended for usage with HW/SW inventory on a Kubernetes objects. It picks the correct path, and relies on the uniqueness of the label names of a Kubernetes objects. Using this function ensures a uniform look across inventories. Typical usage example: yield from labels_to_table(section_info.labels) >>> from cmk.base.plugins.agent_based.utils.kube import LabelName, Label >>> list(labels_to_table({LabelName("app"): Label(name="app", value="checkmk-cluster-agent")})) [TableRow(path=['software', 'applications', 'kube', 'labels'], key_columns={'label_name': 'app'}, inventory_columns={'label_value': 'checkmk-cluster-agent'}, status_columns={})] """ for label in labels.values(): yield TableRow( path=["software", "applications", "kube", "labels"], key_columns={"label_name": label.name}, inventory_columns={"label_value": label.value}, )
def test_inventory(): yielded_inventory = list(inventory_oracle_tablespaces(Section)) assert yielded_inventory == [ TableRow(path=['software', 'applications', 'oracle', 'tablespaces'], key_columns={ 'sid': 'CLUSTER', 'name': 'FOO' }, inventory_columns={ 'version': '', 'type': 'TEMPORARY', 'autoextensible': 'YES' }, status_columns={ 'current_size': 37748736000, 'max_size': 41943040000, 'used_size': 22271754240, 'num_increments': 20, 'increment_size': 4194304000, 'free_space': 21768437760 }) ]
["|size|1000215216|"], ["|uuid|ace42e00-955b-21fd-2ee4-ac0000000001|"], ["|device/address|0000:3b:00.0|"], ["|device/firmware_rev|80002111|"], ["|device/model|PC601 NVMe SK hynix 512GB |"], ["|device/serial|AJ98N635810808T29 |"], ], [ TableRow( path=["hardware", "storage", "disks"], key_columns={ "fsnode": "/sys/devices/pci0000:00/0000:00:1d.4/0000:3b:00.0/nvme/nvme0/nvme0n1", }, inventory_columns={ "firmware": "80002111", "product": "PC601 NVMe SK hynix 512GB", "serial": "AJ98N635810808T29", "signature": "ace42e00-955b-21fd-2ee4-ac0000000001", "size": 512110190592, }, status_columns={}, ), ], ), ], ) def test_lnx_block_devices(string_table, expected_result): assert sort_inventory_result( inventory_lnx_block_devices(parse_lnx_block_devices( string_table))) == sort_inventory_result(expected_result)
"FALSE", ], [ "XE", "processes", "100", "TRUE", ], ], [ TableRow( path=["software", "applications", "oracle", "systemparameter"], key_columns={ "sid": "XE", "name": "lock_name_space", }, inventory_columns={ "value": "", "isdefault": "TRUE", }, status_columns={}, ), TableRow( path=["software", "applications", "oracle", "systemparameter"], key_columns={ "sid": "XE", "name": "processes", }, inventory_columns={ "value": "100", "isdefault": "TRUE", },
({}, []), ( { "names": [ "name2", "name1", ] }, [ TableRow( path=[ "software", "applications", "kubernetes", "assigned_pods" ], key_columns={ "id": "name1", }, inventory_columns={}, status_columns={ "name": "name1", }, ), TableRow( path=[ "software", "applications", "kubernetes", "assigned_pods" ], key_columns={ "id": "name2", }, inventory_columns={},
speed=1000000000, oper_status=2, phys_address="74:DA:88:58:16:11", ), ], 4, None, [ TableRow( path=["networking", "interfaces"], key_columns={ "index": 1, "description": "Vlan-interface1", "alias": "", }, inventory_columns={ "speed": 0, "phys_address": "74:DA:88:58:16:11", "oper_status": 2, "port_type": 6, "available": True, }, status_columns={}, ), TableRow( path=["networking", "interfaces"], key_columns={ "index": 32769, "description": "port-channel 1", "alias": "", }, inventory_columns={
def test_inv_oracle_instance_multiline() -> None: lines = [ [ "SID", "VERSION", "OPENMODE", "LOGINS", "_ARCHIVER", "123", "_DBID", "LOGMODE", "_DATABASE_ROLE", "_FORCE_LOGGING", "_NAME", "080220151025", "_PLUGGABLE", "_CON_ID", "", "_PDBID", "_POPENMODE", "_PRESTRICTED", "_PTOTAL_SIZE", "_PRECOVERY_STATUS", "_PUP_SECONDS", "_PBLOCK_SIZE", ], [ "SID", "VERSION", "_OPENMODE", "LOGINS", "_ARCHIVER", "_RAW_UP_SECONDS", "_DBID", "LOGMODE", "_DATABASE_ROLE", "_FORCE_LOGGING", "_NAME", "080220151026", "TRUE", "_CON_ID", "PNAME", "_PDBID", "POPENMODE", "_PRESTRICTED", "_PTOTAL_SIZE", "_PRECOVERY_STATUS", "456", "_PBLOCK_SIZE", ], ] expected_data = [ TableRow( path=["software", "applications", "oracle", "instance"], key_columns={ "sid": "SID", }, inventory_columns={ "pname": "", "version": "VERSION", "openmode": "OPENMODE", "logmode": "LOGMODE", "logins": "LOGINS", "db_creation_time": "2015-02-08 10:25", }, status_columns={ "db_uptime": 123, }, ), TableRow( path=["software", "applications", "oracle", "instance"], key_columns={ "sid": "SID", }, inventory_columns={ "pname": "PNAME", "version": "VERSION", "openmode": "POPENMODE", "logmode": "LOGMODE", "logins": "ALLOWED", "db_creation_time": "2015-02-08 10:26", }, status_columns={ "db_uptime": 456, }, ), ] assert list(inventory_oracle_instance( parse_oracle_instance(lines))) == expected_data
[ "SID", "VERSION", ], [], ), ( ["SID", "VERSION", "OPENMODE", "LOGINS", "_UNUSED1", "_UNUSED2"], [ TableRow( path=["software", "applications", "oracle", "instance"], key_columns={ "sid": "SID", }, inventory_columns={ "pname": None, "version": "VERSION", "openmode": "OPENMODE", "logmode": None, "logins": "LOGINS", "db_creation_time": None, }, ), ], ), ( [ "SID", "VERSION", "OPENMODE", "LOGINS", "_ARCHIVER",
], [ "direct", "255.255.255.255", "255.255.255.255", "0.0.0.0", "Microsoft Failover Cluster Virtual Adapter", ], ], [ TableRow( path=["networking", "routes"], key_columns={ "target": "0.0.0.0/0", "gateway": "11.112.81.1", }, inventory_columns={ "device": "vmxnet3 Ethernet Adapter #2", "type": "indirect", }, status_columns={}, ), TableRow( path=["networking", "routes"], key_columns={ "target": "11.112.81.0/24", "gateway": "0.0.0.0", }, inventory_columns={ "device": "vmxnet3 Ethernet Adapter #2", "type": "direct", },
"kernel", "scope", "link", "src", "10.10.0.41", "metric", "9", ], ], [ TableRow( path=["networking", "routes"], key_columns={ "target": "0.0.0.0/0", "gateway": "10.10.0.1", }, inventory_columns={ "type": "gateway", "device": "wlan", }, status_columns={}, ), TableRow( path=["networking", "routes"], key_columns={ "target": "10.10.0.0/16", "gateway": None, }, inventory_columns={ "type": "local", "device": "wlan0", },
"section, expected_result", [ ({}, []), ( _SECTION, [ TableRow( path=[ "software", "applications", "kubernetes", "pod_container" ], key_columns={ "name": "pi", }, inventory_columns={ "image": "perl", "image_pull_policy": "Always", "image_id": "5cada8a3709c", }, status_columns={ "ready": "no", "restart_count": 0, "container_id": "94d698838e88", }, ), ], ), ], ) def test_inventory_k8s_pod_container(section, expected_result): assert list(inventory_k8s_pod_container(section)) == expected_result
[ Attributes( path=["software", "applications", "kube", "deployment"], inventory_attributes={ "name": "oh-lord", "namespace": "have-mercy", "strategy": "RollingUpdate (max surge: 25%, max unavailable: 25%)", "match_labels": "", "match_expressions": "", }, status_attributes={}, ), TableRow( path=["software", "applications", "kube", "labels"], key_columns={"label_name": "app"}, inventory_columns={"label_value": "checkmk-cluster-agent"}, status_columns={}, ), ], id="overall look of deployment inventory", ), ], ) def test_inventory_kube_deployment( section_info: DeploymentInfo, section_strategy: DeploymentStrategy, expected_check_result: Sequence[Any], ) -> None: assert list(inventory_kube_deployment( section_info, section_strategy)) == expected_check_result
["ServiceName", " E1G60"], ["Speed", " 1000000000"], ["Address", " 192.168.178.26"], ["Subnet", " 255.255.255.0"], ["DefaultGateway", " 192.168.178.1"], ], [ TableRow( path=["hardware", "nwadapter"], key_columns={ "name": " Intel(R) PRO/1000 MT-Desktopadapter 1", }, inventory_columns={ "type": " Ethernet 802.3", "macaddress": " 08:00:27:9C:F8:39", "speed": 1000000000, "gateway": " 192.168.178.1", "ipv4_address": ", 192.168.178.26", "ipv6_address": None, "ipv4_subnet": "255.255.255.0", "ipv6_subnet": None, }, status_columns={}, ), TableRow( path=["hardware", "nwadapter"], key_columns={ "name": " Intel(R) PRO/1000 MT-Desktopadapter 2", }, inventory_columns={ "type": " Ethernet 802.3",