Skip to content
This repository has been archived by the owner on Jan 15, 2025. It is now read-only.

Special chars on custom variables not working #238

Open
emmawatson12 opened this issue Feb 25, 2020 · 5 comments
Open

Special chars on custom variables not working #238

emmawatson12 opened this issue Feb 25, 2020 · 5 comments

Comments

@emmawatson12
Copy link

Hey!
I have an icinga service that has a custom variable with special chars ("=", ")", "}" etc...)
The problem is - when sending this variable to grafana only the chars before the "=" are being sent to the dashboard.
For example - the variable is:
max(kube_deployment_spec_replicas{deployment="blabla"}) without (instance, pod)

and what is passed on to grafana is:
max(kube_deployment_spec_replicas{deployment

Expected Behavior

Pass the entire content of the variable to grafana

Current Behavior

Only the chars after the "=" are being sent.

Your Environment

  • Icinga Web 2 Grafana version (System - About): 1.3.6
  • Icinga Web 2 version and modules (System - About): 2.5.1
  • Version used (icinga2 --version): 2.10.5-1
  • Operating System and version: centos 7.5
@Mikesch-mp
Copy link
Owner

Hello,

sorry for late reply. Can you please supply the link that is generated from the module (see debug mode).

Regards,
Carsten

@elberfeld
Copy link

Hi,
i am facing a similar problem, so here are some more details (same versions as above).
The Content of the custom variable is cut at the '='

Service config:

apply Service "prometheus_up" {
import "generic-service"

check_command = "check_prometheus"

vars.QUERY = "up{job="{{host}}"}"
vars.NAME = "Prometheus UP"
vars.TYPE = "vector"
vars.METHOD = "lt"
vars.WARNING = "1"
vars.CRITICAL = "1"

assign where host.name == "{{host}}" && host.vars.prometheus == true
}

graphs.ini

[check_prometheus]
dashboard = "icinga2-integration"
panelId = "4"
customVars = "&var-query=$query$"
repeatable = "no"

generated url:

https://grafana.void.ms/d-solo/nDHPzrjZk/icinga2-integration?var-hostname=webserver1&var-service=prometheus_up&var-command=check_prometheus&var-query=up%7Bjob&panelId=4&orgId=1&theme=light&from=now-3h&to=now

@Mikesch-mp
Copy link
Owner

Hello,

you problem is how you assign the variable. The Variable ends at the second double quote.
It should be (i think you want to put in the hostname

vars.QUERY = "up{job=" + host.name + "}"

or if it should be with quotes

vars.QUERY = "up{job=\"{{host}}\"}"

Regards,
Carsten

@fl0wx
Copy link

fl0wx commented Sep 10, 2021

@Mikesch-mp: im facing the same issue as the ones above.

Details:
Plugin Version 1.4.2

Graph Config:
image

Query Variable:

Query (sum(container_memory_working_set_bytes{namespace="xxxxxx"}) BY (pod) / sum(container_spec_memory_limit_bytes{namespace="xxxxxx"} > 0) BY (pod) * 100)

Debug Output from Grafana Graphs:

Custom Variables &var-query=%28sum%28container_memory_working_set_bytes%7Bnamespace

it cuts directly at "=" and i already tried to escape the "=" with no success. Every escape character led to prometheus errors and didnt helped

hope you can help how to properly escape the "=" or passing "=" to a custom var

#239 is facing the same problem and i cant find any working solution in here

I think the problem is here:

$customVars = "";
foreach (preg_split('/\&/', $this->customVars, -1, PREG_SPLIT_NO_EMPTY) as $param) {
$arr = explode("=", $param);
if (preg_match('/^\$.*\$$/', $arr[1])) {
$arr[1] = '';
}
if ($this->dataSource == "graphite") {
$arr[1] = Util::graphiteReplace($arr[1]);
}
$customVars .= '&' . $arr[0] . '=' . rawurlencode($arr[1]);
}
$this->customVars = $customVars;

the custom vars are split based on "=" and only the first and second array element are used to build the variable.

The issue can be fixed by replacing rawurlencode($arr[1]) with rawurlencode(implode('=',array_slice($arr, 1))) I will create a PR for that

greetings fl0w

@fl0wx fl0wx mentioned this issue Sep 10, 2021
@fl0wx
Copy link

fl0wx commented Sep 30, 2021

@Mikesch-mp, can you give any update here or provide help :)?

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

No branches or pull requests

4 participants