diff --git a/library/Director/Monitoring.php b/library/Director/Monitoring.php new file mode 100644 index 00000000..30f85fb3 --- /dev/null +++ b/library/Director/Monitoring.php @@ -0,0 +1,36 @@ +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; + } +} diff --git a/library/Director/Web/Controller/ActionController.php b/library/Director/Web/Controller/ActionController.php index bec63532..8fe29890 100644 --- a/library/Director/Web/Controller/ActionController.php +++ b/library/Director/Web/Controller/ActionController.php @@ -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; + } }