icingaweb2/modules/monitoring/application/controllers/ShowController.php

219 lines
6.6 KiB
PHP
Raw Normal View History

<?php
// {{{ICINGA_LICENSE_HEADER}}}
// {{{ICINGA_LICENSE_HEADER}}}
use Icinga\Application\Benchmark;
use Icinga\Web\Hook;
use Icinga\Web\Widget\Tabs;
use Icinga\Web\Widget\Tabextension\OutputFormat;
use Icinga\Web\Widget\Tabextension\DashboardAction;
use Icinga\Module\Monitoring\Backend;
use Icinga\Module\Monitoring\Controller;
use Icinga\Module\Monitoring\Object\AbstractObject;
use Icinga\Module\Monitoring\Object\Host;
use Icinga\Module\Monitoring\Object\Service;
/**
* Class Monitoring_ShowController
*
* Actions for show context
*/
class Monitoring_ShowController extends Controller
{
/**
* @var Backend
*/
protected $backend;
/**
* @var Hook\GrapherHook
*/
protected $grapher;
/**
* Initialize the controller
*/
public function init()
{
if ($this->getRequest()->getActionName() === 'host') {
$this->view->object = new Host($this->params);
} elseif ($this->getRequest()->getActionName() === 'service') {
$this->view->object = new Service($this->params);
} else {
// TODO: Well... this could be done better
$this->view->object = AbstractObject::fromParams($this->params);
}
2014-03-04 13:50:49 +01:00
if (Hook::has('ticket')) {
$this->view->tickets = Hook::first('ticket');
}
if (Hook::has('grapher')) {
$this->grapher = Hook::first('grapher');
}
$this->createTabs();
}
/**
* Service overview
*/
public function serviceAction()
{
$o = $this->view->object;
2014-03-04 13:33:02 +01:00
$this->setAutorefreshInterval(10);
$this->view->title = $o->service_description
. ' on ' . $o->host_name;
$this->getTabs()->activate('service');
$o->populate();
if ($this->grapher && $this->grapher->hasPreviews($o->host_name, $o->service_description)) {
$this->view->grapherHtml = $this->grapher->getPreviewHtml($o->host_name, $o->service_description);
}
}
/**
* Host overview
*/
public function hostAction()
{
$o = $this->view->object;
2014-03-04 13:33:02 +01:00
$this->setAutorefreshInterval(10);
$this->getTabs()->activate('host');
$this->view->title = $o->host_name;
$o->populate();
if ($this->grapher && $this->grapher->hasPreviews($o->host_name)) {
$this->view->grapherHtml = $this->grapher->getPreviewHtml($o->host_name);
}
}
public function historyAction()
{
$this->getTabs()->activate('history');
//$this->view->object->populate();
$this->view->object->fetchEventHistory();
$this->handleFormatRequest($this->view->object->eventhistory);
$this->view->history = $this->view->object->eventhistory
->paginate($this->params->get('limit', 50));
}
public function servicesAction()
{
$this->getTabs()->activate('services');
$this->_setParam('service', '');
// TODO: This used to be a hack and still is. Modifying query string here.
$_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',
));
}
public function contactAction()
{
$contactName = $this->getParam('contact');
if (! $contactName) {
throw new Zend_Controller_Action_Exception(
$this->translate('The parameter `contact\' is required'),
404
);
}
$query = $this->backend->select()->from('contact', array(
'contact_name',
'contact_id',
'contact_alias',
'contact_email',
'contact_pager',
'contact_notify_service_timeperiod',
'contact_notify_service_recovery',
'contact_notify_service_warning',
'contact_notify_service_critical',
'contact_notify_service_unknown',
'contact_notify_service_flapping',
'contact_notify_service_downtime',
'contact_notify_host_timeperiod',
'contact_notify_host_recovery',
'contact_notify_host_down',
'contact_notify_host_unreachable',
'contact_notify_host_flapping',
'contact_notify_host_downtime',
));
$query->where('contact_name', $contactName);
$contact = $query->getQuery()->fetchRow();
if ($contact) {
$commands = $this->backend->select()->from('command', array(
'command_line',
'command_name'
))->where('contact_id', $contact->contact_id);
$this->view->commands = $commands->paginate();
}
$this->view->contact = $contact;
$this->view->contactName = $contactName;
}
/**
* Creating tabs for this controller
* @return Tabs
*/
protected function createTabs()
{
if (($object = $this->view->object) === null) {
return;
}
$tabs = $this->getTabs();
$params = array(
'host' => $object->host_name,
);
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;
}
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,
)
);
if (isset($params['service'])) {
$tabs->add(
'service',
array(
'title' => 'Service',
'icon' => 'img/icons/service.png',
'url' => 'monitoring/show/service',
'urlParams' => $params,
)
);
}
$tabs->add(
'services',
array(
'title' => 'Services',
'icon' => 'img/icons/service.png',
'url' => 'monitoring/show/services',
'urlParams' => $params,
)
);
$tabs->add(
'history',
array(
'title' => 'History',
'icon' => 'img/icons/history.png',
'url' => 'monitoring/show/history',
'urlParams' => $params,
)
);
$tabs->extend(new OutputFormat())
->extend(new DashboardAction());
}
}