icingaweb2-module-businessp.../library/Businessprocess/Common/EnumList.php

85 lines
2.4 KiB
PHP
Raw Normal View History

<?php
namespace Icinga\Module\Businessprocess\Common;
use Icinga\Module\Businessprocess\IcingaDbBackend;
trait EnumList
{
protected function enumHostForServiceList()
{
if ($this->useIcingaDbBackend()) {
$names = (new IcingaDbBackend())->yieldHostnames();
} else {
$names = $this->backend
->select()
->from('hostStatus', ['hostname' => 'host_name'])
->applyFilter($this->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($this->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($this->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';
}
}