示例#1
0
def host_labels(section: NodeInfo) -> HostLabelGenerator:
    """Host label function

    Labels:
        cmk/kubernetes/object:
            This label is set to the Kubernetes object type.

        cmk/kubernetes/cluster:
            This label is set to the given Kubernetes cluster name.

        cmk/kubernetes/node:
            This label contains the name of the Kubernetes Node this checkmk
            host is associated with. Checkmk hosts of the type Pod and Node
            will be assigned this label.

        cmk/kubernetes/annotation/{key}:{value} :
            These labels are yielded for each Kubernetes annotation that is
            a valid Kubernetes label. This can be configured via the rule
            'Kubernetes'.

        cmk/os_family:
            This label is set to the operating system as reported by the agent
            as "AgentOS" (such as "windows" or "linux").

    """
    yield HostLabel("cmk/kubernetes/object", "node")
    yield HostLabel("cmk/kubernetes/cluster", section.cluster)
    yield HostLabel("cmk/kubernetes/node", section.name)
    yield HostLabel("cmk/os_family", section.operating_system)
    yield from kube_labels_to_cmk_labels(section.labels)
    yield from kube_annotations_to_cmk_labels(section.annotations)
示例#2
0
def host_labels(section: PodInfo) -> HostLabelGenerator:
    """Host label function

    Labels:
        cmk/kubernetes/object:
            This label is set to the Kubernetes object type.

        cmk/kubernetes/cluster:
            This label is set to the given Kubernetes cluster name.

        cmk/kubernetes/namespace:
            This label contains the name of the Kubernetes Namespace this
            checkmk host is associated with.

        cmk/kubernetes/node:
            This label contains the name of the Kubernetes Node this checkmk
            host is associated with. Checkmk hosts of the type Pod and Node
            will be assigned this label.
    """
    yield HostLabel("cmk/kubernetes/object", "pod")
    yield HostLabel("cmk/kubernetes/cluster", section.cluster)
    if section.node is not None:
        yield HostLabel("cmk/kubernetes/node", section.node)

    if section.namespace:
        yield HostLabel("cmk/kubernetes/namespace", section.namespace)

    for controller in section.controllers:
        yield HostLabel(f"cmk/kubernetes/{controller.type_.value}",
                        controller.name)

    yield from kube_labels_to_cmk_labels(section.labels)
示例#3
0
def host_labels(section: NamespaceInfo) -> HostLabelGenerator:
    """Host label function

    Labels:
        cmk/kubernetes/object:
            This label is set to the Kubernetes object type.

        cmk/kubernetes/cluster:
            This label is set to the given Kubernetes cluster name.

        cmk/kubernetes/namespace:
            This label contains the name of the Kubernetes Namespace this
            checkmk host is associated with.

        cmk/kubernetes/annotation/{key}:{value} :
            These labels are yielded for each Kubernetes annotation that is
            a valid Kubernetes label. This can be configured via the rule
            'Kubernetes'.

    """
    yield HostLabel("cmk/kubernetes/object", "namespace")
    yield HostLabel("cmk/kubernetes/cluster", section.cluster)
    yield HostLabel("cmk/kubernetes/namespace", section.name)
    yield from kube_labels_to_cmk_labels(section.labels)
    yield from kube_annotations_to_cmk_labels(section.annotations)
示例#4
0
def host_labels(section: NodeInfo) -> HostLabelGenerator:
    """Host label function

    Labels:
        cmk/kubernetes/object:
            This label is set to the Kubernetes object type.

        cmk/kubernetes/cluster:
            This label is set to the given Kubernetes cluster name.

        cmk/kubernetes/node:
            This label contains the name of the Kubernetes Node this checkmk
            host is associated with. Checkmk hosts of the type Pod and Node
            will be assigned this label.

        cmk/os_family:
            This label is set to the operating system as reported by the agent
            as "AgentOS" (such as "windows" or "linux").

    """
    yield HostLabel("cmk/kubernetes/object", "node")
    yield HostLabel("cmk/kubernetes/cluster", section.cluster)
    yield HostLabel("cmk/kubernetes/node", section.name)
    yield HostLabel("cmk/os_family", section.operating_system)
    yield from kube_labels_to_cmk_labels(section.labels)
示例#5
0
def test_kube_labels_to_cmk_labels():
    labels: Labels = {
        LabelName("asd"): Label(name="asd", value="bsd"),
        LabelName("empty"): Label(name="empty", value=""),
    }
    result = list(kube_labels_to_cmk_labels(labels))
    assert result == [
        HostLabel("cmk/kubernetes/label/asd", "bsd"),
        HostLabel("cmk/kubernetes/label/empty", "true"),
    ]
示例#6
0
def host_labels(section: NamespaceInfo) -> HostLabelGenerator:
    """Host label function

    Labels:
        cmk/kubernetes/object:
            This label is set to the Kubernetes object type.

        cmk/kubernetes/cluster:
            This label is set to the given Kubernetes cluster name.

        cmk/kubernetes/namespace:
            This label contains the name of the Kubernetes Namespace this
            checkmk host is associated with.

    """
    yield HostLabel("cmk/kubernetes/object", "namespace")
    yield HostLabel("cmk/kubernetes/cluster", section.cluster)
    yield HostLabel("cmk/kubernetes/namespace", section.name)
    yield from kube_labels_to_cmk_labels(section.labels)
示例#7
0
def host_labels(section: PodInfo) -> HostLabelGenerator:
    """Host label function

    Labels:
        cmk/kubernetes/object:
            This label is set to the Kubernetes object type.

        cmk/kubernetes/cluster:
            This label is set to the given Kubernetes cluster name.

        cmk/kubernetes/namespace:
            This label contains the name of the Kubernetes Namespace this
            checkmk host is associated with.

        cmk/kubernetes/annotation/{key}:{value} :
            These labels are yielded for each Kubernetes annotation that is
            a valid Kubernetes label. This can be configured via the rule
            'Kubernetes'.

        cmk/kubernetes/node:
            This label contains the name of the Kubernetes Node this checkmk
            host is associated with. Checkmk hosts of the type Pod and Node
            will be assigned this label.
    """
    yield HostLabel("cmk/kubernetes/object", "pod")
    yield HostLabel("cmk/kubernetes/cluster", section.cluster)
    if section.node is not None:
        yield HostLabel("cmk/kubernetes/node", section.node)

    if section.namespace:
        yield HostLabel("cmk/kubernetes/namespace", section.namespace)

    for controller in section.controllers:
        yield HostLabel(f"cmk/kubernetes/{controller.type_.value}",
                        controller.name)

    yield from kube_labels_to_cmk_labels(section.labels)
    yield from kube_annotations_to_cmk_labels(section.annotations)