2013-06-27 10:14:41 +02:00
|
|
|
<?php
|
|
|
|
|
2013-07-15 12:16:14 +02:00
|
|
|
use Monitoring\Backend;
|
2013-06-27 10:14:41 +02:00
|
|
|
use Icinga\Web\ModuleActionController;
|
|
|
|
use Icinga\Web\Hook;
|
2013-07-15 12:16:14 +02:00
|
|
|
use Monitoring\Object\Host;
|
|
|
|
use Monitoring\Object\Service;
|
2013-06-27 10:14:41 +02:00
|
|
|
|
|
|
|
class Monitoring_ShowController extends ModuleActionController
|
|
|
|
{
|
|
|
|
protected $backend;
|
|
|
|
|
|
|
|
public function init()
|
|
|
|
{
|
|
|
|
$host = $this->_getParam('host');
|
|
|
|
$service = $this->_getParam('service');
|
2013-07-12 14:33:17 +02:00
|
|
|
$this->backend = Backend::getInstance($this->_getParam('backend'));
|
|
|
|
$object = null;
|
|
|
|
// TODO: Do not allow wildcards in names!
|
2013-06-27 10:14:41 +02:00
|
|
|
if ($host !== null) {
|
|
|
|
// TODO: $this->assertPermission('host/read', $host);
|
2013-07-12 14:33:17 +02:00
|
|
|
if ($this->action_name !== 'host' && $service !== null && $service !== '*') {
|
|
|
|
// TODO: $this->assertPermission('service/read', $service);
|
|
|
|
$object = Service::fetch($this->backend, $host, $service);
|
|
|
|
} else {
|
|
|
|
$object = Host::fetch($this->backend, $host);
|
|
|
|
}
|
2013-06-27 10:14:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$this->view->compact = $this->_getParam('view') === 'compact';
|
|
|
|
|
2013-07-12 14:33:17 +02:00
|
|
|
if ($object === null) {
|
|
|
|
// TODO: Notification, not found
|
|
|
|
$this->redirectNow('monitoring/list/services');
|
|
|
|
return;
|
2013-06-27 10:14:41 +02:00
|
|
|
}
|
2013-07-12 14:33:17 +02:00
|
|
|
$this->view->object = $object;
|
|
|
|
$this->view->tabs = $this->createTabs();
|
|
|
|
$this->prepareTicketHook();
|
2013-06-27 10:14:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function serviceAction()
|
|
|
|
{
|
2013-07-12 14:33:17 +02:00
|
|
|
$object = $this->view->object->prefetch();
|
|
|
|
$this->prepareGrapherHook();
|
2013-06-27 10:14:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function hostAction()
|
|
|
|
{
|
2013-07-12 14:33:17 +02:00
|
|
|
$this->view->object->prefetch();
|
|
|
|
$this->prepareGrapherHook();
|
2013-06-27 10:14:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function historyAction()
|
|
|
|
{
|
|
|
|
$this->view->history = $this->backend->select()
|
|
|
|
->from('eventHistory', array(
|
|
|
|
'object_type',
|
|
|
|
'host_name',
|
|
|
|
'service_description',
|
|
|
|
'timestamp',
|
|
|
|
'state',
|
|
|
|
'attempt',
|
|
|
|
'max_attempts',
|
|
|
|
'output',
|
|
|
|
'type'
|
|
|
|
))->applyRequest($this->_request);
|
|
|
|
|
2013-07-12 14:33:17 +02:00
|
|
|
$this->view->preserve = $this->view->history->getAppliedFilter()->toParams();
|
2013-06-27 10:14:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function servicesAction()
|
|
|
|
{
|
2013-07-12 14:33:17 +02:00
|
|
|
$this->_setParam('service', null);
|
2013-06-27 10:14:41 +02:00
|
|
|
// Ugly and slow:
|
|
|
|
$this->view->services = $this->view->action('services', 'list', 'monitoring', array(
|
2013-07-12 14:33:17 +02:00
|
|
|
'view' => 'compact'
|
2013-06-27 10:14:41 +02:00
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function ticketAction()
|
|
|
|
{
|
|
|
|
if (Hook::has('ticket')) {
|
2013-07-12 14:33:17 +02:00
|
|
|
// TODO: Still hardcoded, should ask for URL:
|
|
|
|
$id = $this->_getParam('ticket');
|
2013-06-27 10:14:41 +02:00
|
|
|
$ticketModule = 'rt';
|
|
|
|
$this->render();
|
|
|
|
$this->_forward('ticket', 'show', $ticketModule, array(
|
|
|
|
'id' => $id
|
|
|
|
));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-12 14:33:17 +02:00
|
|
|
protected function prepareTicketHook()
|
|
|
|
{
|
|
|
|
if (Hook::has('ticket')) {
|
|
|
|
$object = $this->view->object;
|
|
|
|
$params = array(
|
|
|
|
'host' => $object->host_name
|
|
|
|
);
|
|
|
|
if ($object instanceof Service) {
|
|
|
|
$params['service'] = $object->service_description;
|
|
|
|
}
|
|
|
|
|
|
|
|
$params['ticket'] = '__ID__';
|
|
|
|
$this->view->ticket_link = preg_replace(
|
|
|
|
'~__ID__~',
|
|
|
|
'\$1',
|
|
|
|
$this->view->qlink('#__ID__',
|
|
|
|
'monitoring/show/ticket',
|
|
|
|
$params
|
|
|
|
)
|
|
|
|
);
|
|
|
|
// TODO: Global ticket pattern config (or per environment)
|
|
|
|
$this->view->ticket_pattern = '~#(\d{4,6})~';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function prepareGrapherHook()
|
|
|
|
{
|
|
|
|
if ($grapher = Hook::get('grapher')) {
|
|
|
|
$object = $this->view->object;
|
|
|
|
if ($grapher->hasGraph(
|
|
|
|
$object->host_name,
|
|
|
|
$object->service_description
|
|
|
|
)) {
|
|
|
|
$this->view->preview_image = $grapher->getPreviewImage(
|
|
|
|
$object->host_name,
|
|
|
|
$object->service_description
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-27 10:14:41 +02:00
|
|
|
protected function createTabs()
|
|
|
|
{
|
2013-07-12 14:33:17 +02:00
|
|
|
$object = $this->view->object;
|
2013-06-27 10:14:41 +02:00
|
|
|
$tabs = $this->widget('tabs');
|
2013-07-12 14:33:17 +02:00
|
|
|
$params = array('host' => $object->host_name);
|
2013-06-27 10:14:41 +02:00
|
|
|
if ($backend = $this->_getParam('backend')) {
|
|
|
|
$params['backend'] = $backend;
|
|
|
|
}
|
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
|
|
|
}
|
2013-07-12 14:33:17 +02:00
|
|
|
// TODO: Work with URL
|
|
|
|
$servicesParams = $params;
|
|
|
|
unset($servicesParams['service']);
|
2013-06-27 10:14:41 +02:00
|
|
|
$tabs->add('host', array(
|
|
|
|
'title' => 'Host',
|
|
|
|
'icon' => 'img/classic/server.png',
|
|
|
|
'url' => 'monitoring/show/host',
|
2013-07-12 14:33:17 +02:00
|
|
|
'urlParams' => $params,
|
2013-06-27 10:14:41 +02:00
|
|
|
));
|
|
|
|
$tabs->add('services', array(
|
|
|
|
'title' => 'Services',
|
|
|
|
'icon' => 'img/classic/service.png',
|
|
|
|
'url' => 'monitoring/show/services',
|
2013-07-12 14:33:17 +02:00
|
|
|
'urlParams' => $servicesParams,
|
2013-06-27 10:14:41 +02:00
|
|
|
));
|
|
|
|
if (isset($params['service'])) {
|
|
|
|
$tabs->add('service', array(
|
|
|
|
'title' => 'Service',
|
|
|
|
'icon' => 'img/classic/service.png',
|
|
|
|
'url' => 'monitoring/show/service',
|
|
|
|
'urlParams' => $params,
|
|
|
|
));
|
|
|
|
}
|
|
|
|
$tabs->add('history', array(
|
|
|
|
'title' => 'History',
|
|
|
|
'icon' => 'img/classic/history.gif',
|
|
|
|
'url' => 'monitoring/show/history',
|
|
|
|
'urlParams' => $params,
|
|
|
|
));
|
|
|
|
if ($this->action_name === 'ticket') {
|
|
|
|
$tabs->add('ticket', array(
|
|
|
|
'title' => 'Ticket',
|
|
|
|
'icon' => 'img/classic/ticket.gif',
|
|
|
|
'url' => 'monitoring/show/ticket',
|
|
|
|
'urlParams' => $params + array('ticket' => $this->_getParam('ticket')),
|
|
|
|
));
|
|
|
|
}
|
2013-07-12 14:33:17 +02:00
|
|
|
|
|
|
|
$tabs->activate($this->action_name)->enableSpecialActions();
|
|
|
|
|
2013-06-27 10:14:41 +02:00
|
|
|
/*
|
|
|
|
$tabs->add('contacts', array(
|
|
|
|
'title' => 'Contacts',
|
|
|
|
'icon' => 'img/classic/customer.png',
|
|
|
|
'url' => 'monitoring/detail/contacts',
|
|
|
|
'urlParams' => $params,
|
|
|
|
));
|
|
|
|
*/
|
|
|
|
// TODO: Inventory 'img/classic/facts.gif'
|
|
|
|
// Ticket 'img/classic/ticket.gif'
|
|
|
|
// Customer 'img/classic/customer.png'
|
|
|
|
return $tabs;
|
|
|
|
}
|
|
|
|
}
|