2013-06-27 10:14:41 +02:00
|
|
|
<?php
|
2013-07-02 16:00:41 +02:00
|
|
|
// {{{ICINGA_LICENSE_HEADER}}}
|
|
|
|
// {{{ICINGA_LICENSE_HEADER}}}
|
2013-06-27 10:14:41 +02:00
|
|
|
|
2014-02-18 20:04:54 +01:00
|
|
|
use Icinga\Application\Benchmark;
|
|
|
|
use Icinga\Web\Hook;
|
|
|
|
use Icinga\Web\Widget\Tabs;
|
|
|
|
use Icinga\Web\Widget\Tabextension\OutputFormat;
|
2013-10-15 19:56:33 +02:00
|
|
|
use Icinga\Web\Widget\Tabextension\DashboardAction;
|
2014-02-18 20:04:54 +01:00
|
|
|
use Icinga\Module\Monitoring\Backend;
|
|
|
|
use Icinga\Module\Monitoring\Controller;
|
2013-10-15 19:56:33 +02:00
|
|
|
use Icinga\Module\Monitoring\Object\AbstractObject;
|
2014-02-18 20:04:54 +01:00
|
|
|
use Icinga\Module\Monitoring\Object\Host;
|
|
|
|
use Icinga\Module\Monitoring\Object\Service;
|
2013-08-08 16:22:22 +02:00
|
|
|
|
2013-07-02 16:00:41 +02:00
|
|
|
/**
|
|
|
|
* Class Monitoring_ShowController
|
|
|
|
*
|
|
|
|
* Actions for show context
|
|
|
|
*/
|
2014-02-18 20:04:54 +01:00
|
|
|
class Monitoring_ShowController extends Controller
|
2013-06-27 10:14:41 +02:00
|
|
|
{
|
2013-07-02 16:00:41 +02:00
|
|
|
/**
|
|
|
|
* @var Backend
|
|
|
|
*/
|
2013-06-27 10:14:41 +02:00
|
|
|
protected $backend;
|
|
|
|
|
2014-06-21 04:13:14 +02:00
|
|
|
protected $grapher;
|
|
|
|
|
2013-07-02 16:00:41 +02:00
|
|
|
/**
|
|
|
|
* Initialize the controller
|
|
|
|
*/
|
2013-06-27 10:14:41 +02:00
|
|
|
public function init()
|
|
|
|
{
|
2013-10-17 19:48:46 +02:00
|
|
|
if ($this->getRequest()->getActionName() === 'host') {
|
2014-06-17 15:10:54 +02:00
|
|
|
$this->view->object = new Host($this->params);
|
2014-05-20 15:57:28 +02:00
|
|
|
} elseif ($this->getRequest()->getActionName() === 'service') {
|
2014-06-17 15:10:54 +02:00
|
|
|
$this->view->object = new Service($this->params);
|
2013-10-17 19:48:46 +02:00
|
|
|
} else {
|
2014-02-18 20:04:54 +01:00
|
|
|
// TODO: Well... this could be done better
|
2014-06-17 15:10:54 +02:00
|
|
|
$this->view->object = AbstractObject::fromParams($this->params);
|
2013-10-17 19:48:46 +02:00
|
|
|
}
|
2014-03-04 13:50:49 +01:00
|
|
|
if (Hook::has('ticket')) {
|
|
|
|
$this->view->tickets = Hook::first('ticket');
|
|
|
|
}
|
2014-06-21 04:13:14 +02:00
|
|
|
if (Hook::has('grapher')) {
|
|
|
|
$this->grapher = Hook::first('grapher');
|
|
|
|
}
|
2013-10-17 19:48:46 +02:00
|
|
|
|
2013-08-08 16:22:22 +02:00
|
|
|
$this->createTabs();
|
2013-06-27 10:14:41 +02:00
|
|
|
}
|
|
|
|
|
2013-07-02 16:00:41 +02:00
|
|
|
/**
|
|
|
|
* Service overview
|
|
|
|
*/
|
2013-06-27 10:14:41 +02:00
|
|
|
public function serviceAction()
|
|
|
|
{
|
2014-06-21 04:13:14 +02:00
|
|
|
$o = $this->view->object;
|
2014-03-04 13:33:02 +01:00
|
|
|
$this->setAutorefreshInterval(10);
|
2014-06-21 04:13:14 +02:00
|
|
|
$this->view->title = $o->service_description
|
|
|
|
. ' on ' . $o->host_name;
|
2014-02-18 20:04:54 +01:00
|
|
|
$this->getTabs()->activate('service');
|
2014-06-21 04:13:14 +02:00
|
|
|
$o->populate();
|
|
|
|
if ($this->grapher && $this->grapher->hasGraph($o->host_name, $o->service_description)) {
|
|
|
|
$this->view->grapherHtml = $this->grapher->getPreviewImage($o->host_name, $o->service_description);
|
|
|
|
}
|
2013-06-27 10:14:41 +02:00
|
|
|
}
|
|
|
|
|
2013-07-02 16:00:41 +02:00
|
|
|
/**
|
|
|
|
* Host overview
|
|
|
|
*/
|
2013-06-27 10:14:41 +02:00
|
|
|
public function hostAction()
|
|
|
|
{
|
2014-06-21 04:13:14 +02:00
|
|
|
$o = $this->view->object;
|
2014-03-04 13:33:02 +01:00
|
|
|
$this->setAutorefreshInterval(10);
|
2014-02-18 20:04:54 +01:00
|
|
|
$this->getTabs()->activate('host');
|
2014-06-21 04:13:14 +02:00
|
|
|
$this->view->title = $o->host_name;
|
|
|
|
$o->populate();
|
|
|
|
if ($this->grapher && $this->grapher->hasGraph($o->host_name)) {
|
|
|
|
$this->view->grapherHtml = $this->grapher->getPreviewImage($o->host_name);
|
|
|
|
}
|
2013-06-27 10:14:41 +02:00
|
|
|
}
|
|
|
|
|
2013-10-10 11:54:51 +02:00
|
|
|
public function historyAction()
|
|
|
|
{
|
2014-02-18 20:04:54 +01:00
|
|
|
$this->getTabs()->activate('history');
|
2014-03-08 01:47:35 +01:00
|
|
|
//$this->view->object->populate();
|
2013-10-10 11:54:51 +02:00
|
|
|
$this->view->object->fetchEventHistory();
|
2014-03-07 10:07:54 +01:00
|
|
|
$this->handleFormatRequest($this->view->object->eventhistory);
|
2014-06-20 14:16:36 +02:00
|
|
|
$this->view->history = $this->view->object->eventhistory
|
|
|
|
->paginate($this->params->get('limit', 50));
|
2013-10-10 11:54:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function servicesAction()
|
|
|
|
{
|
2014-03-06 19:54:38 +01:00
|
|
|
$this->getTabs()->activate('services');
|
2014-03-08 01:47:35 +01:00
|
|
|
$this->_setParam('service', '');
|
2014-06-17 15:17:13 +02:00
|
|
|
// TODO: This used to be a hack and still is. Modifying query string here.
|
2014-06-20 14:16:36 +02:00
|
|
|
$_SERVER['QUERY_STRING'] = (string) $this->params->without('service')->set('limit', '');
|
2014-03-08 01:00:21 +01:00
|
|
|
$this->view->services = $this->view->action('services', 'list', 'monitoring', array(
|
|
|
|
'view' => 'compact',
|
|
|
|
'sort' => 'service_description',
|
|
|
|
));
|
2013-10-10 11:54:51 +02:00
|
|
|
}
|
|
|
|
|
2013-07-02 16:00:41 +02:00
|
|
|
/**
|
|
|
|
* Creating tabs for this controller
|
2013-09-24 12:48:30 +02:00
|
|
|
* @return Tabs
|
2013-07-02 16:00:41 +02:00
|
|
|
*/
|
2013-06-27 10:14:41 +02:00
|
|
|
protected function createTabs()
|
|
|
|
{
|
2014-04-09 08:44:51 +02:00
|
|
|
if (($object = $this->view->object) === null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-08-08 16:22:22 +02:00
|
|
|
$tabs = $this->getTabs();
|
2013-06-27 10:14:41 +02:00
|
|
|
$params = array(
|
2013-10-10 11:54:51 +02:00
|
|
|
'host' => $object->host_name,
|
2013-06-27 10:14:41 +02:00
|
|
|
);
|
2013-07-12 14:33:17 +02:00
|
|
|
if ($object instanceof Service) {
|
|
|
|
$params['service'] = $object->service_description;
|
|
|
|
} elseif ($service = $this->_getParam('service')) {
|
|
|
|
$params['service'] = $service;
|
2013-06-27 10:14:41 +02:00
|
|
|
}
|
2014-03-08 01:00:21 +01:00
|
|
|
$tabs->add(
|
|
|
|
'host',
|
|
|
|
array(
|
|
|
|
'title' => 'Host',
|
|
|
|
'icon' => 'img/icons/host.png',
|
|
|
|
'url' => 'monitoring/show/host',
|
|
|
|
'urlParams' => $params,
|
|
|
|
)
|
|
|
|
);
|
2013-10-10 11:54:51 +02:00
|
|
|
if (isset($params['service'])) {
|
|
|
|
$tabs->add(
|
|
|
|
'service',
|
|
|
|
array(
|
|
|
|
'title' => 'Service',
|
2014-02-18 20:04:54 +01:00
|
|
|
'icon' => 'img/icons/service.png',
|
2013-10-10 11:54:51 +02:00
|
|
|
'url' => 'monitoring/show/service',
|
|
|
|
'urlParams' => $params,
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
$tabs->add(
|
|
|
|
'services',
|
|
|
|
array(
|
|
|
|
'title' => 'Services',
|
2014-02-18 20:04:54 +01:00
|
|
|
'icon' => 'img/icons/service.png',
|
2013-10-10 11:54:51 +02:00
|
|
|
'url' => 'monitoring/show/services',
|
2014-03-08 01:47:35 +01:00
|
|
|
'urlParams' => $params,
|
2013-10-10 11:54:51 +02:00
|
|
|
)
|
|
|
|
);
|
|
|
|
$tabs->add(
|
|
|
|
'history',
|
|
|
|
array(
|
|
|
|
'title' => 'History',
|
2014-02-18 20:04:54 +01:00
|
|
|
'icon' => 'img/icons/history.png',
|
2013-10-10 11:54:51 +02:00
|
|
|
'url' => 'monitoring/show/history',
|
|
|
|
'urlParams' => $params,
|
|
|
|
)
|
|
|
|
);
|
2013-08-08 16:22:22 +02:00
|
|
|
$tabs->extend(new OutputFormat())
|
2014-02-18 20:04:54 +01:00
|
|
|
->extend(new DashboardAction());
|
2013-06-27 10:14:41 +02:00
|
|
|
}
|
|
|
|
}
|