def test_cronjob_piggyback_option(): """Test the cronjob piggyback option""" agent = SpecialAgent("agent_kube") arguments = agent.argument_func( { "cluster-name": "cluster", "token": ("password", "token"), "kubernetes-api-server": { "endpoint": "https://11.211.3.32", "verify-cert": False, "proxy": ("no_proxy", "no_proxy"), }, "monitored-objects": ["pods", "cronjobs_pods"], }, "host", "11.211.3.32", ) assert arguments == [ "--cluster", "cluster", "--token", "token", "--monitored-objects", "pods", "cronjobs_pods", "--api-server-endpoint", "https://11.211.3.32", "--api-server-proxy", "NO_PROXY", ]
def test_agent_graylog_arguments_password_store() -> None: agent = SpecialAgent("agent_graylog") params = { "user": "******", "password": ("password", "passwd"), "instance": "test", "protocol": "https", "sections": ["alerts"], "since": 1800, "display_node_details": "host", "display_sidecar_details": "host", "display_source_details": "host", } assert agent.argument_func(params, "testhost", "1.2.3.4") == [ "-P", "https", "-m", "alerts", "-t", 1800, "-u", "user", "-s", "passwd", "--display_node_details", "host", "--display_sidecar_details", "host", "--display_source_details", "host", "test", ]
def test_parse_arguments_with_no_cluster_endpoint(): agent = SpecialAgent("agent_kube") params = { "cluster-name": "cluster", "token": ("password", "token"), "kubernetes-api-server": { "endpoint": "https://127.0.0.1", "verify-cert": False, "proxy": ("no_proxy", "no_proxy"), }, "monitored-objects": ["pods"], } arguments = agent.argument_func(params, "host", "127.0.0.1") assert arguments == [ "--cluster", "cluster", "--token", "token", "--monitored-objects", "pods", "--api-server-endpoint", "https://127.0.0.1", "--api-server-proxy", "NO_PROXY", ]
def test_proxy_arguments(params, expected_proxy_arg): agent = SpecialAgent("agent_kube") arguments = agent.argument_func(params, "host", "11.211.3.32") for argument, argument_after in zip(arguments[:-1], arguments[1:]): if argument == "--api-server-proxy": assert expected_proxy_arg == argument_after return assert False, "--api-server-proxy is missing"
def test_ipmi_sensors_argument_parsing( params: Mapping[str, Any], expected_args: Sequence[str], ) -> None: """Tests if all required arguments are present.""" agent = SpecialAgent("agent_ipmi_sensors") arguments = agent.argument_func(params, "host", "address") assert arguments == expected_args
def test_agent_mobileiron_arguments( params: Mapping[str, Any], expected_args: Sequence[Any], ) -> None: """Tests if all required arguments are present.""" agent = SpecialAgent("agent_mobileiron") arguments = agent.argument_func(params, "mobileironhostname", "address") assert arguments == expected_args
def test_agent_storeonce4x_arguments_password_store() -> None: params = { "user": "******", "password": "******", } agent = SpecialAgent("agent_storeonce4x") assert agent.argument_func( params, "testhost", "1.2.3.4") == ["username", "passwd", "testhost"]
def test_vsphere_argument_parsing( params: Dict, expected_args: List[str], ip_address: Optional[str], expected_host_address: str, ) -> None: """Tests if all required arguments are present.""" agent = SpecialAgent("agent_vsphere") arguments = agent.argument_func(params, "host", ip_address) assert arguments == expected_args + [expected_host_address]
def test_client_configuration_host(params: Mapping[str, Any], host) -> None: agent = SpecialAgent("agent_kube") arguments: List[str] = [] argument_raw: SpecialAgentInfoFunctionResult = agent.argument_func( params, "kubi", "127.0.0.1") # this does not feel right: assert isinstance(argument_raw, list) for element in argument_raw: assert isinstance(element, str) arguments.append(element) client = make_api_client(parse_arguments(arguments)) assert client.configuration.host == host
def test_agent_smb_share_arguments_password_store() -> None: params = { "authentication": ("user", ("password", "passwd")), "patterns": [], } agent = SpecialAgent("agent_smb_share") assert agent.argument_func(params, "testhost", "1.2.3.4") == [ "testhost", "1.2.3.4", "--username", "user", "--password", "passwd", ]
def test_client_configuration_host(params: Dict[str, Any], host: str) -> None: # black box test: wato config and corresponding url that is used by the special agent to query k8s agent = SpecialAgent("agent_kubernetes") arguments: List[str] = [] argument_raw: SpecialAgentInfoFunctionResult = agent.argument_func( params, "a-host-name", "192.168.1.1") # this does not feel right: assert isinstance(argument_raw, list) for element in argument_raw: assert isinstance(element, str) arguments.append(element) client = get_api_client(parse_arguments(arguments)) assert client.configuration.host == host
def test_agent_couchbase_arguments_password_store() -> None: params = { "authentication": ( "user", ("password", "passwd"), ) } agent = SpecialAgent("agent_couchbase") assert agent.argument_func(params, "testhost", "1.2.3.4") == [ "--username", "user", "--password", "passwd", "1.2.3.4", ]
def test_agent_vnx_quotas_arguments_password_store() -> None: params = { "user": "******", "password": "******", "nas_db": "", } agent = SpecialAgent("agent_vnx_quotas") assert agent.argument_func(params, "testhost", "1.2.3.4") == [ "-u", "username", "-p", "passwd", "--nas-db", "", "1.2.3.4", ]
def test_parse_namespace_patterns(): """Tests if all required arguments are present.""" agent = SpecialAgent("agent_kube") arguments = agent.argument_func( { "cluster-name": "cluster", "token": ("password", "token"), "kubernetes-api-server": { "endpoint": "https://11.211.3.32", "verify-cert": False, "proxy": ("no_proxy", "no_proxy"), }, "cluster-collector": { "endpoint": "https://11.211.3.32:20026", "verify-cert": False, }, "namespaces": ("namespace-include-patterns", ["default", "kube-system"]), }, "host", "11.211.3.32", ) assert arguments == [ "--cluster", "cluster", "--token", "token", "--monitored-objects", "nodes", "deployments", "pods", "--namespace-include-patterns", "default", "--namespace-include-patterns", "kube-system", "--api-server-endpoint", "https://11.211.3.32", "--api-server-proxy", "NO_PROXY", "--cluster-collector-endpoint", "https://11.211.3.32:20026", "--cluster-collector-proxy", "FROM_ENVIRONMENT", ]
def test_agent_jenkins_arguments_password_store() -> None: params = { "user": "******", "password": ("password", "passwd"), "instance": "test", "protocol": "https", } agent = SpecialAgent("agent_jenkins") assert agent.argument_func(params, "testhost", "1.2.3.4") == [ "-P", "https", "-u", "username", "-s", "passwd", "test", ]
def test_agent_splunk_arguments_password_store() -> None: params = { "user": "******", "password": ("password", "passwd"), "infos": "alerts", "protocol": "https", } agent = SpecialAgent("agent_splunk") assert agent.argument_func(params, "testhost", "1.2.3.4") == [ "-P", "https", "-m", "a l e r t s", "-u", "username", "-s", "passwd", "testhost", ]
def test_agent_elasticsearch_arguments_password_store() -> None: params = { "hosts": "testhost", "protocol": "https", "infos": ["cluster_health", "nodestats", "stats"], "user": "******", "password": ("password", "pass"), } agent = SpecialAgent("agent_elasticsearch") assert agent.argument_func(params, "testhost", "1.2.3.4") == [ "-P", "https", "-m", " ".join(params["infos"]), "-u", "user", "-s", "pass", ] + list(params["hosts"])
def test_agent_rabbitmq_arguments_password_store() -> None: params = { "user": "******", "password": ("password", "passwd"), "sections": "nodes", "protocol": "https", } agent = SpecialAgent("agent_rabbitmq") assert agent.argument_func(params, "testhost", "1.2.3.4") == [ "-P", "https", "-m", "n,o,d,e,s", "-u", "username", "-s", "passwd", "--hostname", "testhost", ]
def test_parse_namespace_patterns(): agent = SpecialAgent("agent_kube") arguments = agent.argument_func( { "cluster-name": "cluster", "token": ("password", "token"), "kubernetes-api-server": { "endpoint": "https://11.211.3.32", "verify-cert": False, "proxy": ("no_proxy", "no_proxy"), }, "monitored-objects": ["pods"], "namespaces": ("namespace-include-patterns", ["default", "kube-system"]), }, "host", "11.211.3.32", ) assert arguments == [ "--cluster", "cluster", "--token", "token", "--monitored-objects", "pods", "--namespace-include-patterns", "default", "--namespace-include-patterns", "kube-system", "--cluster-aggregation-exclude-node-roles", "control-plane", "infra", "--api-server-endpoint", "https://11.211.3.32", "--api-server-proxy", "NO_PROXY", ]
def test_ucs_bladecenter_argument_parsing(params, expected_args): """Tests if all required arguments are present.""" agent = SpecialAgent("agent_ucs_bladecenter") arguments = agent.argument_func(params, "host", "address") assert arguments == expected_args
def test_parse_arguments(params, expected_args): """Tests if all required arguments are present.""" agent = SpecialAgent("agent_kube") arguments = agent.argument_func(params, "host", "11.211.3.32") assert arguments == expected_args
def test_cisco_prime_argument_parsing(params, hostname, ipaddress, args): agent = SpecialAgent("agent_cisco_prime") arguments = agent.argument_func(params, hostname, ipaddress) assert arguments == args
def test_cluster_resource_aggregation(): """Test the cluster-resource-aggregation option""" agent = SpecialAgent("agent_kube") arguments = agent.argument_func( { "cluster-name": "cluster", "token": ("password", "token"), "kubernetes-api-server": { "endpoint": "https://11.211.3.32", "verify-cert": False, "proxy": ("no_proxy", "no_proxy"), }, "monitored-objects": ["pods"], "cluster-resource-aggregation": ( "cluster-aggregation-exclude-node-roles", ["control*", "worker"], ), }, "host", "11.211.3.32", ) assert arguments == [ "--cluster", "cluster", "--token", "token", "--monitored-objects", "pods", "--cluster-aggregation-exclude-node-roles", "control*", "worker", "--api-server-endpoint", "https://11.211.3.32", "--api-server-proxy", "NO_PROXY", ] arguments = agent.argument_func( { "cluster-name": "cluster", "token": ("password", "token"), "kubernetes-api-server": { "endpoint": "https://11.211.3.32", "verify-cert": False, "proxy": ("no_proxy", "no_proxy"), }, "monitored-objects": ["pods"], "cluster-resource-aggregation": "cluster-aggregation-include-all-nodes", }, "host", "11.211.3.32", ) assert arguments == [ "--cluster", "cluster", "--token", "token", "--monitored-objects", "pods", "--cluster-aggregation-include-all-nodes", "--api-server-endpoint", "https://11.211.3.32", "--api-server-proxy", "NO_PROXY", ] arguments = agent.argument_func( { "cluster-name": "cluster", "token": ("password", "token"), "kubernetes-api-server": { "endpoint": "https://11.211.3.32", "verify-cert": False, "proxy": ("no_proxy", "no_proxy"), }, "monitored-objects": ["pods"], }, "host", "11.211.3.32", ) assert arguments == [ "--cluster", "cluster", "--token", "token", "--monitored-objects", "pods", "--cluster-aggregation-exclude-node-roles", "control-plane", "infra", "--api-server-endpoint", "https://11.211.3.32", "--api-server-proxy", "NO_PROXY", ]
def test_host_labels_annotation_selection(): """Test the import-annotations option""" agent = SpecialAgent("agent_kube") # Option not set -> no annotations imported. This special case is covered # by test_parse_arguments. If test_parse_arguments is migrated, this # special case needs to be reconsidered. # Explicit no filtering arguments = agent.argument_func( { "cluster-name": "cluster", "token": ("password", "token"), "kubernetes-api-server": { "endpoint": "https://11.211.3.32", "verify-cert": False, "proxy": ("no_proxy", "no_proxy"), }, "import-annotations": "include-annotations-as-host-labels", "monitored-objects": ["pods"], }, "host", "11.211.3.32", ) assert arguments == [ "--cluster", "cluster", "--token", "token", "--monitored-objects", "pods", "--cluster-aggregation-exclude-node-roles", "control-plane", "infra", "--include-annotations-as-host-labels", "--api-server-endpoint", "https://11.211.3.32", "--api-server-proxy", "NO_PROXY", ] # Explicit filtering arguments = agent.argument_func( { "cluster-name": "cluster", "token": ("password", "token"), "kubernetes-api-server": { "endpoint": "https://11.211.3.32", "verify-cert": False, "proxy": ("no_proxy", "no_proxy"), }, "import-annotations": ( "include-matching-annotations-as-host-labels", "checkmk-monitoring$", ), "monitored-objects": ["pods"], }, "host", "11.211.3.32", ) assert arguments == [ "--cluster", "cluster", "--token", "token", "--monitored-objects", "pods", "--cluster-aggregation-exclude-node-roles", "control-plane", "infra", "--include-matching-annotations-as-host-labels", "checkmk-monitoring$", "--api-server-endpoint", "https://11.211.3.32", "--api-server-proxy", "NO_PROXY", ]
def test_ddn_s2a(params, result): agent = SpecialAgent("agent_ddn_s2a") arguments = agent.argument_func(params, "host", "address") assert arguments == result
def test_azure_argument_parsing(params, expected_args): """Tests if all required arguments are present.""" agent = SpecialAgent("agent_azure") arguments = agent.argument_func(params, "testhost", "address") assert arguments == expected_args
def test_allnet_ip_sensoric_argument_parsing(params, expected_args): """Tests if all required arguments are present.""" agent = SpecialAgent("agent_allnet_ip_sensoric") arguments = agent.argument_func(params, "host", "address") assert arguments == expected_args