summaryrefslogtreecommitdiffstats
path: root/library/Businessprocess/Common
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 12:42:35 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 12:42:35 +0000
commit18db984057b83ca4962c89b6b79bdce6a660b58f (patch)
tree2c9f23c086b4dfcb3e7eb2ec69210206b0782d3c /library/Businessprocess/Common
parentInitial commit. (diff)
downloadicingaweb2-module-businessprocess-upstream/2.4.0.tar.xz
icingaweb2-module-businessprocess-upstream/2.4.0.zip
Adding upstream version 2.4.0.upstream/2.4.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'library/Businessprocess/Common')
-rw-r--r--library/Businessprocess/Common/EnumList.php168
1 files changed, 168 insertions, 0 deletions
diff --git a/library/Businessprocess/Common/EnumList.php b/library/Businessprocess/Common/EnumList.php
new file mode 100644
index 0000000..a1e5b56
--- /dev/null
+++ b/library/Businessprocess/Common/EnumList.php
@@ -0,0 +1,168 @@
+<?php
+
+namespace Icinga\Module\Businessprocess\Common;
+
+use Icinga\Application\Modules\Module;
+use Icinga\Data\Filter\Filter;
+use Icinga\Module\Businessprocess\IcingaDbObject;
+use Icinga\Module\Businessprocess\MonitoringRestrictions;
+use Icinga\Module\Businessprocess\ProvidedHook\Icingadb\IcingadbSupport;
+
+trait EnumList
+{
+ protected function enumHostForServiceList()
+ {
+ if ($this->useIcingaDbBackend()) {
+ $names = (new IcingaDbObject())->yieldHostnames();
+ } else {
+ $names = $this->backend
+ ->select()
+ ->from('hostStatus', ['hostname' => 'host_name'])
+ ->applyFilter(MonitoringRestrictions::getRestriction('monitoring/filter/objects'))
+ ->order('host_name')
+ ->getQuery()
+ ->fetchColumn();
+ }
+
+ // fetchPairs doesn't seem to work when using the same column with
+ // different aliases twice
+ $res = array();
+ foreach ($names as $name) {
+ $res[$name] = $name;
+ }
+
+ return $res;
+ }
+
+ protected function enumHostList()
+ {
+ if ($this->useIcingaDbBackend()) {
+ $names = (new IcingaDbObject())->yieldHostnames();
+ } else {
+ $names = $this->backend
+ ->select()
+ ->from('hostStatus', ['hostname' => 'host_name'])
+ ->applyFilter(MonitoringRestrictions::getRestriction('monitoring/filter/objects'))
+ ->order('host_name')
+ ->getQuery()
+ ->fetchColumn();
+ }
+
+ // fetchPairs doesn't seem to work when using the same column with
+ // different aliases twice
+ $res = array();
+ $suffix = ';Hoststatus';
+ foreach ($names as $name) {
+ $res[$name . $suffix] = $name;
+ }
+
+ return $res;
+ }
+
+ protected function enumServiceList($host)
+ {
+ if ($this->useIcingaDbBackend()) {
+ $names = (new IcingaDbObject())->yieldServicenames($host);
+ } else {
+ $names = $this->backend
+ ->select()
+ ->from('serviceStatus', ['service' => 'service_description'])
+ ->where('host_name', $host)
+ ->applyFilter(MonitoringRestrictions::getRestriction('monitoring/filter/objects'))
+ ->order('service_description')
+ ->getQuery()
+ ->fetchColumn();
+ }
+
+ $services = array();
+ foreach ($names as $name) {
+ $services[$host . ';' . $name] = $name;
+ }
+
+ return $services;
+ }
+
+ protected function enumHostListByFilter($filter)
+ {
+ if ($this->useIcingaDbBackend()) {
+ $names = (new IcingaDbObject())->yieldHostnames($filter);
+ } else {
+ $names = $this->backend
+ ->select()
+ ->from('hostStatus', ['hostname' => 'host_name'])
+ ->applyFilter(MonitoringRestrictions::getRestriction('monitoring/filter/objects'))
+ ->order('host_name')
+ ->getQuery()
+ ->fetchColumn();
+ }
+
+ // fetchPairs doesn't seem to work when using the same column with
+ // different aliases twice
+ $res = array();
+ $suffix = ';Hoststatus';
+ foreach ($names as $name) {
+ $res[$name . $suffix] = $name;
+ }
+
+ return $res;
+ }
+
+ protected function enumServiceListByFilter($filter)
+ {
+ $services = array();
+
+ if ($this->useIcingaDbBackend()) {
+ $objects = (new IcingaDbObject())->fetchServices($filter);
+ foreach ($objects as $object) {
+ $services[$object->host->name . ';' . $object->name] = $object->host->name . ':' . $object->name;
+ }
+ } else {
+ $objects = $this->backend
+ ->select()
+ ->from('serviceStatus', ['host' => 'host_name', 'service' => 'service_description'])
+ ->applyFilter(Filter::fromQueryString($filter))
+ ->applyFilter(MonitoringRestrictions::getRestriction('monitoring/filter/objects'))
+ ->order('service_description')
+ ->getQuery()
+ ->fetchAll();
+ foreach ($objects as $object) {
+ $services[$object->host . ';' . $object->service] = $object->host . ':' . $object->service;
+ }
+ }
+
+ return $services;
+ }
+
+ protected function enumHostStateList()
+ {
+ $hostStateList = [
+ 0 => $this->translate('UP'),
+ 1 => $this->translate('DOWN'),
+ 99 => $this->translate('PENDING')
+ ];
+
+ return $hostStateList;
+ }
+
+ protected function enumServiceStateList()
+ {
+ $serviceStateList = [
+ 0 => $this->translate('OK'),
+ 1 => $this->translate('WARNING'),
+ 2 => $this->translate('CRITICAL'),
+ 3 => $this->translate('UNKNOWN'),
+ 99 => $this->translate('PENDING'),
+ ];
+
+ return $serviceStateList;
+ }
+
+ protected function useIcingaDbBackend()
+ {
+ if (Module::exists('icingadb')) {
+ return ! $this->bp->hasBackendName() && IcingadbSupport::useIcingaDbAsBackend();
+ }
+
+ return false;
+ }
+}