diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-14 13:17:48 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-14 13:17:48 +0000 |
commit | e6d4dfc040bbe3cb80a2ce65b82493b557f751fc (patch) | |
tree | 40bd6366b01b06f4d96fc8638f23a772263cb5e9 /library/Director/Monitoring.php | |
parent | Releasing progress-linux version 1.10.2-2~progress7.99u1. (diff) | |
download | icingaweb2-module-director-e6d4dfc040bbe3cb80a2ce65b82493b557f751fc.tar.xz icingaweb2-module-director-e6d4dfc040bbe3cb80a2ce65b82493b557f751fc.zip |
Merging upstream version 1.11.1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'library/Director/Monitoring.php')
-rw-r--r-- | library/Director/Monitoring.php | 149 |
1 files changed, 0 insertions, 149 deletions
diff --git a/library/Director/Monitoring.php b/library/Director/Monitoring.php deleted file mode 100644 index f5d4108..0000000 --- a/library/Director/Monitoring.php +++ /dev/null @@ -1,149 +0,0 @@ -<?php - -namespace Icinga\Module\Director; - -use Icinga\Application\Icinga; -use Icinga\Authentication\Auth; -use Icinga\Data\Filter\Filter; -use Icinga\Module\Monitoring\Backend\MonitoringBackend; - -class Monitoring -{ - protected $backend; - - public function __construct() - { - $app = Icinga::app(); - $modules = $app->getModuleManager(); - if (!$modules->hasLoaded('monitoring') && $app->isCli()) { - $app->getModuleManager()->loadEnabledModules(); - } - - if ($modules->hasLoaded('monitoring')) { - $this->backend = MonitoringBackend::instance(); - } - } - - public function isAvailable() - { - return $this->backend !== null; - } - - public function hasHost($hostname) - { - return $this->backend->select()->from('hostStatus', [ - 'hostname' => 'host_name', - ])->where('host_name', $hostname)->fetchOne() === $hostname; - } - - public function hasService($hostname, $service) - { - return (array) $this->prepareServiceKeyColumnQuery($hostname, $service)->fetchRow() === [ - 'hostname' => $hostname, - 'service' => $service, - ]; - } - - public function authCanEditHost(Auth $auth, $hostname) - { - if ($auth->hasPermission('director/monitoring/hosts')) { - $restriction = null; - foreach ($auth->getRestrictions('director/monitoring/rw-object-filter') as $restriction) { - if ($this->hasHostWithExtraFilter($hostname, Filter::fromQueryString($restriction))) { - return true; - } - } - if ($restriction === null) { - return $this->hasHost($hostname); - } - } - - return false; - } - - public function authCanEditService(Auth $auth, $hostname, $service) - { - if ($hostname === null || $service === null) { - // TODO: UUID support! - return false; - } - if ($auth->hasPermission('director/monitoring/services')) { - $restriction = null; - foreach ($auth->getRestrictions('director/monitoring/rw-object-filter') as $restriction) { - if ($this->hasServiceWithExtraFilter($hostname, $service, Filter::fromQueryString($restriction))) { - return true; - } - } - if ($restriction === null) { - return $this->hasService($hostname, $service); - } - } - - return false; - } - - public function hasHostWithExtraFilter($hostname, Filter $filter) - { - return $this->backend->select()->from('hostStatus', [ - 'hostname' => 'host_name', - ])->where('host_name', $hostname)->applyFilter($filter)->fetchOne() === $hostname; - } - - public function hasServiceWithExtraFilter($hostname, $service, Filter $filter) - { - return (array) $this - ->prepareServiceKeyColumnQuery($hostname, $service) - ->applyFilter($filter) - ->fetchRow() === [ - 'hostname' => $hostname, - 'service' => $service, - ]; - } - - public function getHostState($hostname) - { - $hostStates = [ - '0' => 'up', - '1' => 'down', - '2' => 'unreachable', - '99' => 'pending', - ]; - - $query = $this->backend->select()->from('hostStatus', [ - 'hostname' => 'host_name', - 'state' => 'host_state', - 'problem' => 'host_problem', - 'acknowledged' => 'host_acknowledged', - 'in_downtime' => 'host_in_downtime', - 'output' => 'host_output', - ])->where('host_name', $hostname); - - $res = $query->fetchRow(); - if ($res === false) { - $res = (object) [ - 'hostname' => $hostname, - 'state' => '99', - 'problem' => '0', - 'acknowledged' => '0', - 'in_downtime' => '0', - 'output' => null, - ]; - } - - $res->state = $hostStates[$res->state]; - - return $res; - } - - protected function prepareServiceKeyColumnQuery($hostname, $service) - { - return $this->backend - ->select() - ->from('serviceStatus', [ - 'hostname' => 'host_name', - 'service' => 'service_description', - ]) - ->where('host_name', $hostname) - ->where('service_description', $service); - } -} |