move classes into subfolder

fix some problems and mark TODO
This commit is contained in:
Tobias Tiederle 2022-12-29 19:36:25 +00:00 committed by Sukhwinder Dhillon
parent 1c6090193d
commit b28b36f815
4 changed files with 67 additions and 33 deletions

View File

@ -5,6 +5,9 @@ namespace Icinga\Module\Director;
use Icinga\Application\Icinga;
use Icinga\Authentication\Auth;
use Icinga\Data\Filter\Filter;
use Icinga\Module\Director\Backend\MonitorBackend;
use Icinga\Module\Director\Backend\MonitorBackendIcingadb;
use Icinga\Module\Director\Backend\MonitorBackendMonitoring;
class Backend implements MonitorBackend
{
@ -53,15 +56,26 @@ class Backend implements MonitorBackend
public function hasHost($hostname)
{
return (($this->backend === null) || $this->backend->hasHost($hostname));
return (($this->backend !== null) && $this->backend->hasHost($hostname));
}
public function hasHostWithExtraFilter($hostname, Filter $filter)
{
return (($this->backend !== null) && $this->backend->hasHostWithExtraFilter($hostname, $filter));
}
public function hasService($hostname, $service)
{
return (($this->backend === null) || $this->backend->hasService($hostname, $service));
return (($this->backend !== null) && $this->backend->hasService($hostname, $service));
}
public function authCanEditHost(Auth $auth, $hostname, $service)
public function hasServiceWithExtraFilter($hostname, $service, Filter $filter)
{
return (($this->backend !== null)
&& $this->backend->hasServiceWithExtraFilter($hostname, $service, $filter));
}
public function authCanEditHost(Auth $auth, $hostname)
{
if ($auth->hasPermission('director/monitoring/hosts')) {
$restriction = null;
@ -99,32 +113,6 @@ class Backend implements MonitorBackend
return false;
}
public function hasHostWithExtraFilter($hostname, Filter $filter)
{
if ($this->backend === null) {
return false;
}
return $this->backend->select()->from('hostStatus', [
'hostname' => 'host_name',
])->where('host_name', $hostname)->applyFilter($filter)->fetchOne() === $hostname;
}
public function hasServiceWithExtraFilter($hostname, $service, Filter $filter)
{
if ($this->backend === null) {
return false;
}
return (array) $this
->prepareServiceKeyColumnQuery($hostname, $service)
->applyFilter($filter)
->fetchRow() === [
'hostname' => $hostname,
'service' => $service,
];
}
public function getHostLink($title, $hostname, array $attributes = null)
{
if ($this->backend !== null) {
@ -138,7 +126,7 @@ class Backend implements MonitorBackend
if ($this->backend === null) {
return (object) [
'hostname' => $hostname,
'state' => 'pending',
'state' => '99',
'problem' => '0',
'acknowledged' => '0',
'in_downtime' => '0',

View File

@ -1,6 +1,8 @@
<?php
namespace Icinga\Module\Director;
namespace Icinga\Module\Director\Backend;
use Icinga\Data\Filter\Filter;
interface MonitorBackend
{
@ -8,8 +10,12 @@ interface MonitorBackend
public function hasHost($hostname);
public function hasHostWithExtraFilter($hostname, Filter $filter);
public function hasService($hostname, $service);
public function hasServiceWithExtraFilter($hostname, $service, Filter $filter);
public function getHostLink($title, $hostname, array $attributes = null);
public function getHostState($hostname);

View File

@ -1,9 +1,10 @@
<?php
namespace Icinga\Module\Director;
namespace Icinga\Module\Director\Backend;
use gipfl\IcingaWeb2\Link;
use Icinga\Application\Icinga;
use Icinga\Data\Filter\Filter as DataFilter;
use Icinga\Module\Icingadb\Common\Auth;
use Icinga\Module\Icingadb\Common\Database;
use Icinga\Module\Icingadb\Model\Host;
@ -36,6 +37,12 @@ class MonitorBackendIcingadb implements MonitorBackend
return ($host !== null);
}
public function hasHostWithExtraFilter($hostname, DataFilter $filter)
{
// TODO
return false;
}
public function hasService($hostname, $service)
{
$query = Service::on($this->getDb());
@ -53,6 +60,12 @@ class MonitorBackendIcingadb implements MonitorBackend
return ($service !== null);
}
public function hasServiceWithExtraFilter($hostname, $service, DataFilter $filter)
{
// TODO
return false;
}
public function getHostLink($title, $hostname, array $attributes = null)
{
return Link::create(

View File

@ -1,9 +1,10 @@
<?php
namespace Icinga\Module\Director;
namespace Icinga\Module\Director\Backend;
use gipfl\IcingaWeb2\Link;
use Icinga\Application\Icinga;
use Icinga\Data\Filter\Filter;
use Icinga\Module\Monitoring\Backend\MonitoringBackend;
class MonitorBackendMonitoring implements MonitorBackend
@ -39,6 +40,17 @@ class MonitorBackendMonitoring implements MonitorBackend
])->where('host_name', $hostname)->fetchOne() === $hostname;
}
public function hasHostWithExtraFilter($hostname, Filter $filter)
{
if ($this->backend === null) {
return false;
}
return $this->backend->select()->from('hostStatus', [
'hostname' => 'host_name',
])->where('host_name', $hostname)->applyFilter($filter)->fetchOne() === $hostname;
}
public function hasService($hostname, $service)
{
if ($this->backend === null) {
@ -51,6 +63,21 @@ class MonitorBackendMonitoring implements MonitorBackend
];
}
public function hasServiceWithExtraFilter($hostname, $service, Filter $filter)
{
if ($this->backend === null) {
return false;
}
return (array) $this
->prepareServiceKeyColumnQuery($hostname, $service)
->applyFilter($filter)
->fetchRow() === [
'hostname' => $hostname,
'service' => $service,
];
}
public function getHostLink($title, $hostname, array $attributes = null)
{
return Link::create(