icingaweb2-module-businessp.../library/Businessprocess/Common/EnumList.php
Ravi Kumar Kempapura Srinivasa ce3bbde289 Apply public static getRestriction and applyMonitoringRestriction changes
Apply the public static getRestriction and applyMonitoringRestriction changes in the places were the corresponding methods are used.
2022-02-03 16:54:01 +01:00

86 lines
2.5 KiB
PHP

<?php
namespace Icinga\Module\Businessprocess\Common;
use Icinga\Module\Businessprocess\IcingaDbBackend;
use Icinga\Module\Businessprocess\MonitoringRestrictions;
trait EnumList
{
protected function enumHostForServiceList()
{
if ($this->useIcingaDbBackend()) {
$names = (new IcingaDbBackend())->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 IcingaDbBackend())->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 IcingaDbBackend())->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 useIcingaDbBackend()
{
return $this->backendName === '_icingadb';
}
}