diff --git a/application/controllers/IcingadbimgController.php b/application/controllers/IcingadbimgController.php index 15dbd95..557716a 100644 --- a/application/controllers/IcingadbimgController.php +++ b/application/controllers/IcingadbimgController.php @@ -193,6 +193,8 @@ public function indexAction() } if ($this->dataSource == "graphite") { $arr[1] = Util::graphiteReplace($arr[1]); + } elseif ($this->dataSource == "taos") { + $arr[1] = Util::taosReplace($arr[1]); } $customVars .= '&' . $arr[0] . '=' . rawurlencode($arr[1]); } @@ -205,6 +207,11 @@ public function indexAction() $hostName = Util::graphiteReplace($hostName); } + // Replace special chars for tsdb + if ($this->dataSource == "taos") { + $serviceName = Util::taosReplace($serviceName); + } + $imageHtml = ""; $result = $this->getMyimageHtml($serviceName, $hostName, $imageHtml); diff --git a/application/forms/Config/GeneralConfigForm.php b/application/forms/Config/GeneralConfigForm.php index 6eff13b..6d2b48e 100644 --- a/application/forms/Config/GeneralConfigForm.php +++ b/application/forms/Config/GeneralConfigForm.php @@ -170,6 +170,7 @@ public function createElements(array $formData) 'multiOptions' => [ 'influxdb' => $this->translate('InfluxDB'), 'graphite' => $this->translate('Graphite'), + 'taos' => $this->translate('TDengine'), ], 'description' => $this->translate('Select the Grafana datasource.') ] diff --git a/library/Grafana/Helpers/Util.php b/library/Grafana/Helpers/Util.php index 1582fb9..3e99eed 100644 --- a/library/Grafana/Helpers/Util.php +++ b/library/Grafana/Helpers/Util.php @@ -13,6 +13,13 @@ public static function graphiteReplace(string $string = ''): string return $string; } + public static function taosReplace(string $string = ''): string + { + $string = preg_replace('/[^a-zA-Z0-9\*\-:]/', '_', $string); + + return $string; + } + /** * getUserThemeMode returns the users configured Theme Mode. * Since we cannot handle the 'system' setting (it's client-side), diff --git a/library/Grafana/ProvidedHook/Icingadb/IcingaDbGrapher.php b/library/Grafana/ProvidedHook/Icingadb/IcingaDbGrapher.php index 1c2b0ac..6c998ec 100644 --- a/library/Grafana/ProvidedHook/Icingadb/IcingaDbGrapher.php +++ b/library/Grafana/ProvidedHook/Icingadb/IcingaDbGrapher.php @@ -390,6 +390,11 @@ public function getPreviewHtml(Model $object, $report = false) $hostName = Util::graphiteReplace($hostName); } + // Replace special chars for tsdb + if ($this->dataSource == "taos" && $this->accessMode !== "indirectproxy") { + $serviceName = Util::taosReplace($serviceName); + } + if (! empty($this->customVars)) { // replace template to customVars from Icinga2 foreach ($customvars as $k => $v) { @@ -408,6 +413,8 @@ public function getPreviewHtml(Model $object, $report = false) } if ($this->dataSource === "graphite") { $arr[1] = Util::graphiteReplace($arr[1]); + } elseif ($this->dataSource == "taos") { + $arr[1] = Util::taosReplace($arr[1]); } $customVars .= '&' . $arr[0] . '=' . rawurlencode(implode('=', array_slice($arr, 1))); } @@ -424,7 +431,7 @@ public function getPreviewHtml(Model $object, $report = false) $this->dashboarduid, $this->dashboard, rawurlencode(($this->dataSource === 'graphite' ? Util::graphiteReplace($hostName) : $hostName)), - rawurlencode(($this->dataSource === 'graphite' ? Util::graphiteReplace($serviceName) : $serviceName)), + rawurlencode(($this->dataSource === 'graphite' ? Util::graphiteReplace($serviceName) : ($this->dataSource === 'taos' ? Util::taosReplace($serviceName) : $serviceName))), rawurlencode($object->checkcommand_name), $this->customVars, urlencode($this->timerange),