Monitoring: add monitoring integration helper
This commit is contained in:
parent
00b5e7c3f1
commit
775363e281
|
@ -0,0 +1,36 @@
|
|||
<?php
|
||||
|
||||
namespace Icinga\Module\Director;
|
||||
|
||||
use Icinga\Application\Icinga;
|
||||
use Icinga\Module\Monitoring\Backend\MonitoringBackend;
|
||||
|
||||
class Monitoring
|
||||
{
|
||||
protected $backend;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$app = Icinga::app();
|
||||
$modules = $app->getModuleManager();
|
||||
if (!$modules->hasLoaded('monitoring') && $app->isCli()) {
|
||||
$app->getModuleManager()->loadEnabledModules();
|
||||
}
|
||||
|
||||
if ($modules->hasLoaded('monitoring')) {
|
||||
$this->backend = MonitoringBackend::createBackend();
|
||||
}
|
||||
}
|
||||
|
||||
public function isAvailable()
|
||||
{
|
||||
return $this->backend !== null;
|
||||
}
|
||||
|
||||
public function hasHost($hostname)
|
||||
{
|
||||
return $this->backend->select()->from('hostStatus', array(
|
||||
'hostname' => 'host_name',
|
||||
))->where('host_name', $hostname)->fetchOne() === $hostname;
|
||||
}
|
||||
}
|
|
@ -8,6 +8,7 @@ use Icinga\Exception\AuthenticationException;
|
|||
use Icinga\Exception\ConfigurationError;
|
||||
use Icinga\Exception\NotFoundError;
|
||||
use Icinga\Module\Director\Db;
|
||||
use Icinga\Module\Director\Monitoring;
|
||||
use Icinga\Module\Director\Objects\IcingaEndpoint;
|
||||
use Icinga\Module\Director\Web\Form\FormLoader;
|
||||
use Icinga\Module\Director\Web\Table\TableLoader;
|
||||
|
@ -22,6 +23,8 @@ abstract class ActionController extends Controller
|
|||
|
||||
private $api;
|
||||
|
||||
private $monitoring;
|
||||
|
||||
public function init()
|
||||
{
|
||||
if ($this->getRequest()->isApiRequest()) {
|
||||
|
@ -219,4 +222,13 @@ abstract class ActionController extends Controller
|
|||
|
||||
return $this->db;
|
||||
}
|
||||
|
||||
protected function monitoring()
|
||||
{
|
||||
if ($this->monitoring === null) {
|
||||
$this->monitoring = new Monitoring;
|
||||
}
|
||||
|
||||
return $this->monitoring;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue