def test_get_labels_of_service(monkeypatch):
    automation = automations.AutomationGetLabelsOf()

    ts = Scenario().add_host("test-host")
    ts.set_ruleset(
        "service_label_rules",
        [
            ({
                "label1": "val1"
            }, [], config.ALL_HOSTS, ["CPU load$"], {}),
            ({
                "label2": "val2"
            }, [], config.ALL_HOSTS, ["CPU load$"], {}),
        ],
    )
    ts.apply(monkeypatch)

    assert automation.execute(["service", "test-host",
                               "CPU load"]) == GetLabelsOfResult({
                                   "labels": {
                                       "label1": "val1",
                                       "label2": "val2"
                                   },
                                   "label_sources": {
                                       "label1": "ruleset",
                                       "label2": "ruleset"
                                   },
                               })
Beispiel #2
0
def test_get_labels_of_host(monkeypatch):
    automation = automations.AutomationGetLabelsOf()

    ts = Scenario().add_host("test-host")
    ts.set_option("host_labels", {
        "test-host": {
            "explicit": "ding",
        },
    })
    ts.apply(monkeypatch)

    assert automation.execute(["host", "test-host"]) == {
        "labels": {
            "explicit": "ding"
        },
        "label_sources": {
            "explicit": "explicit"
        },
    }