2013-10-10 14:40:13 +02:00
|
|
|
<?php
|
|
|
|
// {{{ICINGA_LICENSE_HEADER}}}
|
|
|
|
// {{{ICINGA_LICENSE_HEADER}}}
|
|
|
|
|
|
|
|
namespace Icinga\Module\Monitoring;
|
|
|
|
|
|
|
|
use Icinga\Application\Config as IcingaConfig;
|
2013-10-14 14:08:20 +02:00
|
|
|
use Icinga\Module\Monitoring\DataView\ServiceStatus as ServiceStatusView;
|
2013-10-10 14:40:13 +02:00
|
|
|
use Icinga\Web\Controller\ActionController;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Base class for all monitoring action controller
|
|
|
|
*/
|
|
|
|
class Controller extends ActionController
|
|
|
|
{
|
2013-10-17 19:48:46 +02:00
|
|
|
|
2013-10-10 14:40:13 +02:00
|
|
|
/**
|
|
|
|
* Retrieve services from either given parameters or request
|
|
|
|
*
|
|
|
|
* @param array $params
|
|
|
|
*
|
|
|
|
* @return \Zend_Paginator
|
|
|
|
*/
|
|
|
|
protected function fetchServices(array $params = null)
|
|
|
|
{
|
|
|
|
$columns = array(
|
|
|
|
'host_name',
|
|
|
|
'host_state',
|
|
|
|
'host_state_type',
|
|
|
|
'host_last_state_change',
|
|
|
|
'host_address',
|
|
|
|
'host_handled',
|
|
|
|
'service_description',
|
|
|
|
'service_display_name',
|
|
|
|
'service_state',
|
|
|
|
'service_in_downtime',
|
|
|
|
'service_acknowledged',
|
|
|
|
'service_handled',
|
|
|
|
'service_output',
|
2013-10-19 20:09:17 +02:00
|
|
|
'service_attempt',
|
2013-10-10 14:40:13 +02:00
|
|
|
'service_last_state_change',
|
|
|
|
'service_icon_image',
|
|
|
|
'service_long_output',
|
|
|
|
'service_is_flapping',
|
|
|
|
'service_state_type',
|
|
|
|
'service_handled',
|
|
|
|
'service_severity',
|
|
|
|
'service_last_check',
|
|
|
|
'service_notifications_enabled',
|
|
|
|
'service_action_url',
|
|
|
|
'service_notes_url',
|
|
|
|
'service_last_comment',
|
|
|
|
'service_active_checks_enabled',
|
2013-10-14 13:36:59 +02:00
|
|
|
'service_passive_checks_enabled',
|
|
|
|
'current_check_attempt' => 'service_current_check_attempt',
|
|
|
|
'max_check_attempts' => 'service_max_check_attempts'
|
2013-10-10 14:40:13 +02:00
|
|
|
);
|
|
|
|
if ($params === null) {
|
2013-10-14 14:08:20 +02:00
|
|
|
$query = ServiceStatusView::fromRequest(
|
2013-10-10 14:40:13 +02:00
|
|
|
$this->_request,
|
|
|
|
$columns
|
|
|
|
)->getQuery();
|
|
|
|
} else {
|
|
|
|
$params['backend'] = $this->_request->getParam('backend');
|
2013-10-14 14:08:20 +02:00
|
|
|
$query = ServiceStatusView::fromParams(
|
2013-10-10 14:40:13 +02:00
|
|
|
$params,
|
|
|
|
$columns
|
|
|
|
)->getQuery();
|
|
|
|
}
|
|
|
|
$this->handleFormatRequest($query);
|
|
|
|
return $query->paginate();
|
|
|
|
}
|
|
|
|
|
2013-10-22 15:57:30 +02:00
|
|
|
protected function handleFormatRequest($query)
|
2013-10-10 14:40:13 +02:00
|
|
|
{
|
2013-10-22 15:57:30 +02:00
|
|
|
if ($this->compactView !== null && ($this->_getParam('view', false) === 'compact')) {
|
|
|
|
$this->_helper->viewRenderer($this->compactView);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-10-10 14:40:13 +02:00
|
|
|
if ($this->_getParam('format') === 'sql'
|
|
|
|
&& IcingaConfig::app()->global->get('environment', 'production') === 'development') {
|
|
|
|
echo '<pre>'
|
|
|
|
. htmlspecialchars(wordwrap($query->dump()))
|
|
|
|
. '</pre>';
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
if ($this->_getParam('format') === 'json'
|
2013-10-17 21:40:02 +02:00
|
|
|
|| $this->_request->getHeader('Accept') === 'application/json') {
|
2013-10-10 14:40:13 +02:00
|
|
|
header('Content-type: application/json');
|
|
|
|
echo json_encode($query->fetchAll());
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
if ($this->_getParam('format') === 'csv'
|
|
|
|
|| $this->_request->getHeader('Accept') === 'text/csv') {
|
|
|
|
Csv::fromQuery($query)->dump();
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// @codingStandardsIgnoreEnd
|