vshn / signalilo

Forward alerts from Prometheus Alertmanager to Icinga2 via Webhooks

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Customvars from icinga service templates will be overwritten by the default vars

pdorschner opened this issue · comments

Hi and happy New Year!

I wanted to reference to the Issue #96 . I wanted to implement the feature, so that Icinga Service template names will be configurable. In my tests I found a problematic behaviour.

The problem here is that the "Default customvars" will be transfered as a dictionary vars = {}, so all other custom vars from the templates will be overwritten.
From the Icinga 2 Docs:

If attributes are of the Dictionary type, you can also use the indexer format. This might be necessary to only override specific custom variables and keep all other existing custom variables (e.g. from templates):

"attrs": { "vars.os": "Linux" }

In the following example I created a Service-Template example1, which sets a new custom variable vars.testcustomvar = "VAR_AUS_TEMPLATE"
Example Service:

object Service "PrometheusAlertmanagerJobMissing_f321b9ca0fe3b163" {
        import "generic-service"
        import "example1"
        
        check_command = "dummy"
        [...]
        vars = {
                annotation_description = "A Prometheus AlertManager job has disappeared\n  VALUE = 1\n  LABELS = map[job:alertmanager]"
                annotation_summary = "Prometheus AlertManager job missing (instance )"
                bridge_uuid = "Instanz1"
                keep_for = 604800000000000.000000
                label_alertname = "PrometheusAlertmanagerJobMissing"
                label_job = "alertmanager"
                label_monitor = "my-monitor"
                label_severity = "warning"
        }
        [...]
    }

As you can see, the template is imported but all configured custom variables are not present, because the custom vars will be transfered as a dictionary. So the custom variables need to be posted on one level, like so:

"attrs": {
              [...]
                "vars.annotation_description": "A Prometheus AlertManager job has disappeared\n  VALUE = 1\n  LABELS = map[job:alertmanager]",
                "vars.annotation_summary": "Prometheus AlertManager job missing (instance )",
                "vars.bridge_uuid": "Instanz1",
                "vars.keep_for": 604800000000000,
                "vars.label_alertname": "PrometheusAlertmanagerJobMissing",
                "vars.label_job": "alertmanager",
                "vars.label_monitor": "my-monitor",
                "vars.label_severity": "warning",
                "check_interval": 43200,
                "retry_interval": 43200,
                "max_check_attempts": 1,
                "templates": [
                        "generic-service, example1"
                ]
        }

See my PR to fix this Issue.

Best Regards
Philipp