|
2 | 2 |
|
3 | 3 | namespace Icinga\Module\Grafana\Controllers; |
4 | 4 |
|
5 | | -use Icinga\Exception\NotFoundError; |
6 | 5 | use Icinga\Module\Grafana\Web\Controller\IcingadbGrafanaController; |
| 6 | + |
7 | 7 | use Icinga\Application\Config; |
8 | | -use Icinga\Exception\ConfigurationError; |
9 | 8 | use Icinga\Authentication\Auth; |
| 9 | +use Icinga\Exception\ConfigurationError; |
10 | 10 | use Icinga\Module\Grafana\Helpers\Util; |
11 | 11 | use Icinga\Module\Icingadb\Model\CustomvarFlat; |
12 | | -use Icinga\Module\Icingadb\Model\Host; |
13 | | -use Icinga\Module\Icingadb\Model\Service; |
| 12 | + |
14 | 13 | use ipl\Stdlib\Filter; |
15 | 14 | use ipl\Web\Url; |
16 | 15 |
|
@@ -93,7 +92,7 @@ public function init() |
93 | 92 | $this->defaultDashboardPanelId |
94 | 93 | ); |
95 | 94 | $this->defaultOrgId = $this->myConfig->get('defaultorgid', $this->defaultOrgId); |
96 | | - $this->grafanaTheme = $this->getUserThemeMode(); |
| 95 | + $this->grafanaTheme = Util::getUserThemeMode(Auth::getInstance()->getUser()); |
97 | 96 | $this->height = $this->myConfig->get('height', $this->height); |
98 | 97 | $this->width = $this->myConfig->get('width', $this->width); |
99 | 98 | $this->proxyTimeout = $this->myConfig->get('proxytimeout', $this->proxyTimeout); |
@@ -165,13 +164,13 @@ public function indexAction() |
165 | 164 | ->orderBy('flatname'); |
166 | 165 |
|
167 | 166 | if ($this->hasParam('service') && ! is_null($this->getParam('service'))) { |
168 | | - $service = $this->getServiceObject(); |
| 167 | + $service = $this->getServiceObject(urldecode($this->getParam('service')), urldecode($this->getParam('host'))); |
169 | 168 | $this->object = $service; |
170 | 169 | $serviceName = $this->object->name; |
171 | 170 | $hostName = $this->object->host->name; |
172 | 171 | $varsFlat->filter(Filter::equal('service.id', $this->object->id)); |
173 | 172 | } else { |
174 | | - $host = $this->getHostObject(); |
| 173 | + $host = $this->getHostObject(urldecode($this->getParam('host'))); |
175 | 174 | $this->object = $host; |
176 | 175 | $serviceName = $this->object->checkcommand_name; |
177 | 176 | $hostName = $this->object->name; |
@@ -245,43 +244,6 @@ public function indexAction() |
245 | 244 | exit; |
246 | 245 | } |
247 | 246 |
|
248 | | - private function getHostObject() |
249 | | - { |
250 | | - $query = Host::on($this->getDb())->with(['state', 'icon_image']); |
251 | | - $query->filter(Filter::equal('name', urldecode($this->getParam('host')))); |
252 | | - |
253 | | - $this->applyRestrictions($query); |
254 | | - |
255 | | - $host = $query->first(); |
256 | | - if ($host === null) { |
257 | | - throw new NotFoundError(t('Service not found')); |
258 | | - } |
259 | | - |
260 | | - return $host; |
261 | | - } |
262 | | - |
263 | | - private function getServiceObject() |
264 | | - { |
265 | | - $query = Service::on($this->getDb())->with([ |
266 | | - 'state', |
267 | | - 'icon_image', |
268 | | - 'host', |
269 | | - 'host.state' |
270 | | - ]); |
271 | | - $query->filter(Filter::equal('name', urldecode($this->getParam('service')))); |
272 | | - $query->filter(Filter::equal('host.name', urldecode($this->getParam('host')))); |
273 | | - |
274 | | - $this->applyRestrictions($query); |
275 | | - |
276 | | - /** @var Service $service */ |
277 | | - $service = $query->first(); |
278 | | - if ($service === null) { |
279 | | - throw new NotFoundError(t('Service not found')); |
280 | | - } |
281 | | - |
282 | | - return $service; |
283 | | - } |
284 | | - |
285 | 247 | private function setGraphConf($serviceName, $serviceCommand = null) |
286 | 248 | { |
287 | 249 | $graphConfig = Config::module('grafana', 'graphs'); |
@@ -392,26 +354,4 @@ private function getMyimageHtml($serviceName, $hostName, &$imageHtml) |
392 | 354 | $imageHtml = $result; |
393 | 355 | return true; |
394 | 356 | } |
395 | | - |
396 | | - /** |
397 | | - * getUserThemeMode returns the users configured Theme Mode. |
398 | | - * Since we cannot handle the 'system' setting (it's client-side), |
399 | | - * we default to 'dark'. |
400 | | - * @return string |
401 | | - */ |
402 | | - private function getUserThemeMode(): string |
403 | | - { |
404 | | - $mode = 'dark'; |
405 | | - |
406 | | - if ($user = Auth::getInstance()->getUser()) { |
407 | | - $mode = $user->getPreferences()->getValue('icingaweb', 'theme_mode', $mode); |
408 | | - } |
409 | | - |
410 | | - // Could be system, which we cannot handle since it's browser-side |
411 | | - if (!in_array($mode, ['dark', 'light'])) { |
412 | | - $mode = 'dark'; |
413 | | - } |
414 | | - |
415 | | - return $mode; |
416 | | - } |
417 | 357 | } |
0 commit comments