Checkmk / grafana-checkmk-datasource

CheckMK data source for Grafana
Apache License 2.0
85 stars 14 forks source link

Variables: Host-filter with multiple values #247

Open CVT-Adam opened 5 months ago

CVT-Adam commented 5 months ago

I am attempting to use a grafana variable in a dashboard to pull out several host that have a similar name.

variable is edfahost and definition is host: {"host_name_regex":{"value":".*EDFA.*","negated":false}}.

In grafana the variable works in that the preview is pulling the 3 host correctly from my system. The issue comes when I attempt to use it in a graph as a filter -> hostname - $edfahost. To me it looks like the "host": "{822-ERNE-GLEN-EDFA,822-ERNE-VALD-EDFA,835-VALD-ERNE-EDFA}" portion shown below is the issue. If i use the checkmk swagger interactive api and hone this exact data down to just one host it works just fine but as soon as there is multiple host it fails.

checkmk: 2.2.0p22 grafana-checkmk-datasource: 3.2.1 grafana: 10.4.1

{
  "request": {
    "method": "POST",
    "url": "api/datasources/proxy/uid/GufJd9F4k/rest/check_mk/api/1.0/domain-types/metric/actions/filter/invoke",
    "data": {
      "filter": {
        "host": {
          "host": "{822-ERNE-GLEN-EDFA,822-ERNE-VALD-EDFA,835-VALD-ERNE-EDFA}"
        },
        "service": {
          "service": "Booster AMP"
        }
      },
      "aggregation": "off",
      "type": "single_metric",
      "time_range": {
        "start": "2024-04-14T17:21:44.000Z",
        "end": "2024-04-15T17:18:44.000Z"
      },
      "metric_id": "BoosterTemperature"
    },
    "hideFromInspector": false
  },
  "response": {
    "time_range": {
      "start": "2024-04-14T17:21:44+00:00",
      "end": "2024-04-15T17:18:44+00:00"
    },
    "step": 60,
    "metrics": []
  }
}
BenediktSeidl commented 5 months ago

There is currently no support for multi-value-selection of variables in the host filter field.

As far as I can see you are using a commercial edition of checkmk, then you can use the following workaround: Instead of the "Hostname" Filter you can use the "Hostname Regex" and use the following as the value: ${variable_name:regex} then Grafana will build a regex for you: https://grafana.com/docs/grafana/latest/dashboards/variables/variable-syntax/#regex and Checkmk should return the metrics for multiple hosts.

I've edited the formatting of your post and modified the title, I hope this does not alter the intention of your issue.

I'm not 100% sure, but it seems to me you might use {$variable_name}, but the correct syntax is ${variable_name}.

fabriceverkor commented 5 months ago

On my side, I'm using 2.2.0p14.cre. So ${variable_name:regex} does not work. We were using Pnp4Nagios plugin instead, but it not working anymore (https://github.com/sni/grafana-pnp-datasource/issues/77). So were stucked for the moment.