Monitoring: add monitoring integration helper

This commit is contained in:
Thomas Gelf 2016-03-20 11:18:06 +01:00
parent 00b5e7c3f1
commit 775363e281
2 changed files with 48 additions and 0 deletions

View File

@ -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;
}
}

View File

@ -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;
}
}