2013-06-27 10:14:41 +02:00
|
|
|
<?php
|
2015-02-04 10:46:36 +01:00
|
|
|
/* Icinga Web 2 | (c) 2013-2015 Icinga Development Team | GPLv2+ */
|
2013-06-27 10:14:41 +02:00
|
|
|
|
2014-09-04 13:07:03 +02:00
|
|
|
use Icinga\Module\Monitoring\Object\MonitoredObject;
|
2014-02-18 20:04:54 +01:00
|
|
|
use Icinga\Web\Hook;
|
2014-09-24 07:37:14 +02:00
|
|
|
use Icinga\Web\Url;
|
2014-02-18 20:04:54 +01:00
|
|
|
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-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-08-27 09:35:43 +02:00
|
|
|
/**
|
|
|
|
* @var Hook\GrapherHook
|
|
|
|
*/
|
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()
|
|
|
|
{
|
2014-09-24 07:37:14 +02:00
|
|
|
$this->view->object = MonitoredObject::fromParams($this->params);
|
2014-09-30 10:11:40 +02:00
|
|
|
if ($this->view->object && $this->view->object->fetch() === false) {
|
2014-09-24 07:37:14 +02:00
|
|
|
throw new Zend_Controller_Action_Exception($this->translate('Host or service not found'));
|
2013-10-17 19:48:46 +02:00
|
|
|
}
|
2014-09-24 07:37:14 +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');
|
2014-09-04 18:57:20 +02:00
|
|
|
if ($this->grapher && ! $this->grapher->hasPreviews()) {
|
2014-09-04 18:51:54 +02:00
|
|
|
$this->grapher = null;
|
|
|
|
}
|
2014-06-21 04:13:14 +02:00
|
|
|
}
|
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
|
|
|
/**
|
2014-09-24 07:37:14 +02:00
|
|
|
* @deprecated
|
2013-07-02 16:00:41 +02:00
|
|
|
*/
|
2013-06-27 10:14:41 +02:00
|
|
|
public function serviceAction()
|
|
|
|
{
|
2014-09-24 07:37:14 +02:00
|
|
|
$this->redirectNow(Url::fromRequest()->setPath('monitoring/service/show'));
|
2013-06-27 10:14:41 +02:00
|
|
|
}
|
|
|
|
|
2013-07-02 16:00:41 +02:00
|
|
|
/**
|
2014-09-24 07:37:14 +02:00
|
|
|
* @deprecated
|
2013-07-02 16:00:41 +02:00
|
|
|
*/
|
2013-06-27 10:14:41 +02:00
|
|
|
public function hostAction()
|
|
|
|
{
|
2014-09-24 07:37:14 +02:00
|
|
|
$this->redirectNow(Url::fromRequest()->setPath('monitoring/host/show'));
|
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');
|
2013-10-10 11:54:51 +02:00
|
|
|
$this->view->object->fetchEventHistory();
|
2014-12-29 17:54:09 +01:00
|
|
|
$this->view->history = $this->view->object->eventhistory->getQuery()->paginate($this->params->get('limit', 50));
|
2014-03-07 10:07:54 +01:00
|
|
|
$this->handleFormatRequest($this->view->object->eventhistory);
|
2014-09-05 18:03:45 +02:00
|
|
|
$this->fetchHostStats();
|
2013-10-10 11:54:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function servicesAction()
|
|
|
|
{
|
2014-11-25 16:35:09 +01:00
|
|
|
$this->setAutorefreshInterval(15);
|
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',
|
|
|
|
));
|
2014-09-05 18:03:45 +02:00
|
|
|
$this->fetchHostStats();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function fetchHostStats()
|
|
|
|
{
|
|
|
|
$this->view->stats = $this->backend->select()->from('statusSummary', array(
|
|
|
|
'services_total',
|
|
|
|
'services_ok',
|
|
|
|
'services_problem',
|
|
|
|
'services_problem_handled',
|
|
|
|
'services_problem_unhandled',
|
|
|
|
'services_critical',
|
|
|
|
'services_critical_unhandled',
|
|
|
|
'services_critical_handled',
|
|
|
|
'services_warning',
|
|
|
|
'services_warning_unhandled',
|
|
|
|
'services_warning_handled',
|
|
|
|
'services_unknown',
|
|
|
|
'services_unknown_unhandled',
|
|
|
|
'services_unknown_handled',
|
|
|
|
'services_pending',
|
|
|
|
))->where('service_host_name', $this->params->get('host'))->getQuery()->fetchRow();
|
2013-10-10 11:54:51 +02:00
|
|
|
}
|
|
|
|
|
2014-07-18 11:48:26 +02:00
|
|
|
public function contactAction()
|
|
|
|
{
|
2015-04-10 09:39:39 +02:00
|
|
|
$contactName = $this->getParam('contact_name');
|
2014-08-27 16:13:25 +02:00
|
|
|
|
|
|
|
if (! $contactName) {
|
2014-07-18 11:48:26 +02:00
|
|
|
throw new Zend_Controller_Action_Exception(
|
2015-04-10 09:39:39 +02:00
|
|
|
$this->translate('The parameter `contact_name\' is required'),
|
2014-07-18 11:48:26 +02:00
|
|
|
404
|
|
|
|
);
|
|
|
|
}
|
2014-08-27 16:13:25 +02:00
|
|
|
|
2014-07-18 11:48:26 +02:00
|
|
|
$query = $this->backend->select()->from('contact', array(
|
|
|
|
'contact_name',
|
|
|
|
'contact_id',
|
2015-04-10 09:45:23 +02:00
|
|
|
'contact_alias_name',
|
|
|
|
'contact_email_address',
|
2014-07-18 11:48:26 +02:00
|
|
|
'contact_pager',
|
2014-08-27 16:36:52 +02:00
|
|
|
'contact_object_id',
|
2014-07-18 11:48:26 +02:00
|
|
|
'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',
|
2015-04-10 09:45:23 +02:00
|
|
|
'contact_notify_host_downtime'
|
2014-07-18 11:48:26 +02:00
|
|
|
));
|
2014-08-27 16:13:25 +02:00
|
|
|
|
|
|
|
$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();
|
2014-08-27 16:36:52 +02:00
|
|
|
|
|
|
|
$notifications = $this->backend->select()->from('notification', array(
|
|
|
|
'host',
|
|
|
|
'service',
|
|
|
|
'notification_output',
|
|
|
|
'notification_contact',
|
|
|
|
'notification_start_time',
|
2015-01-21 15:50:32 +01:00
|
|
|
'notification_state',
|
|
|
|
'host_display_name',
|
|
|
|
'service_display_name'
|
2015-01-21 15:49:36 +01:00
|
|
|
));
|
2014-08-27 16:36:52 +02:00
|
|
|
|
|
|
|
$notifications->where('contact_object_id', $contact->contact_object_id);
|
|
|
|
|
|
|
|
$this->view->compact = true;
|
|
|
|
$this->view->notifications = $notifications->paginate();
|
2014-08-27 16:13:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$this->view->contact = $contact;
|
|
|
|
$this->view->contactName = $contactName;
|
2014-07-18 11:48:26 +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;
|
|
|
|
}
|
2014-09-24 07:37:14 +02:00
|
|
|
if ($object->getType() === $object::TYPE_HOST) {
|
2015-02-23 16:56:49 +01:00
|
|
|
$isService = false;
|
2014-09-24 07:37:14 +02:00
|
|
|
$params = array(
|
2015-04-08 16:25:29 +02:00
|
|
|
'host_name' => $object->getName()
|
2014-09-24 07:37:14 +02:00
|
|
|
);
|
|
|
|
} else {
|
2015-02-23 16:56:49 +01:00
|
|
|
$isService = true;
|
2014-09-24 07:37:14 +02:00
|
|
|
$params = array(
|
2015-04-08 16:49:52 +02:00
|
|
|
'host_name' => $object->getHost()->getName(),
|
|
|
|
'service_description' => $object->getName()
|
2014-09-24 07:37:14 +02:00
|
|
|
);
|
2013-06-27 10:14:41 +02:00
|
|
|
}
|
2014-09-24 07:37:14 +02:00
|
|
|
$tabs = $this->getTabs();
|
2014-03-08 01:00:21 +01:00
|
|
|
$tabs->add(
|
|
|
|
'host',
|
|
|
|
array(
|
2015-02-23 16:56:49 +01:00
|
|
|
'title' => sprintf(
|
|
|
|
$this->translate('Show detailed information for host %s'),
|
|
|
|
$isService ? $object->getHost()->getName() : $object->getName()
|
|
|
|
),
|
|
|
|
'label' => $this->translate('Host'),
|
2014-11-13 20:08:58 +01:00
|
|
|
'icon' => 'host',
|
2015-04-08 16:25:29 +02:00
|
|
|
'url' => 'monitoring/host/show',
|
2014-03-08 01:00:21 +01:00
|
|
|
'urlParams' => $params,
|
|
|
|
)
|
|
|
|
);
|
2015-02-23 16:56:49 +01:00
|
|
|
if ($isService) {
|
2013-10-10 11:54:51 +02:00
|
|
|
$tabs->add(
|
|
|
|
'service',
|
|
|
|
array(
|
2015-02-23 16:56:49 +01:00
|
|
|
'title' => sprintf(
|
|
|
|
$this->translate('Show detailed information for service %s on host %s'),
|
|
|
|
$object->getName(),
|
|
|
|
$object->getHost()->getName()
|
|
|
|
),
|
|
|
|
'label' => $this->translate('Service'),
|
2014-11-17 17:02:01 +01:00
|
|
|
'icon' => 'service',
|
2015-04-08 16:49:52 +02:00
|
|
|
'url' => 'monitoring/service/show',
|
2013-10-10 11:54:51 +02:00
|
|
|
'urlParams' => $params,
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
$tabs->add(
|
|
|
|
'services',
|
|
|
|
array(
|
2015-02-23 16:56:49 +01:00
|
|
|
'title' => sprintf(
|
|
|
|
$this->translate('List all services on host %s'),
|
|
|
|
$isService ? $object->getHost()->getName() : $object->getName()
|
|
|
|
),
|
|
|
|
'label' => $this->translate('Services'),
|
2014-11-17 17:02:01 +01:00
|
|
|
'icon' => 'services',
|
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
|
|
|
)
|
|
|
|
);
|
2014-11-16 18:43:36 +01:00
|
|
|
if ($this->backend->hasQuery('eventHistory')) {
|
|
|
|
$tabs->add(
|
|
|
|
'history',
|
|
|
|
array(
|
2015-02-23 16:56:49 +01:00
|
|
|
'title' => $isService
|
|
|
|
? sprintf(
|
|
|
|
$this->translate('Show all event records of service %s on host %s'),
|
|
|
|
$object->getName(),
|
|
|
|
$object->getHost()->getName()
|
|
|
|
)
|
|
|
|
: sprintf($this->translate('Show all event records of host %s'), $object->getName())
|
|
|
|
,
|
|
|
|
'label' => $this->translate('History'),
|
2014-11-16 18:43:36 +01:00
|
|
|
'icon' => 'rewind',
|
|
|
|
'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
|
|
|
}
|
|
|
|
}
|