def inventory_kube_daemonset( section_kube_daemonset_info: Optional[DaemonSetInfo], section_kube_update_strategy: Optional[UpdateStrategy], ) -> InventoryResult: if section_kube_daemonset_info is None or section_kube_update_strategy is None: return yield Attributes( path=["software", "applications", "kube", "metadata"], inventory_attributes={ "object": "DaemonSet", "name": section_kube_daemonset_info.name, "namespace": section_kube_daemonset_info.namespace, }, ) selector = section_kube_daemonset_info.selector yield Attributes( path=["software", "applications", "kube", "daemonset"], inventory_attributes={ "strategy": strategy_text(section_kube_update_strategy.strategy), "match_labels": match_labels_to_str(selector.match_labels), "match_expressions": match_expressions_to_str(selector.match_expressions), }, ) yield from labels_to_table(section_kube_daemonset_info.labels)
def inventory_kube_pod( section_kube_pod_info: Optional[PodInfo], section_kube_pod_containers: Optional[PodContainers], section_kube_pod_init_containers: Optional[PodContainers], section_kube_pod_container_specs: Optional[ContainerSpecs], section_kube_pod_init_container_specs: Optional[ContainerSpecs], ) -> InventoryResult: if (section_kube_pod_info is None or section_kube_pod_container_specs is None or section_kube_pod_init_container_specs is None): return yield Attributes( path=["software", "applications", "kube", "metadata"], inventory_attributes={ "name": section_kube_pod_info.name, "namespace": section_kube_pod_info.namespace, }, ) yield Attributes( path=["software", "applications", "kube", "pod"], inventory_attributes={ "dns_policy": section_kube_pod_info.dns_policy, "host_ip": section_kube_pod_info.host_ip, "host_network": section_kube_pod_info.host_network, "node": section_kube_pod_info.node, "pod_ip": section_kube_pod_info.pod_ip, "qos_class": section_kube_pod_info.qos_class, }, ) yield from labels_to_table(section_kube_pod_info.labels) yield from _containers_to_table(section_kube_pod_container_specs, section_kube_pod_containers) yield from _containers_to_table(section_kube_pod_init_container_specs, section_kube_pod_init_containers)
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", "metadata"], inventory_attributes={ "name": section_kube_node_info.name, }, ) yield Attributes( path=["software", "applications", "kube", "node"], inventory_attributes={ "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 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_}, ) yield from labels_to_table(section_kube_node_info.labels)
def test_inventroy_fritz(): assert list( inventory_fritz({"VersionOS": "Fritz!OS 1970.12.19", "VersionDevice": "Tyson Beckford"}) ) == [ Attributes(path=["hardware", "system"], inventory_attributes={"model": "Tyson Beckford"}), Attributes( path=["software", "os"], inventory_attributes={"version": "Fritz!OS 1970.12.19"} ), ]
def inventory_kube_cluster(section: ClusterInfo, ) -> InventoryResult: yield Attributes( path=["software", "applications", "kube", "metadata"], inventory_attributes={ "name": section.name, }, ) yield Attributes( path=["software", "applications", "kube", "cluster"], inventory_attributes={ "version": section.version, }, )
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_inv_docker_container_node_name(section: Section) -> None: assert list(inventory_docker_container_node_name(section)) == [ Attributes( path=["software", "applications", "docker", "container"], inventory_attributes={"node_name": "klappben"}, status_attributes={}, ) ]
def test_inventory_fortisandbox_system(): assert list(inventory_fortisandbox_system(['v2.52-build0340 (GA)'])) == [ Attributes( path=['software', 'os'], inventory_attributes={ 'Version': 'v2.52-build0340 (GA)', }, ), ]
def test_allnet_ip_sensoric(section: ais.Section) -> None: assert list(ais.inventory_allnet_ip_sensoric(section)) == [ Attributes( path=["hardware", "system"], inventory_attributes={ "model": "ALL5000", }, ), ]
def test_inventory_fortisandbox_system(): assert list(inventory_fortisandbox_system(["v2.52-build0340 (GA)"])) == [ Attributes( path=["software", "os"], inventory_attributes={ "Version": "v2.52-build0340 (GA)", }, ), ]
def test_inventory(): # Setting the timezone is needed, otherwise test results will differ between jenkins and local # runs with set_timezone("UTC"): actual = sort_inventory_result(inv_esx_vsphere_hostsystem(section)) assert actual == sort_inventory_result([ Attributes( path=["hardware", "cpu"], inventory_attributes={ "max_speed": 2933437096.0, "cpus": "2", "cores": "12", "threads": "24", "model": "Intel(R) Xeon(R) CPU X5670 @ 2.93GHz", "vendor": "intel", "bus_speed": 133338039.0, "cores_per_cpu": 6.0, "threads_per_cpu": 12.0, }, status_attributes={}, ), Attributes( path=["software", "bios"], inventory_attributes={ "version": "-[ABIOSVERSION-1.0]-", "date": "2000-01-26" }, status_attributes={}, ), Attributes( path=["hardware", "system"], inventory_attributes={ "product": "System x1 M3 -[123456]-", "vendor": "IBM", "uuid": "bar-foo", }, status_attributes={}, ), Attributes( path=["hardware", "memory"], inventory_attributes={"total_ram_usable": 146016378880.0}, status_attributes={}, ), ])
def test_inv_docker_container_node_name(): info = [line.split("\0") for line in AGENT_OUTPUT.split("\n")] plugin = agent_based_register.get_inventory_plugin( InventoryPluginName('docker_container_node_name')) assert plugin assert list(plugin.inventory_function(info)) == [ Attributes(path=['software', 'applications', 'docker', 'container'], inventory_attributes={'node_name': 'klappben'}, status_attributes={}) ]
def test_inv_docker_container_node_name(fix_register): info = [line.split("\0") for line in AGENT_OUTPUT.split("\n")] plugin = fix_register.inventory_plugins[InventoryPluginName( "docker_container_node_name")] assert list(plugin.inventory_function(info)) == [ Attributes( path=["software", "applications", "docker", "container"], inventory_attributes={"node_name": "klappben"}, status_attributes={}, ) ]
def inventory_kube_namespace( section: NamespaceInfo, ) -> InventoryResult: yield Attributes( path=["software", "applications", "kube", "metadata"], inventory_attributes={ "object": "Namespace", "name": section.name, "namespace": section.name, }, )
def test_inventory(section: abl.Section) -> None: assert list(abl.inventory_aix_baselevel(section)) == [ Attributes( path=["software", "os"], inventory_attributes={ "version": "some version", "vendor": "IBM", "type": "aix", "name": "IBM AIX some version", }, ), ]
def test_inventory_lnx_if_empty() -> None: assert list(lnx_if.inventory_lnx_if(lnx_if.parse_lnx_if([]), None)) == [ Attributes( path=["networking"], inventory_attributes={ "available_ethernet_ports": 0, "total_ethernet_ports": 0, "total_interfaces": 0, }, status_attributes={}, ), ]
def test_fortimail_serial_inventory(): assert list( inventory_fortimail_system( { "model": "FortiMail-VM", "serial": "FEVM1234567890", "os": "v5.4,build719,180328 (5.4.5 GA)", }, ), ) == [ Attributes( path=["hardware", "system"], inventory_attributes={ "model": "FortiMail-VM", "serial": "FEVM1234567890", }, ), Attributes( path=["software", "operating_system"], inventory_attributes={ "version": "v5.4,build719,180328 (5.4.5 GA)", }, ), ]
def test_inventory_fortiauthenticator_system(): assert sort_inventory_result( inventory_fortiauthenticator_system({ "model": "FACVM", "serial": "FAC-VMTM18000123", })) == sort_inventory_result([ Attributes( path=["hardware", "system"], inventory_attributes={ "Model": "FACVM", "Serial number": "FAC-VMTM18000123", }, ), ])
def test_inventory_fortiauthenticator_system(): assert list( inventory_fortiauthenticator_system({ 'model': 'FACVM', 'serial': 'FAC-VMTM18000123', })) == [ Attributes( path=['hardware', 'system'], inventory_attributes={ 'Model': 'FACVM', 'Serial number': 'FAC-VMTM18000123', }, ), ]
def test_inventory_win_bios(section: Mapping[str, Union[str, int]]) -> None: assert list(inventory_win_bios({ **section, "date": 0 })) == [ # aviod TZ issues in C Attributes( path=["software", "bios"], inventory_attributes={ "date": 0, "model": "Default System BIOS", "vendor": "innotek GmbH", "version": "VirtualBox 2.5", }, ) ]
def inventory_win_bios(section: Mapping[str, Union[str, int]]): attr = { k: section[k] for k in ("date", "model", "vendor", "version") if k in section } with suppress(KeyError): attr[ "version"] = f"{section['smbios_version']} {section['major_version']}.{section['minor_version']}" yield Attributes( path=["software", "bios"], inventory_attributes=attr, )
def test_inv_docker_container_labels(): info = [line.split("\0") for line in AGENT_OUTPUT.split("\n")] assert list(inventory_docker_container_labels(parse_docker_container_labels(info))) == [ Attributes(path=['software', 'applications', 'docker', 'container'], inventory_attributes={ 'labels': ('com.docker.swarm.node.id: x2my5tv8bqg0yh5jq98gzodr2, ' 'com.docker.swarm.service.id: nrgxet23d204ywz1rjl8fbtff, ' 'com.docker.swarm.service.name: redis, ' 'com.docker.swarm.task: , ' 'com.docker.swarm.task.id: jjp7380fb51n4figvv4zxl350, ' 'com.docker.swarm.task.name: redis.1.jjp7380fb51n4figvv4zxl350') }, status_attributes={}) ]
def test_inventory_fritz() -> None: assert list(inventory_fritz(_SECTION)) == [ Attributes( path=["hardware", "system"], inventory_attributes={"model": "AVM FRITZ!Box 7412 (UI)"}, ), Attributes( path=["software", "os"], inventory_attributes={"version": "137.06.83"}, ), Attributes( path=["software", "applications", "fritz"], inventory_attributes={ "link_type": "PPPoE", "wan_access_type": "DSL", "auto_disconnect_time": "0", "dns_server_1": "217.237.148.102", "dns_server_2": "217.237.151.115", "voip_dns_server_1": "217.237.148.102", "voip_dns_server_2": "217.237.151.115", "upnp_config_enabled": "1", }, ), ]
def test_inventory(): # Setting the timezone is needed, otherwise test results will differ between jenkins and local # runs with set_timezone("UTC"): actual = list(inv_esx_vsphere_hostsystem(section)) assert actual == [ Attributes(path=['hardware', 'cpu'], inventory_attributes={ 'max_speed': '2.93 GHz', 'cpus': '2', 'cores': '12', 'threads': '24', 'model': 'Intel(R) Xeon(R) CPU X5670 @ 2.93GHz', 'vendor': 'intel', 'bus_speed': '133 MHz', 'cores_per_cpu': '6', 'threads_per_cpu': '12' }, status_attributes={}), Attributes(path=['software', 'bios'], inventory_attributes={ 'version': '-[ABIOSVERSION-1.0]-', 'date': '2000-01-26' }, status_attributes={}), Attributes(path=['hardware', 'system'], inventory_attributes={ 'product': 'System x1 M3 -[123456]-', 'vendor': 'IBM', 'uuid': 'bar-foo' }, status_attributes={}), Attributes(path=['hardware', 'memory'], inventory_attributes={'total_ram_usable': '136 GiB'}, status_attributes={}), ]
def test_inv_docker_node_network(): pre_parsed = [line.split("\0") for line in AGENT_OUTPUT.split("\n")] result = inventory_docker_node_network( parse_docker_node_network(pre_parsed)) assert list(result) == [ Attributes( path=['software', 'applications', 'docker', 'networks', 'asd'], inventory_attributes={ 'name': 'asd', 'network_id': 'f42d7f03e6d7', 'scope': 'local', 'labels': 'label_asd: 1, label_asd_2: 2' }, status_attributes={}), ]
def test_inventory_fortigate_ha(): assert list(inventory_fortigate_ha(SECTION)) == [ Attributes( path=[ 'software', 'applications', 'fortinet', 'fortigate_high_availability' ], inventory_attributes={ 'Mode': 'activePassive', 'Priority': '128', 'Schedule': 'roundRobin', 'Group ID': '11', 'Group Name': 'SZAG-DE-SAR-FF', }, ), ]
def test_inventory_fortigate_ha(): assert list(inventory_fortigate_ha(SECTION)) == [ Attributes( path=[ "software", "applications", "fortinet", "fortigate_high_availability" ], inventory_attributes={ "Mode": "activePassive", "Priority": "128", "Schedule": "roundRobin", "Group ID": "11", "Group Name": "SZAG-DE-SAR-FF", }, ), ]
def test_inventory_lnx_cpuinfo(section_1: Section) -> None: assert list(inventory_lnx_cpuinfo(section_1)) == [ Attributes( path=["hardware", "cpu"], inventory_attributes={ "vendor": "amd", "model": "Common KVM processor", "cache_size": 524288, "threads_per_cpu": 2, "cores_per_cpu": 2, "arch": "x86_64", "cores": 6, "threads": 6, "cpus": 3, }, ), ]
def test_inv_docker_node_network(): pre_parsed = [line.split("\0") for line in AGENT_OUTPUT.split("\n")] assert sort_inventory_result( inventory_docker_node_network( parse_docker_node_network(pre_parsed))) == sort_inventory_result([ Attributes( path=[ "software", "applications", "docker", "networks", "asd" ], inventory_attributes={ "name": "asd", "network_id": "f42d7f03e6d7", "scope": "local", "labels": "label_asd: 1, label_asd_2: 2", }, status_attributes={}, ), ])
def test_inv_docker_container_labels(): info = [ line.split("\0") if "\0" in line else line.split(" ") for line in AGENT_OUTPUT.split("\n") ] plugin = agent_based_register.get_inventory_plugin( InventoryPluginName('docker_container_labels')) assert plugin assert list(plugin.inventory_function(info)) == [ Attributes(path=['software', 'applications', 'docker', 'container'], inventory_attributes={ 'labels': ('com.docker.swarm.node.id: x2my5tv8bqg0yh5jq98gzodr2, ' 'com.docker.swarm.service.id: nrgxet23d204ywz1rjl8fbtff, ' 'com.docker.swarm.service.name: redis, ' 'com.docker.swarm.task: , ' 'com.docker.swarm.task.id: jjp7380fb51n4figvv4zxl350, ' 'com.docker.swarm.task.name: redis.1.jjp7380fb51n4figvv4zxl350') }, status_attributes={}) ]