Skip to content

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

Description

@pdorschner

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions