2020-04-27 19:08:24 -04:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace Icinga\Module\Businessprocess\Common;
|
|
|
|
|
|
2021-11-18 06:19:05 -05:00
|
|
|
use Icinga\Application\Modules\Module;
|
2021-11-17 04:10:00 -05:00
|
|
|
use Icinga\Data\Filter\Filter;
|
2021-11-17 10:22:22 -05:00
|
|
|
use Icinga\Module\Businessprocess\IcingaDbObject;
|
2020-05-04 05:22:47 -04:00
|
|
|
use Icinga\Module\Businessprocess\MonitoringRestrictions;
|
2021-11-17 11:28:05 -05:00
|
|
|
use Icinga\Module\Businessprocess\ProvidedHook\Icingadb\IcingadbSupport;
|
2020-04-27 19:08:24 -04:00
|
|
|
|
|
|
|
|
trait EnumList
|
|
|
|
|
{
|
|
|
|
|
protected function enumHostForServiceList()
|
|
|
|
|
{
|
|
|
|
|
if ($this->useIcingaDbBackend()) {
|
2021-11-17 10:22:22 -05:00
|
|
|
$names = (new IcingaDbObject())->yieldHostnames();
|
2020-04-27 19:08:24 -04:00
|
|
|
} else {
|
|
|
|
|
$names = $this->backend
|
|
|
|
|
->select()
|
|
|
|
|
->from('hostStatus', ['hostname' => 'host_name'])
|
2020-05-04 05:22:47 -04:00
|
|
|
->applyFilter(MonitoringRestrictions::getRestriction('monitoring/filter/objects'))
|
2020-04-27 19:08:24 -04:00
|
|
|
->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()) {
|
2021-11-17 10:22:22 -05:00
|
|
|
$names = (new IcingaDbObject())->yieldHostnames();
|
2020-04-27 19:08:24 -04:00
|
|
|
} else {
|
|
|
|
|
$names = $this->backend
|
|
|
|
|
->select()
|
|
|
|
|
->from('hostStatus', ['hostname' => 'host_name'])
|
2020-05-04 05:22:47 -04:00
|
|
|
->applyFilter(MonitoringRestrictions::getRestriction('monitoring/filter/objects'))
|
2020-04-27 19:08:24 -04:00
|
|
|
->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()) {
|
2021-11-17 10:22:22 -05:00
|
|
|
$names = (new IcingaDbObject())->yieldServicenames($host);
|
2020-04-27 19:08:24 -04:00
|
|
|
} else {
|
|
|
|
|
$names = $this->backend
|
|
|
|
|
->select()
|
|
|
|
|
->from('serviceStatus', ['service' => 'service_description'])
|
|
|
|
|
->where('host_name', $host)
|
2020-05-04 05:22:47 -04:00
|
|
|
->applyFilter(MonitoringRestrictions::getRestriction('monitoring/filter/objects'))
|
2020-04-27 19:08:24 -04:00
|
|
|
->order('service_description')
|
|
|
|
|
->getQuery()
|
|
|
|
|
->fetchColumn();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$services = array();
|
|
|
|
|
foreach ($names as $name) {
|
|
|
|
|
$services[$host . ';' . $name] = $name;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $services;
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-17 04:10:00 -05:00
|
|
|
protected function enumHostListByFilter($filter)
|
|
|
|
|
{
|
|
|
|
|
if ($this->useIcingaDbBackend()) {
|
2021-11-17 10:22:22 -05:00
|
|
|
$names = (new IcingaDbObject())->yieldHostnames($filter);
|
2021-11-17 04:10:00 -05:00
|
|
|
} 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()) {
|
2021-11-17 10:22:22 -05:00
|
|
|
$objects = (new IcingaDbObject())->fetchServices($filter);
|
2021-11-17 04:10:00 -05:00
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-18 06:40:32 -05:00
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-27 19:08:24 -04:00
|
|
|
protected function useIcingaDbBackend()
|
|
|
|
|
{
|
2021-11-18 06:19:05 -05:00
|
|
|
if (Module::exists('icingadb')) {
|
|
|
|
|
return $this->backendName === '_icingadb' || IcingadbSupport::useIcingaDbAsBackend();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
2020-04-27 19:08:24 -04:00
|
|
|
}
|
2020-04-30 09:55:49 -04:00
|
|
|
}
|