def test_discovered_host_labels_add(): labels_1 = DiscoveredHostLabels() labels_1.add_label(HostLabel(u"äbc", u"123", "plugin_1")) labels_2 = DiscoveredHostLabels() labels_2.add_label(HostLabel(u"xyz", u"blä", "plugin_2")) new_labels = labels_1 + labels_2 assert new_labels.to_dict() == { u"äbc": { "value": u"123", "plugin_name": "plugin_1", }, u"xyz": { "value": u"blä", "plugin_name": "plugin_2", }, } labels_1 += labels_2 assert labels_1.to_dict() == { u"äbc": { "value": u"123", "plugin_name": "plugin_1", }, u"xyz": { "value": u"blä", "plugin_name": "plugin_2", }, }
def test_discovered_host_labels_to_list(): labels = DiscoveredHostLabels() assert labels.to_list() == [] labels.add_label(HostLabel(u"äbc", u"123", "plugin_1")) labels.add_label(HostLabel(u"xyz", u"blä", "plugin_2")) assert labels.to_list() == [ HostLabel(u"xyz", u"blä", "plugin_2"), HostLabel(u"äbc", u"123", "plugin_1") ]
def test_discovered_host_labels_to_dict(): labels = DiscoveredHostLabels() assert labels.to_dict() == {} labels.add_label(HostLabel(u"äbc", u"123", "plugin_1")) labels.add_label(HostLabel(u"xyz", u"blä", "plugin_2")) assert labels.to_dict() == { u"äbc": { "value": u"123", "plugin_name": "plugin_1", }, u"xyz": { "value": u"blä", "plugin_name": "plugin_2", }, }
def test_discovered_host_labels_store_save(discovered_host_labels_dir): store = DiscoveredHostLabelsStore("host") labels = DiscoveredHostLabels(HostLabel(u"xyz", u"äbc")) label_dict = labels.to_dict() assert not store.file_path.exists() # pylint: disable=no-member store.save(label_dict) assert store.file_path.exists() # pylint: disable=no-member assert store.load() == label_dict
# yapf: disable from cmk_base.discovered_labels import HostLabel checkname = 'docker_node_info' info = [ [ '{"ID":"VAW5:RDCA:ATG7:24TV:Q7IJ:L33R:U5MX:XKXN:Z77K:AR22:QUE6:3JGL","Containers":0,"ContainersRunning":0,"ContainersPaused":0,"ContainersStopped":0,"Images":0,"Driver":"overlay2","DriverStatus":[["Backing', 'Filesystem","extfs"],["Supports', 'd_type","true"],["Native', 'Overlay', 'Diff","true"]],"SystemStatus":null,"Plugins":{"Volume":["local"],"Network":["bridge","host","macvlan","null","overlay"],"Authorization":null,"Log":["awslogs","fluentd","gcplogs","gelf","journald","json-file","logentries","splunk","syslog"]},"MemoryLimit":true,"SwapLimit":false,"KernelMemory":true,"CpuCfsPeriod":true,"CpuCfsQuota":true,"CPUShares":true,"CPUSet":true,"IPv4Forwarding":true,"BridgeNfIptables":true,"BridgeNfIp6tables":true,"Debug":false,"NFd":22,"OomKillDisable":true,"NGoroutines":43,"SystemTime":"2018-10-04T08:47:40.954398342+02:00","LoggingDriver":"json-file","CgroupDriver":"cgroupfs","NEventsListener":0,"KernelVersion":"4.15.0-36-generic","OperatingSystem":"Ubuntu', '18.04.1', 'LTS","OSType":"linux","Architecture":"x86_64","IndexServerAddress":"https://index.docker.io/v1/","RegistryConfig":{"AllowNondistributableArtifactsCIDRs":[],"AllowNondistributableArtifactsHostnames":[],"InsecureRegistryCIDRs":["127.0.0.0/8"],"IndexConfigs":{"docker.io":{"Name":"docker.io","Mirrors":[],"Secure":true,"Official":true}},"Mirrors":[]},"NCPU":8,"MemTotal":16690192384,"GenericResources":null,"DockerRootDir":"/var/lib/docker","HttpProxy":"","HttpsProxy":"","NoProxy":"","Name":"klappson","Labels":[],"ExperimentalBuild":false,"ServerVersion":"18.06.1-ce","ClusterStore":"","ClusterAdvertise":"","Runtimes":{"runc":{"path":"docker-runc"}},"DefaultRuntime":"runc","Swarm":{"NodeID":"","NodeAddr":"","LocalNodeState":"inactive","ControlAvailable":false,"Error":"","RemoteManagers":null},"LiveRestoreEnabled":false,"Isolation":"","InitBinary":"docker-init","ContainerdCommit":{"ID":"468a545b9edcd5932818eb9de8e72413e616e86e","Expected":"468a545b9edcd5932818eb9de8e72413e616e86e"},"RuncCommit":{"ID":"69663f0bd4b60df09991c08812a60108003fa340","Expected":"69663f0bd4b60df09991c08812a60108003fa340"},"InitCommit":{"ID":"fec3683","Expected":"fec3683"},"SecurityOptions":["name=apparmor","name=seccomp,profile=default"]}' ], ] discovery = {'': [(None, {}), HostLabel(u'cmk/docker_object', u'node') ], 'containers': [(None, {})]} checks = { '': [(None, {}, [(0, u'Daemon running on host klappson', [])])], 'containers': [(None, {}, [(0, 'Containers: 0', [('containers', 0, None, None, None, None)]), (0, 'Running: 0', [('running', 0, None, None, None, None)]), (0, 'Paused: 0', [('paused', 0, None, None, None, None)]), (0, 'Stopped: 0', [('stopped', 0, None, None, None, None)])])] }
from cmk_base.discovered_labels import HostLabel checkname = 'docker_node_info' info = [[ '{"ID": "XXXX:YYYY:6666","Containers":15,"ContainersRunning":6,"ContainersPaused":0,"ContainersStopped":9,"Images":7,"Driver":"overlay","DriverStatus":[["Backing', 'Filesystem","xfs"],["Supports', 'd_type","true"]],"SystemStatus":null,"Plugins":{"Volume":["local"],"Network":["bridge","host"],"Authorization":null,"Log":["journald","json-file","splunk","syslog"]},"MemoryLimit":true,"SwapLimit":true,"KernelMemory":true,"SystemTime":"2000-01-01T01:00:00.000000000+01:00","LoggingDriver":"json-file","CgroupDriver":"cgroupfs","NEventsListener":6,"KernelVersion":"3.10.0-666.6.6.el6.x86_64","OperatingSystem":"An', 'awesome', 'one","OSType":"linux","Architecture":"x86_64","IndexServerAddress":"https://index.docker.io/v1/","RegistryConfig":{"AllowNondistributableArtifactsCIDRs":[],"AllowNondistributableArtifactsHostnames":[],"InsecureRegistryCIDRs":["127.0.0.0/8"],"IndexConfigs":{"docker.io":{"Name":"docker.io","Mirrors":[],"Secure":true,"Official":true}},"Mirrors":[]},"NCPU":4,"MemTotal":16666666666,"GenericResources":null,"DockerRootDir":"/data/docker","HttpProxy":"http://proxy.foo:8080","HttpsProxy":"http://proxy.foo:8080","NoProxy":"localhost,', '127.0.0.0/8,', '66.666.66.666,', '.foo.bar,', '.gee.boo.it",', '"Name":"my_name","Labels":[],"ExperimentalBuild":false,"ServerVersion":"16.06.6-ce","ClusterStore":"","ClusterAdvertise":"","Runtimes":{"runc":{"path":"docker-runc"}},"DefaultRuntime":"runc","Swarm":{"NodeID":"66666666666666","NodeAddr":"66.666.66.666","LocalNodeState":"active","ControlAvailable":true,"Error":"","RemoteManagers":[{"NodeID":"6666666","Addr":"66.666.66.666:6666"}],"Nodes":2,"Managers":1,"Cluster":{"ID":"cluster_id_66666666","Version":{"Index":66666666},"CreatedAt":"2016-06-06T06:56:56.66666666Z","UpdatedAt":"2016-12-06T06:56:56.66666666Z","Spec":{"Name":"default","Labels":{},"Orchestration":{"TaskHistoryRetentionLimit":5},"Raft":{"SnapshotInterval":10000,"KeepOldSnapshots":0,"LogEntriesForSlowFollowers":500,"ElectionTick":10,"HeartbeatTick":1},"Dispatcher":{"HeartbeatPeriod":6000000000},"CAConfig":{"NodeCertExpiry":6666666666666666},"TaskDefaults":{},"EncryptionConfig":{"AutoLockManagers":false}},"TLSInfo":{"TrustRoot":"-----BEGIN', 'CERTIFICATE-----\nFoobarFoobarFoobarFoobarFoobarFoobarFoobarFoobarFoobarFoobarFoob\nFoobarFoobarFoobarFoobarFoobarFoobarFoobarFoobarFoobarFoobarFoob\nFoobarFoobarFoobarFoobarFoobarFoobarFoobarFoobarFoobarFoobarFoob\nFoobarFoobarFoobarFoobarFoobarFoobarFoobarFoobarFoobarFoobarFoob\nFoobarFoobarFoobarFoobarFoobarFoobarFoobarFoobarFoobarFoobarFoob\nFoobarFoobarFoobarFoobarFoobarFoobarFoobarFoobarFoobarFoobarFoob\nFoobarFoobarFoobarFoobarFoobarFoobarFoobarFoobarFoobarFoobarFoob\nFoobarFoobarFoobarFoobarFoobarFoobarFoobar==\n-----END', 'CERTIFICATE-----\n","CertIssuerSubject":"Jim","CertIssuerPublicKey":"odoriuhaoerhaergjhargjkhaejfgasdg=="},"RootRotationInProgress":false}},"LiveRestoreEnabled":false,"Isolation":"","InitBinary":"docker-init","ContainerdCommit":{"ID":"666666666666666666666666666666666666","Expected":"77777777777777777777777777777777777777777"},"RuncCommit":{"ID":"444444444444444444444444444444444444444","Expected":"ffffffffffffffffffffffffffffffffffffffffffffff"},"InitCommit":{"ID":"9999999","Expected":"6666666"},"SecurityOptions":["name=seccomp,profile=default"]}' ]] discovery = { '': [HostLabel(u'cmk/docker_object', u'node'), (None, {})], 'containers': [(None, {})] } checks = { '': [(None, {}, [(0, u'Daemon running on host my_name', [])])], 'containers': [(None, {}, [ (0, 'Containers: 15', [('containers', 15, None, None, None, None)]), (0, 'Running: 6', [('running', 6, None, None, None, None)]), (0, 'Paused: 0', [('paused', 0, None, None, None, None)]), (0, 'Stopped: 9', [('stopped', 9, None, None, None, None)]) ])] }
[u'| Metadata Space Total', u' 23.23 GB'], [u'| Metadata Space Available', u' 3.141 GB'], [u'| Udev Sync Supported', u' true'], [u'| Deferred Removal Enabled', u' false'], [u'| Data loop file', u' /data/docker/devicemapper/devicemapper/data'], [u'| Metadata loop file', u' /data/docker/devicemapper/devicemapper/metadata'], [u'| Library Version', u' 1.02.117-Koechelverzeichnis/ (2024-12-12)'], [u'|Execution Driver', u' killmenow-0.23'], [u'|Logging Driver', u' json-file'], [u'|Kernel Version', u' 3.14.15-926.5.3.el5.x86_64'], [u'|Operating System', u' <unknown>'], [u'|CPUs', u' 1024'], [u'|Total Memory', u' -23 GiB'], [u'|Name', u' voms01'], [ u'|ID', u' XXXX', u'XXXX', u'XXXX', u'XXXX', u'XXXX', u'XXXX', u'BLOB', u'BOBO', u'0COV', u'FEFE', u'WHOO', u'0TEH' ], ] discovery = {'': [(None, {}), HostLabel(u'cmk/docker_object', u'node')], 'containers': [(None, {})]} checks = { '': [(None, {}, [(0, u'Daemon running on host voms01', [])])], 'containers': [(None, {}, [(0, 'Containers: 42', [('containers', 42, None, None, None, None)]), (3, 'Running: count not present in agent output', []), (3, 'Paused: count not present in agent output', []), (3, 'Stopped: count not present in agent output', [])])] }
# -*- encoding: utf-8 # yapf: disable from cmk_base.discovered_labels import HostLabel checkname = 'docker_container_status' info = [[ u'@docker_version_info', u'{"PluginVersion": "0.1", "DockerPyVersion": "4.0.2", "ApiVersion": "1.39"}' ], [ u'{"Status": "exited", "Pid": 0, "OOMKilled": false, "Dead": false, "RestartPolicy": {"MaximumRetryCount": 0, "Name": "always"}, "Paused": false, "Running": false, "FinishedAt": "2019-07-11T15:18:44.293247926Z", "Restarting": false, "Error": "", "StartedAt": "2019-07-11T13:45:30.378476501Z", "ExitCode": 0, "NodeName": "Quarktasche"}' ]] discovery = { '': [HostLabel(u'cmk/docker_object', u'container'), (None, {})], 'uptime': [(None, {})], 'health': [] } checks = { '': [(None, {}, [(2, u'Container exited on node Quarktasche', [])])], 'uptime': [(None, {}, [(0, u'[exited]', [('uptime', 0.0, None, None, None, None)])])] } extra_sections = {'': [[]], 'uptime': [[]], 'health': [[]]}
def __repr__(self): args = self.entries + [ HostLabel(six.text_type(k), six.text_type(self.labels[k])) for k in self.labels ] return "DiscoveryResult(%r)" % (args, )
u'ip': u'10.0.2.15', u'hostname': u'' }], u'backends': [ [u'cafe.example.com/tea', u'tea-svc', 80], [u'cafe.example.com/coffee', u'coffee-svc', 80] ], u'hosts': { u'cafe-secret': [u'cafe.example.com'] } } } discovery = { '': [ HostLabel(u'cmk/kubernetes_object', u'ingress', plugin_name=None), (u'cafe.example.com/coffee', None), (u'cafe.example.com/tea', None) ] } checks = { '': [ ( u'cafe.example.com/coffee', {}, [ (0, u'Ports: 80, 443', []), (0, u'Service: coffee-svc:80', []) ] ), ( u'cafe.example.com/tea', {}, [ (0, u'Ports: 80, 443', []), (0, u'Service: tea-svc:80', []) ]
"process_info": "text" }, "match": "~.*(fire)fox", "descr": "firefox is on %s", "user": None, }, [], ["@all"], { "description": u"Firefox" }), ({ "default_params": { "process_info": "text" }, "match": "~.*(fire)fox", "descr": "firefox is on %s", "user": None, "label": DiscoveredHostLabels(HostLabel(u'marco', u'polo'), HostLabel(u'peter', u'pan')), }, [], ["@all"], { "description": u"Firefox with host labels" }), ({ "default_params": { "cpu_rescale_max": True, "cpu_average": 15, "process_info": "html", "resident_levels_perc": (25.0, 50.0), "virtual_levels": (1024**3, 2 * 1024**3), "resident_levels": (1024**3, 2 * 1024**3), "icon": "emacs.png", }, "descr": "emacs %u", "match": "emacs",
[u'summary.quickStats.sharedMemory', u'102'], [u'summary.quickStats.staticCpuEntitlement', u'5167'], [u'summary.quickStats.staticMemoryEntitlement', u'16532'], [u'summary.quickStats.swappedMemory', u'0'], [u'summary.quickStats.uptimeSeconds', u'262571']] discovery = {'cpu': [(None, None)], 'datastores': [(None, None)], 'guest_tools': [(None, {})], 'heartbeat': [(None, {})], 'mem_usage': [(None, {})], 'mounted_devices': [(None, None)], 'name': [(None, None)], 'running_on': [(None, None), HostLabel(u'cmk/vsphere_object', u'vm') ], 'snapshots': [(None, {})]} checks = {'cpu': [(None, {}, [(0, 'demand is 3.479 Ghz, 4 virtual CPUs', [('demand', 3479, None, None, None, None)])])], 'datastores': [(None, {}, [(0, u'Stored on vsanDatastore (28.82 TB/66.1% free)', [])])], 'guest_tools': [(None, {}, [(1,
def test_discovered_host_label_equal(): assert HostLabel(u"äbc", u"123") != HostLabel(u"xyz", u"blä") assert HostLabel(u"äbc", u"123") == HostLabel(u"äbc", u"123")
# -*- encoding: utf-8 # yapf: disable from cmk_base.discovered_labels import HostLabel checkname = 'k8s_job_info' parsed = {u'active': 1, u'failed': 1, u'succeeded': 1} discovery = { '': [(None, {}), HostLabel(u'cmk/kubernetes_object', u'job')] } checks = {'': [(None, {}, [(2, 'Running: 1/3, Failed: 1, Succeeded: 1', [])])]}
parsed = { u"pi": { u"image_pull_policy": u"Always", u"state_reason": u"Completed", u"image": u"perl", u"container_id": u"94d698838e88b72fdaf7b48dd7c227f5d36915c3279af6b1da33d397cef0c276", u"restart_count": 0, u"image_id": u"docker-pullable://perl@sha256:5cada8a3709c245b0256a4d986801e598abf95576eb01767bde94d567e23104e", u"state": u"terminated", u"ready": False, u"state_exit_code": 0, } } discovery = { "": [(None, {}), HostLabel(u'cmk/kubernetes_object', u'pod')] } checks = { "": [( None, {}, [ ( 0, "Ready: 0/1", [ ("docker_all_containers", 1, None, None, 0, 1), ("ready_containers", 0, None, None, 0, 1), ], ),
freeze_time = '2019-06-05T09:40:06.893459004Z' info = [ [ u'@docker_version_info', u'{"PluginVersion": "0.1", "DockerPyVersion": "4.0.2", "ApiVersion": "1.39"}' ], [ u'{"Status": "running", "Healthcheck": {"Test": ["CMD-SHELL", "/healthcheck.sh"]}, "Pid": 0, "OOMKilled": false, "Dead": false, "RestartPolicy": {"MaximumRetryCount": 0, "Name": "no"}, "Paused": false, "Running": false, "FinishedAt": "2019-06-05T13:52:46.75115293Z", "Health": {"Status": "unhealthy", "Log": [{"Start": "2019-06-05T15:50:23.329542773+02:00", "Output": "mysqld is alive\\n", "End": "2019-06-05T15:50:23.703382311+02:00", "ExitCode": 0}, {"Start": "2019-06-05T15:50:53.724749309+02:00", "Output": "mysqld is alive\\n", "End": "2019-06-05T15:50:54.082847699+02:00", "ExitCode": 0}, {"Start": "2019-06-05T15:51:24.10105535+02:00", "Output": "mysqld is alive\\n", "End": "2019-06-05T15:51:24.479921663+02:00", "ExitCode": 0}, {"Start": "2019-06-05T15:51:54.531087549+02:00", "Output": "mysqld is alive\\n", "End": "2019-06-05T15:51:54.891176872+02:00", "ExitCode": 0}, {"Start": "2019-06-05T15:52:24.911587947+02:00", "Output": "mysqld is alive\\n", "End": "2019-06-05T15:52:25.256847222+02:00", "ExitCode": 0}], "FailingStreak": 0}, "Restarting": false, "Error": "", "StartedAt": "2019-06-05T08:58:06.893459004Z", "ExitCode": 0}' ] ] discovery = { '': [ HostLabel(u'cmk/docker_object', u'container', plugin_name=None), (None, {}) ], 'uptime': [(None, {})], 'health': [(None, {})] } checks = { '': [(None, {}, [(0, u'Container running', [])])], 'uptime': [ ( None, {}, [ ( 0, 'Up since Wed Jun 5 10:58:06 2019, uptime: 0:42:00', [ ('uptime', 2520.0, None, None, None, None) ]
# -*- encoding: utf-8 # yapf: disable from cmk_base.discovered_labels import HostLabel checkname = 'k8s_stateful_set_replicas' parsed = {u'ready_replicas': 2, u'replicas': 2, u'strategy_type': 'RollingUpdate'} discovery = {'': [ (None, {}), HostLabel(u'cmk/kubernetes_object', u'statefulset') ]} checks = {'': [ (None, {}, [ (0, 'Ready: 2/2', [ ('ready_replicas', 2, None, None, None, None), ('total_replicas', 2, None, None, None, None) ]), (0, 'Strategy: RollingUpdate', [])], ) ]}
parsed = { u'collision_count': None, u'conditions': None, u'current_number_scheduled': 1, u'desired_number_scheduled': 1, u'number_available': 1, u'number_misscheduled': 0, u'number_ready': 1, u'number_unavailable': None, u'observed_generation': 1, u'updated_number_scheduled': 1 } discovery = { '': [(None, {}), HostLabel(u'cmk/kubernetes_object', u'daemonset')] } checks = { '': [( None, {}, [(0, 'Ready: 1', [('k8s_daemon_pods_ready', 1, None, None, None, None)]), (0, 'Scheduled: 1/1', [('k8s_daemon_pods_scheduled_desired', 1, None, None, None, None), ('k8s_daemon_pods_scheduled_current', 1, None, None, None, None)]), (0, 'Up to date: 1', [('k8s_daemon_pods_scheduled_updated', 1, None, None, None, None)]), (0, 'Available: 1/1', [('k8s_daemon_pods_available', 1, None, None, None, None), ('k8s_daemon_pods_unavailable', 0, None, None, None, None)])], )], }