mirror of
https://github.com/Icinga/icingaweb2-module-businessprocess.git
synced 2025-12-23 08:09:37 -05:00
85 lines
2.4 KiB
PHP
85 lines
2.4 KiB
PHP
|
|
<?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';
|
||
|
|
}
|
||
|
|
}
|