Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
pdorschner opened this issue Jan 2, 2023 · 0 comments

Comments

@pdorschner
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant