Merge branch 'master' into feature/user-and-group-management-8826
This commit is contained in:
commit
265725447d
|
@ -3,6 +3,8 @@
|
|||
|
||||
use Icinga\Application\Icinga;
|
||||
use Icinga\Application\Logger;
|
||||
use Icinga\Exception\Http\HttpMethodNotAllowedException;
|
||||
use Icinga\Exception\Http\HttpNotFoundException;
|
||||
use Icinga\Exception\MissingParameterException;
|
||||
use Icinga\Security\SecurityException;
|
||||
use Icinga\Web\Controller\ActionController;
|
||||
|
@ -34,11 +36,7 @@ class ErrorController extends ActionController
|
|||
$path = preg_split('~/~', $path);
|
||||
$path = array_shift($path);
|
||||
$this->getResponse()->setHttpResponseCode(404);
|
||||
$title = preg_replace('/\r?\n.*$/s', '', $exception->getMessage());
|
||||
$this->view->title = 'Server error: ' . $title;
|
||||
if ($this->getInvokeArg('displayExceptions')) {
|
||||
$this->view->stackTrace = $exception->getTraceAsString();
|
||||
}
|
||||
$this->view->message = $this->translate('Page not found.');
|
||||
if ($modules->hasInstalled($path) && ! $modules->hasEnabled($path)) {
|
||||
$this->view->message .= ' ' . sprintf(
|
||||
$this->translate('Enabling the "%s" module might help!'),
|
||||
|
@ -49,8 +47,12 @@ class ErrorController extends ActionController
|
|||
break;
|
||||
default:
|
||||
switch (true) {
|
||||
case $exception instanceof SecurityException:
|
||||
$this->getResponse()->setHttpResponseCode(403);
|
||||
case $exception instanceof HttpMethodNotAllowedException:
|
||||
$this->getResponse()->setHttpResponseCode(405);
|
||||
$this->getResponse()->setHeader('Allow', $exception->getAllowedMethods());
|
||||
break;
|
||||
case $exception instanceof HttpNotFoundException:
|
||||
$this->getResponse()->setHttpResponseCode(404);
|
||||
break;
|
||||
case $exception instanceof MissingParameterException:
|
||||
$this->getResponse()->setHttpResponseCode(400);
|
||||
|
@ -59,12 +61,13 @@ class ErrorController extends ActionController
|
|||
'Missing parameter ' . $exception->getParameter()
|
||||
);
|
||||
break;
|
||||
case $exception instanceof SecurityException:
|
||||
$this->getResponse()->setHttpResponseCode(403);
|
||||
break;
|
||||
default:
|
||||
$this->getResponse()->setHttpResponseCode(500);
|
||||
break;
|
||||
}
|
||||
$title = preg_replace('/\r?\n.*$/s', '', $exception->getMessage());
|
||||
$this->view->title = 'Server error: ' . $title;
|
||||
$this->view->message = $exception->getMessage();
|
||||
if ($this->getInvokeArg('displayExceptions')) {
|
||||
$this->view->stackTrace = $exception->getTraceAsString();
|
||||
|
|
|
@ -1,13 +1,8 @@
|
|||
<div class="controls">
|
||||
<?= $this->tabs->showOnlyCloseButton() ?>
|
||||
<?php if ($this->title): ?>
|
||||
<h1><?= $this->escape($title) ?></h1>
|
||||
<?php endif ?>
|
||||
</div>
|
||||
<div class="content">
|
||||
<?php if ($this->message): ?>
|
||||
<p><strong><?= nl2br($this->escape($message)) ?></strong></p>
|
||||
<?php endif ?>
|
||||
<?php if (isset($stackTrace)) : ?>
|
||||
<hr />
|
||||
<pre><?= $this->escape($stackTrace) ?></pre>
|
||||
|
|
|
@ -621,7 +621,7 @@ class Module
|
|||
*
|
||||
* @return Config
|
||||
*/
|
||||
public function getConfig($file = null)
|
||||
public function getConfig($file = 'config')
|
||||
{
|
||||
return $this->app->getConfig()->module($this->name, $file);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
<?php
|
||||
|
||||
namespace Icinga\Exception\Http;
|
||||
|
||||
use Icinga\Exception\IcingaException;
|
||||
|
||||
/**
|
||||
* Base class for HTTP exceptions
|
||||
*/
|
||||
abstract class HttpException extends IcingaException
|
||||
{
|
||||
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
<?php
|
||||
|
||||
namespace Icinga\Exception\Http;
|
||||
|
||||
/**
|
||||
* Exception thrown if the HTTP method is not allowed
|
||||
*/
|
||||
class HttpMethodNotAllowedException extends HttpException
|
||||
{
|
||||
/**
|
||||
* Allowed HTTP methods
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $allowedMethods;
|
||||
|
||||
/**
|
||||
* Get the allowed HTTP methods
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getAllowedMethods()
|
||||
{
|
||||
return $this->allowedMethods;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the allowed HTTP methods
|
||||
*
|
||||
* @param string $allowedMethods
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setAllowedMethods($allowedMethods)
|
||||
{
|
||||
$this->allowedMethods = (string) $allowedMethods;
|
||||
return $this;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
<?php
|
||||
|
||||
namespace Icinga\Exception\Http;
|
||||
|
||||
/**
|
||||
* Exception thrown for sending a HTTP 404 response w/ a custom message
|
||||
*/
|
||||
class HttpNotFoundException extends HttpException
|
||||
{
|
||||
|
||||
}
|
|
@ -3,9 +3,9 @@
|
|||
|
||||
namespace Icinga\Web;
|
||||
|
||||
use Zend_Controller_Action_Exception;
|
||||
use Icinga\Data\Sortable;
|
||||
use Icinga\Data\QueryInterface;
|
||||
use Icinga\Exception\Http\HttpNotFoundException;
|
||||
use Icinga\Web\Controller\ModuleActionController;
|
||||
use Icinga\Web\Widget\Limiter;
|
||||
use Icinga\Web\Widget\Paginator;
|
||||
|
@ -55,11 +55,11 @@ class Controller extends ModuleActionController
|
|||
*
|
||||
* @param $message
|
||||
*
|
||||
* @throws Zend_Controller_Action_Exception
|
||||
* @throws HttpNotFoundException
|
||||
*/
|
||||
public function httpNotFound($message)
|
||||
{
|
||||
throw new Zend_Controller_Action_Exception($message, 404);
|
||||
throw new HttpNotFoundException($message);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -7,6 +7,7 @@ use Exception;
|
|||
use Icinga\Application\Benchmark;
|
||||
use Icinga\Application\Config;
|
||||
use Icinga\Authentication\Manager;
|
||||
use Icinga\Exception\Http\HttpMethodNotAllowedException;
|
||||
use Icinga\Exception\IcingaException;
|
||||
use Icinga\Exception\ProgrammingError;
|
||||
use Icinga\File\Pdf;
|
||||
|
@ -192,16 +193,17 @@ class ActionController extends Zend_Controller_Action
|
|||
/**
|
||||
* Respond with HTTP 405 if the current request's method is not one of the given methods
|
||||
*
|
||||
* @param string $httpMethod Unlimited number of allowed HTTP methods
|
||||
* @param string $httpMethod Unlimited number of allowed HTTP methods
|
||||
*
|
||||
* @throws \Zend_Controller_Action_Exception If the request method is not one of the given methods
|
||||
* @throws HttpMethodNotAllowedException If the request method is not one of the given methods
|
||||
*/
|
||||
public function assertHttpMethod($httpMethod)
|
||||
{
|
||||
$httpMethods = array_flip(array_map('strtoupper', func_get_args()));
|
||||
if (! isset($httpMethods[$this->getRequest()->getMethod()])) {
|
||||
$this->getResponse()->setHeader('Allow', implode(', ', array_keys($httpMethods)));
|
||||
throw new \Zend_Controller_Action_Exception($this->translate('Method Not Allowed'), 405);
|
||||
$e = new HttpMethodNotAllowedException($this->translate('Method Not Allowed'));
|
||||
$e->setAllowedMethods(implode(', ', array_keys($httpMethods)));
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@ use Icinga\Data\Filter\FilterOr;
|
|||
use Icinga\Web\Url;
|
||||
use Icinga\Application\Icinga;
|
||||
use Icinga\Exception\ProgrammingError;
|
||||
use Icinga\Web\Notification;
|
||||
use Exception;
|
||||
|
||||
/**
|
||||
|
@ -215,31 +216,10 @@ class FilterEditor extends AbstractWidget
|
|||
$filter = $this->getFilter();
|
||||
|
||||
if ($search !== null) {
|
||||
if ($this->searchColumns === null) {
|
||||
if (empty($this->searchColumns)) {
|
||||
if (strpos($search, '=') === false) {
|
||||
// TODO: Ask the view for (multiple) search columns
|
||||
switch($request->getActionName()) {
|
||||
case 'services':
|
||||
$searchCol = 'service';
|
||||
break;
|
||||
case 'hosts':
|
||||
$searchCol = 'host';
|
||||
break;
|
||||
case 'hostgroups':
|
||||
$searchCol = 'hostgroup';
|
||||
break;
|
||||
case 'servicegroups':
|
||||
$searchCol = 'servicegroup';
|
||||
break;
|
||||
default:
|
||||
$searchCol = null;
|
||||
}
|
||||
|
||||
if ($searchCol === null) {
|
||||
throw new Exception('Cannot search here');
|
||||
}
|
||||
$search = ltrim($search);
|
||||
$filter = $this->mergeRootExpression($filter, $searchCol, '=', "*$search*");
|
||||
Notification::error(mt('monitoring', 'Cannot search here'));
|
||||
return $this;
|
||||
} else {
|
||||
list($k, $v) = preg_split('/=/', $search);
|
||||
$filter = $this->mergeRootExpression($filter, trim($k), '=', ltrim($v));
|
||||
|
|
|
@ -163,7 +163,7 @@ class Monitoring_ChartController extends Controller
|
|||
public function hostgroupAction()
|
||||
{
|
||||
$query = $this->backend->select()->from(
|
||||
'groupsummary',
|
||||
'hostgroupsummary',
|
||||
array(
|
||||
'hostgroup',
|
||||
'hosts_up',
|
||||
|
@ -194,7 +194,7 @@ class Monitoring_ChartController extends Controller
|
|||
public function servicegroupAction()
|
||||
{
|
||||
$query = $this->backend->select()->from(
|
||||
'groupsummary',
|
||||
'servicegroupsummary',
|
||||
array(
|
||||
'servicegroup',
|
||||
'services_ok',
|
||||
|
|
|
@ -20,13 +20,11 @@ class Monitoring_CommentController extends Controller
|
|||
|
||||
/**
|
||||
* Fetch the first comment with the given id and add tabs
|
||||
*
|
||||
* @throws Zend_Controller_Action_Exception
|
||||
*/
|
||||
public function init()
|
||||
{
|
||||
$commentId = $this->params->get('comment_id');
|
||||
|
||||
$commentId = $this->params->getRequired('comment_id');
|
||||
|
||||
$this->comment = $this->backend->select()->from('comment', array(
|
||||
'id' => 'comment_internal_id',
|
||||
'objecttype' => 'comment_objecttype',
|
||||
|
@ -41,9 +39,9 @@ class Monitoring_CommentController extends Controller
|
|||
'host_display_name',
|
||||
'service_display_name'
|
||||
))->where('comment_internal_id', $commentId)->getQuery()->fetchRow();
|
||||
|
||||
if (false === $this->comment) {
|
||||
throw new Zend_Controller_Action_Exception($this->translate('Comment not found'));
|
||||
|
||||
if ($this->comment === false) {
|
||||
$this->httpNotFound($this->translate('Comment not found'));
|
||||
}
|
||||
|
||||
$this->getTabs()->add(
|
||||
|
@ -88,7 +86,7 @@ class Monitoring_CommentController extends Controller
|
|||
private function createDelCommentForm()
|
||||
{
|
||||
$this->assertPermission('monitoring/command/comment/delete');
|
||||
|
||||
|
||||
$delCommentForm = new DeleteCommentCommandForm();
|
||||
$delCommentForm->setAction(
|
||||
Url::fromPath('monitoring/comment/show')
|
||||
|
|
|
@ -30,13 +30,11 @@ class Monitoring_DowntimeController extends Controller
|
|||
|
||||
/**
|
||||
* Fetch the downtime matching the given id and add tabs
|
||||
*
|
||||
* @throws Zend_Controller_Action_Exception
|
||||
*/
|
||||
public function init()
|
||||
{
|
||||
$downtimeId = $this->params->get('downtime_id');
|
||||
|
||||
$downtimeId = $this->params->getRequired('downtime_id');
|
||||
|
||||
$this->downtime = $this->backend->select()->from('downtime', array(
|
||||
'id' => 'downtime_internal_id',
|
||||
'objecttype' => 'downtime_objecttype',
|
||||
|
@ -60,17 +58,17 @@ class Monitoring_DowntimeController extends Controller
|
|||
'host_display_name',
|
||||
'service_display_name'
|
||||
))->where('downtime_internal_id', $downtimeId)->getQuery()->fetchRow();
|
||||
|
||||
if (false === $this->downtime) {
|
||||
throw new Zend_Controller_Action_Exception($this->translate('Downtime not found'));
|
||||
|
||||
if ($this->downtime === false) {
|
||||
$this->httpNotFound($this->translate('Downtime not found'));
|
||||
}
|
||||
|
||||
|
||||
if (isset($this->downtime->service_description)) {
|
||||
$this->isService = true;
|
||||
} else {
|
||||
$this->isService = false;
|
||||
}
|
||||
|
||||
|
||||
$this->getTabs()
|
||||
->add(
|
||||
'downtime',
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
<?php
|
||||
/* Icinga Web 2 | (c) 2013-2015 Icinga Development Team | GPLv2+ */
|
||||
|
||||
use Icinga\Exception\MissingParameterException;
|
||||
use Icinga\Module\Monitoring\Forms\Command\Object\AcknowledgeProblemCommandForm;
|
||||
use Icinga\Module\Monitoring\Forms\Command\Object\AddCommentCommandForm;
|
||||
use Icinga\Module\Monitoring\Forms\Command\Object\ProcessCheckResultCommandForm;
|
||||
|
@ -22,27 +21,15 @@ class Monitoring_HostController extends MonitoredObjectController
|
|||
|
||||
/**
|
||||
* Fetch the requested host from the monitoring backend
|
||||
*
|
||||
* @throws Zend_Controller_Action_Exception If the host was not found
|
||||
*/
|
||||
public function init()
|
||||
{
|
||||
if ($this->params->get('host') === null) {
|
||||
throw new MissingParameterException(
|
||||
$this->translate('Required parameter \'%s\' is missing'),
|
||||
'host'
|
||||
);
|
||||
}
|
||||
|
||||
$host = new Host($this->backend, $this->params->get('host'));
|
||||
$host = new Host($this->backend, $this->params->getRequired('host'));
|
||||
|
||||
$this->applyRestriction('monitoring/hosts/filter', $host);
|
||||
|
||||
if ($host->fetch() === false) {
|
||||
throw new Zend_Controller_Action_Exception(
|
||||
sprintf($this->translate('Host \'%s\' not found'), $this->params->get('host')),
|
||||
404
|
||||
);
|
||||
$this->httpNotFound($this->translate('Host not found'));
|
||||
}
|
||||
$this->object = $host;
|
||||
$this->createTabs();
|
||||
|
|
|
@ -53,6 +53,8 @@ class Monitoring_HostsController extends Controller
|
|||
protected function handleCommandForm(ObjectsCommandForm $form)
|
||||
{
|
||||
$this->hostList->setColumns(array(
|
||||
'host_icon_image',
|
||||
'host_icon_image_alt',
|
||||
'host_name',
|
||||
'host_state',
|
||||
'host_problem',
|
||||
|
@ -94,6 +96,8 @@ class Monitoring_HostsController extends Controller
|
|||
->handleRequest();
|
||||
$this->view->checkNowForm = $checkNowForm;
|
||||
$this->hostList->setColumns(array(
|
||||
'host_icon_image',
|
||||
'host_icon_image_alt',
|
||||
'host_name',
|
||||
'host_state',
|
||||
'host_problem',
|
||||
|
|
|
@ -12,6 +12,7 @@ use Icinga\Web\Widget\Tabs;
|
|||
use Icinga\Data\Filter\Filter;
|
||||
use Icinga\Web\Widget;
|
||||
use Icinga\Module\Monitoring\Forms\StatehistoryForm;
|
||||
use Icinga\Module\Monitoring\DataView\DataView;
|
||||
|
||||
class Monitoring_ListController extends Controller
|
||||
{
|
||||
|
@ -70,6 +71,7 @@ class Monitoring_ListController extends Controller
|
|||
$this->setAutorefreshInterval(10);
|
||||
$query = $this->backend->select()->from('hostStatus', array_merge(array(
|
||||
'host_icon_image',
|
||||
'host_icon_image_alt',
|
||||
'host_name',
|
||||
'host_display_name',
|
||||
'host_state' => $stateColumn,
|
||||
|
@ -162,6 +164,7 @@ class Monitoring_ListController extends Controller
|
|||
'service_attempt',
|
||||
'service_last_state_change' => $stateChangeColumn,
|
||||
'service_icon_image',
|
||||
'service_icon_image_alt',
|
||||
'service_is_flapping',
|
||||
'service_state_type',
|
||||
'service_handled',
|
||||
|
@ -468,35 +471,33 @@ class Monitoring_ListController extends Controller
|
|||
);
|
||||
$this->setAutorefreshInterval(12);
|
||||
|
||||
$query = $this->backend->select()->from('groupsummary', array(
|
||||
'servicegroup_name',
|
||||
'servicegroup_alias',
|
||||
'hosts_up',
|
||||
'hosts_unreachable_handled',
|
||||
'hosts_unreachable_unhandled',
|
||||
$query = $this->backend->select()->from('servicegroupsummary', array(
|
||||
'hosts_down_handled',
|
||||
'hosts_down_unhandled',
|
||||
'hosts_pending',
|
||||
'services_ok',
|
||||
'services_unknown_handled',
|
||||
'services_unknown_unhandled',
|
||||
'hosts_unreachable_handled',
|
||||
'hosts_unreachable_unhandled',
|
||||
'hosts_up',
|
||||
'servicegroup_alias',
|
||||
'servicegroup_name',
|
||||
'services_critical_handled',
|
||||
'services_critical_unhandled',
|
||||
'services_warning_handled',
|
||||
'services_warning_unhandled',
|
||||
'services_pending',
|
||||
'services_ok_last_state_change',
|
||||
'services_pending_last_state_change',
|
||||
'services_warning_last_state_change_handled',
|
||||
'services_critical_last_state_change_handled',
|
||||
'services_unknown_last_state_change_handled',
|
||||
'services_warning_last_state_change_unhandled',
|
||||
'services_critical_last_state_change_unhandled',
|
||||
'services_critical_unhandled',
|
||||
'services_ok',
|
||||
'services_ok_last_state_change',
|
||||
'services_pending',
|
||||
'services_pending_last_state_change',
|
||||
'services_total',
|
||||
'services_unknown_handled',
|
||||
'services_unknown_last_state_change_handled',
|
||||
'services_unknown_last_state_change_unhandled',
|
||||
'services_total'
|
||||
))->order('services_severity')->order('servicegroup_alias');
|
||||
// TODO(el): Can't default to the sort rules of the data view because it's meant for both host groups and
|
||||
// service groups. We should separate them.
|
||||
'services_unknown_unhandled',
|
||||
'services_warning_handled',
|
||||
'services_warning_last_state_change_handled',
|
||||
'services_warning_last_state_change_unhandled',
|
||||
'services_warning_unhandled'
|
||||
));
|
||||
$this->filterQuery($query);
|
||||
$this->view->servicegroups = $query;
|
||||
|
||||
|
@ -505,12 +506,7 @@ class Monitoring_ListController extends Controller
|
|||
$this->setupSortControl(array(
|
||||
'services_severity' => $this->translate('Severity'),
|
||||
'servicegroup_alias' => $this->translate('Service Group Name'),
|
||||
'services_total' => $this->translate('Total Services'),
|
||||
'services_ok' => $this->translate('Services OK'),
|
||||
'services_unknown' => $this->translate('Services UNKNOWN'),
|
||||
'services_critical' => $this->translate('Services CRITICAL'),
|
||||
'services_warning' => $this->translate('Services WARNING'),
|
||||
'services_pending' => $this->translate('Services PENDING')
|
||||
'services_total' => $this->translate('Total Services')
|
||||
), $query);
|
||||
}
|
||||
|
||||
|
@ -519,56 +515,42 @@ class Monitoring_ListController extends Controller
|
|||
$this->addTitleTab('hostgroups', $this->translate('Host Groups'), $this->translate('List host groups'));
|
||||
$this->setAutorefreshInterval(12);
|
||||
|
||||
$query = $this->backend->select()->from('groupsummary', array(
|
||||
'hostgroup_name',
|
||||
$query = $this->backend->select()->from('hostgroupsummary', array(
|
||||
'hostgroup_alias',
|
||||
'hosts_up',
|
||||
'hosts_unreachable_handled',
|
||||
'hosts_unreachable_unhandled',
|
||||
'hostgroup_name',
|
||||
'hosts_down_handled',
|
||||
'hosts_down_last_state_change_handled',
|
||||
'hosts_down_last_state_change_unhandled',
|
||||
'hosts_down_unhandled',
|
||||
'hosts_pending',
|
||||
'hosts_up_last_state_change',
|
||||
'hosts_pending_last_state_change',
|
||||
'hosts_down_last_state_change_handled',
|
||||
'hosts_unreachable_last_state_change_handled',
|
||||
'hosts_down_last_state_change_unhandled',
|
||||
'hosts_unreachable_last_state_change_unhandled',
|
||||
'hosts_total',
|
||||
'services_ok',
|
||||
'services_unknown_handled',
|
||||
'services_unknown_unhandled',
|
||||
'hosts_unreachable_handled',
|
||||
'hosts_unreachable_last_state_change_handled',
|
||||
'hosts_unreachable_last_state_change_unhandled',
|
||||
'hosts_unreachable_unhandled',
|
||||
'hosts_up',
|
||||
'hosts_up_last_state_change',
|
||||
'services_critical_handled',
|
||||
'services_critical_unhandled',
|
||||
'services_warning_handled',
|
||||
'services_warning_unhandled',
|
||||
'services_ok',
|
||||
'services_pending',
|
||||
'services_ok_last_state_change',
|
||||
'services_pending_last_state_change',
|
||||
'services_warning_last_state_change_handled',
|
||||
'services_critical_last_state_change_handled',
|
||||
'services_unknown_last_state_change_handled',
|
||||
'services_warning_last_state_change_unhandled',
|
||||
'services_critical_last_state_change_unhandled',
|
||||
'services_unknown_last_state_change_unhandled',
|
||||
'services_total'
|
||||
))->order('services_severity')->order('hostgroup_alias');
|
||||
// TODO(el): Can't default to the sort rules of the data view because it's meant for both host groups and
|
||||
// service groups. We should separate them.
|
||||
'services_total',
|
||||
'services_unknown_handled',
|
||||
'services_unknown_unhandled',
|
||||
'services_warning_handled',
|
||||
'services_warning_unhandled'
|
||||
));
|
||||
$this->filterQuery($query);
|
||||
$this->view->hostgroups = $query;
|
||||
|
||||
$this->setupLimitControl();
|
||||
$this->setupPaginationControl($this->view->hostgroups);
|
||||
$this->setupSortControl(array(
|
||||
'services_severity' => $this->translate('Severity'),
|
||||
'hosts_severity' => $this->translate('Severity'),
|
||||
'hostgroup_alias' => $this->translate('Host Group Name'),
|
||||
'services_total' => $this->translate('Total Services'),
|
||||
'services_ok' => $this->translate('Services OK'),
|
||||
'services_unknown' => $this->translate('Services UNKNOWN'),
|
||||
'services_critical' => $this->translate('Services CRITICAL'),
|
||||
'services_warning' => $this->translate('Services WARNING'),
|
||||
'services_pending' => $this->translate('Services PENDING')
|
||||
'hosts_total' => $this->translate('Total Hosts'),
|
||||
'services_total' => $this->translate('Total Services')
|
||||
), $query);
|
||||
}
|
||||
|
||||
|
@ -626,23 +608,31 @@ class Monitoring_ListController extends Controller
|
|||
$this->view->verticalPaginator = $pivot->paginateYAxis();
|
||||
}
|
||||
|
||||
protected function filterQuery($query)
|
||||
/**
|
||||
* Apply filters on a DataView
|
||||
*
|
||||
* @param DataView $dataView The DataView to apply filters on
|
||||
*
|
||||
* @return DataView $dataView
|
||||
*/
|
||||
protected function filterQuery(DataView $dataView)
|
||||
{
|
||||
$editor = Widget::create('filterEditor')
|
||||
->setQuery($query)
|
||||
->setQuery($dataView)
|
||||
->preserveParams(
|
||||
'limit', 'sort', 'dir', 'format', 'view', 'backend',
|
||||
'stateType', 'addColumns', '_dev'
|
||||
)
|
||||
->ignoreParams('page')
|
||||
->setSearchColumns($dataView->getSearchColumns())
|
||||
->handleRequest($this->getRequest());
|
||||
$query->applyFilter($editor->getFilter());
|
||||
$dataView->applyFilter($editor->getFilter());
|
||||
|
||||
$this->setupFilterControl($editor);
|
||||
$this->view->filter = $editor->getFilter();
|
||||
|
||||
$this->handleFormatRequest($query);
|
||||
return $query;
|
||||
$this->handleFormatRequest($dataView);
|
||||
return $dataView;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
<?php
|
||||
/* Icinga Web 2 | (c) 2013-2015 Icinga Development Team | GPLv2+ */
|
||||
|
||||
use Icinga\Exception\MissingParameterException;
|
||||
use Icinga\Module\Monitoring\Forms\Command\Object\AcknowledgeProblemCommandForm;
|
||||
use Icinga\Module\Monitoring\Forms\Command\Object\AddCommentCommandForm;
|
||||
use Icinga\Module\Monitoring\Forms\Command\Object\ProcessCheckResultCommandForm;
|
||||
|
@ -22,27 +21,17 @@ class Monitoring_ServiceController extends MonitoredObjectController
|
|||
|
||||
/**
|
||||
* Fetch the requested service from the monitoring backend
|
||||
*
|
||||
* @throws Zend_Controller_Action_Exception If the service was not found
|
||||
*/
|
||||
public function init()
|
||||
{
|
||||
if ($this->params->get('host') === null || $this->params->get('service') === null) {
|
||||
throw new MissingParameterException(
|
||||
$this->translate('One of the required parameters \'%s\' is missing'),
|
||||
'host or service'
|
||||
);
|
||||
}
|
||||
|
||||
$service = new Service($this->backend, $this->params->get('host'), $this->params->get('service'));
|
||||
$service = new Service(
|
||||
$this->backend, $this->params->getRequired('host'), $this->params->getRequired('service')
|
||||
);
|
||||
|
||||
$this->applyRestriction('monitoring/services/filter', $service);
|
||||
|
||||
if ($service->fetch() === false) {
|
||||
throw new Zend_Controller_Action_Exception(
|
||||
sprintf($this->translate('Service \'%s\' not found'), $this->params->get('service')),
|
||||
404
|
||||
);
|
||||
$this->httpNotFound($this->translate('Service not found'));
|
||||
}
|
||||
$this->object = $service;
|
||||
$this->createTabs();
|
||||
|
|
|
@ -50,11 +50,15 @@ class Monitoring_ServicesController extends Controller
|
|||
protected function handleCommandForm(ObjectsCommandForm $form)
|
||||
{
|
||||
$this->serviceList->setColumns(array(
|
||||
'host_icon_image',
|
||||
'host_icon_image_alt',
|
||||
'host_name',
|
||||
'host_output',
|
||||
'host_state',
|
||||
'host_problem',
|
||||
'host_handled',
|
||||
'service_icon_image',
|
||||
'service_icon_image_alt',
|
||||
'service_description',
|
||||
'service_state',
|
||||
'service_problem',
|
||||
|
@ -93,11 +97,15 @@ class Monitoring_ServicesController extends Controller
|
|||
->handleRequest();
|
||||
$this->view->checkNowForm = $checkNowForm;
|
||||
$this->serviceList->setColumns(array(
|
||||
'host_icon_image',
|
||||
'host_icon_image_alt',
|
||||
'host_name',
|
||||
'host_output',
|
||||
'host_state',
|
||||
'host_problem',
|
||||
'host_handled',
|
||||
'service_icon_image',
|
||||
'service_icon_image_alt',
|
||||
'service_output',
|
||||
'service_description',
|
||||
'service_state',
|
||||
|
|
|
@ -0,0 +1,62 @@
|
|||
<?php
|
||||
/* Icinga Web 2 | (c) 2013-2015 Icinga Development Team | GPLv2+ */
|
||||
|
||||
/**
|
||||
* Generate icons to describe a given hosts state
|
||||
*/
|
||||
class Zend_View_Helper_IconImage extends Zend_View_Helper_Abstract
|
||||
{
|
||||
/**
|
||||
* Create dispatch instance
|
||||
*
|
||||
* @return \Zend_View_Helper_IconImage
|
||||
*/
|
||||
public function iconImage()
|
||||
{
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the image_icon of a MonitoredObject
|
||||
*
|
||||
* @param MonitoredObject|stdClass $object The host or service
|
||||
* @return string
|
||||
*/
|
||||
public function host($object)
|
||||
{
|
||||
if ($object->host_icon_image && ! preg_match('/[\'"]/', $object->host_icon_image)) {
|
||||
return $this->view->img(
|
||||
'img/icons/' . $this->view->resolveMacros($object->host_icon_image, $object),
|
||||
null,
|
||||
array(
|
||||
'alt' => $object->host_icon_image_alt,
|
||||
'title' => $object->host_icon_image_alt,
|
||||
'data-tooltip-delay' => 0
|
||||
)
|
||||
);
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the image_icon of a MonitoredObject
|
||||
*
|
||||
* @param MonitoredObject|stdClass $object The host or service
|
||||
* @return string
|
||||
*/
|
||||
public function service($object)
|
||||
{
|
||||
if ($object->service_icon_image && ! preg_match('/[\'"]/', $object->service_icon_image)) {
|
||||
return $this->view->img(
|
||||
'img/icons/' . $this->view->resolveMacros($object->service_icon_image, $object),
|
||||
null,
|
||||
array(
|
||||
'alt' => $object->service_icon_image_alt,
|
||||
'title' => $object->service_icon_image_alt,
|
||||
'data-tooltip-delay' => 0
|
||||
)
|
||||
);
|
||||
}
|
||||
return '';
|
||||
}
|
||||
}
|
|
@ -52,9 +52,7 @@ if (count($hosts) === 0) {
|
|||
|
||||
<!-- Host / Status / Output -->
|
||||
<td>
|
||||
<?php if ($host->host_icon_image && ! preg_match('/[\'"]/', $host->host_icon_image)): ?>
|
||||
<?= $this->icon($this->resolveMacros($host->host_icon_image, $host)) ?>
|
||||
<?php endif ?>
|
||||
<?= $this->iconImage()->host($host) ?>
|
||||
<?= implode(' ', $this->hostFlags($host)) ?>
|
||||
<?= $this->qlink(
|
||||
$host->host_display_name,
|
||||
|
@ -75,7 +73,7 @@ if (count($hosts) === 0) {
|
|||
'host' => $host->host_name,
|
||||
'service_problem' => 1,
|
||||
'service_handled' => 0
|
||||
),
|
||||
),
|
||||
array(
|
||||
'style' => 'font-weight: normal',
|
||||
'title' => sprintf(
|
||||
|
|
|
@ -58,12 +58,8 @@ if (count($services) === 0) {
|
|||
|
||||
<td>
|
||||
<div class="sparkline-box"><?= $this->perfdata($service->service_perfdata, true, 8) ?> </div>
|
||||
|
||||
<?= $this->iconImage()->service($service) ?>
|
||||
<?= implode(' ', $this->serviceFlags($service)); ?>
|
||||
|
||||
<?php if ($service->service_icon_image && ! preg_match('/[\'"]/', $service->service_icon_image)): ?>
|
||||
<?= $this->icon($this->resolveMacros($service->service_icon_image, $service)) ?>
|
||||
<?php endif ?>
|
||||
<?= $this->qlink(
|
||||
$service->service_display_name,
|
||||
$serviceLink,
|
||||
|
|
|
@ -1,11 +1,10 @@
|
|||
<?php if ($comment->objecttype === 'service'): ?>
|
||||
<?= $this->icon('service', $this->translate('Service')); ?>
|
||||
<?= $this->link()->service(
|
||||
$comment->service_description,
|
||||
<?= sprintf(
|
||||
$this->translate('%s on %s', 'Service running on host'),
|
||||
$comment->service_display_name,
|
||||
$comment->host_name,
|
||||
$comment->host_display_name
|
||||
); ?>
|
||||
) ?>
|
||||
<?php else: ?>
|
||||
<?= $this->icon('host', $this->translate('Host')); ?>
|
||||
<?= $this->link()->host($comment->host_name, $comment->host_display_name); ?>
|
||||
|
|
|
@ -9,6 +9,7 @@ use Icinga\Module\Monitoring\Object\Host;
|
|||
<?= $this->prefixedTimeSince($object->host_last_state_change, true); ?>
|
||||
</td>
|
||||
<td>
|
||||
<?= $this->iconImage()->host($object) ?>
|
||||
<strong><?= $this->escape($object->host_display_name); ?></strong>
|
||||
<?php if ($object->host_display_name !== $object->host_name): ?>
|
||||
<small>(<?= $this->escape($object->host_name); ?>)</small>
|
||||
|
@ -20,4 +21,4 @@ use Icinga\Module\Monitoring\Object\Host;
|
|||
<?= $this->render('partials/host/statusicons.phtml'); ?>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</table>
|
||||
|
|
|
@ -17,6 +17,7 @@ $i = 0;
|
|||
<tr class="state <?= Host::getStateText($host->host_state); ?><?= $host->host_handled ? ' handled' : '' ?>">
|
||||
<td class="state"><?= Host::getStateText($host->host_state, true); ?><br /></td>
|
||||
<td>
|
||||
<?= $this->iconImage()->host($host) ?>
|
||||
<?= implode(' ', $this->hostFlags($host)) ?>
|
||||
<b><?= $this->escape($host->getName()); ?></b><br>
|
||||
<?= $this->escape($host->host_output) ?>
|
||||
|
|
|
@ -10,7 +10,8 @@ use Icinga\Module\Monitoring\Object\Service;
|
|||
<?= $this->prefixedTimeSince($object->host_last_state_change, true); ?>
|
||||
</td>
|
||||
<td>
|
||||
<strong><?= $this->escape($object->host_display_name); ?></strong>
|
||||
<?= $this->iconImage()->service($object) ?>
|
||||
<strong><?= $this->escape($object->host_display_name); ?></strong>
|
||||
<?php if ($object->host_display_name !== $object->host_name): ?>
|
||||
<small>(<?= $this->escape($object->host_name); ?>)</small>
|
||||
<?php endif ?>
|
||||
|
@ -27,10 +28,11 @@ use Icinga\Module\Monitoring\Object\Service;
|
|||
<?= $this->prefixedTimeSince($object->service_last_state_change, true); ?>
|
||||
</td>
|
||||
<td>
|
||||
<?= $this->iconImage()->host($object) ?>
|
||||
<strong><?= $this->translate('Service'); ?>: <?= $this->escape($object->service_display_name); ?></strong>
|
||||
<?php if ($object->service_display_name !== $object->service_description): ?>
|
||||
<small>(<?= $this->escape($object->service_description); ?>)</small>
|
||||
<?php endif ?>
|
||||
<?php if ($object->service_display_name !== $object->service_description): ?>
|
||||
<small>(<?= $this->escape($object->service_description); ?>)</small>
|
||||
<?php endif ?>
|
||||
<?= $this->render('partials/service/statusicons.phtml'); ?>
|
||||
</td>
|
||||
</tr>
|
||||
|
|
|
@ -15,6 +15,7 @@ $i = 0;
|
|||
<tr class="state <?= Service::getStateText($service->service_state); ?><?= $service->service_handled ? ' handled' : '' ?>">
|
||||
<td class="state"><?= Service::getStateText($service->service_state, true); ?><br /></td>
|
||||
<td>
|
||||
<?= $this->iconImage()->service($service) ?>
|
||||
<?= implode(' ', $this->serviceFlags($service)) ?>
|
||||
<b>
|
||||
<?= $this->escape($service->getName()); ?>
|
||||
|
|
|
@ -5,59 +5,72 @@ namespace Icinga\Module\Monitoring\Backend\Ido\Query;
|
|||
|
||||
use Zend_Db_Select;
|
||||
|
||||
/**
|
||||
* Query for host and service group summaries
|
||||
*/
|
||||
class GroupSummaryQuery extends IdoQuery
|
||||
{
|
||||
protected $useSubqueryCount = true;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected $columnMap = array(
|
||||
'hoststatussummary' => array(
|
||||
'hosts_total' => 'SUM(CASE WHEN object_type = \'host\' THEN 1 ELSE 0 END)',
|
||||
'hostgroup' => 'hostgroup COLLATE latin1_general_ci',
|
||||
'hostgroup_alias' => 'hostgroup_alias COLLATE latin1_general_ci',
|
||||
'hostgroup_name' => 'hostgroup_name',
|
||||
'hosts_up' => 'SUM(CASE WHEN object_type = \'host\' AND state = 0 THEN 1 ELSE 0 END)',
|
||||
'hosts_unreachable' => 'SUM(CASE WHEN object_type = \'host\' AND state = 2 THEN 1 ELSE 0 END)',
|
||||
'hosts_unreachable_handled' => 'SUM(CASE WHEN object_type = \'host\' AND state = 2 AND acknowledged + in_downtime != 0 THEN 1 ELSE 0 END)',
|
||||
'hosts_unreachable_unhandled' => 'SUM(CASE WHEN object_type = \'host\' AND state = 2 AND acknowledged + in_downtime = 0 THEN 1 ELSE 0 END)',
|
||||
'hosts_down' => 'SUM(CASE WHEN object_type = \'host\' AND state = 1 THEN 1 ELSE 0 END)',
|
||||
'hosts_down_handled' => 'SUM(CASE WHEN object_type = \'host\' AND state = 1 AND acknowledged + in_downtime != 0 THEN 1 ELSE 0 END)',
|
||||
'hosts_down_last_state_change_handled' => 'MAX(CASE WHEN object_type = \'host\' AND state = 1 AND acknowledged + in_downtime != 0 THEN state_change ELSE 0 END)',
|
||||
'hosts_down_last_state_change_unhandled' => 'MAX(CASE WHEN object_type = \'host\' AND state = 1 AND acknowledged + in_downtime = 0 THEN state_change ELSE 0 END)',
|
||||
'hosts_down_unhandled' => 'SUM(CASE WHEN object_type = \'host\' AND state = 1 AND acknowledged + in_downtime = 0 THEN 1 ELSE 0 END)',
|
||||
'hosts_pending' => 'SUM(CASE WHEN object_type = \'host\' AND state = 99 THEN 1 ELSE 0 END)',
|
||||
'hosts_up_last_state_change' => 'MAX(CASE WHEN object_type = \'host\' AND state = 0 THEN state_change ELSE 0 END)',
|
||||
'hosts_pending_last_state_change' => 'MAX(CASE WHEN object_type = \'host\' AND state = 99 THEN state_change ELSE 0 END)',
|
||||
'hosts_down_last_state_change_handled' => 'MAX(CASE WHEN object_type = \'host\' AND state = 1 AND acknowledged + in_downtime != 0 THEN state_change ELSE 0 END)',
|
||||
'hosts_severity' => 'MAX(CASE WHEN object_type = \'host\' THEN severity ELSE 0 END)',
|
||||
'hosts_total' => 'SUM(CASE WHEN object_type = \'host\' THEN 1 ELSE 0 END)',
|
||||
'hosts_unreachable_last_state_change_handled' => 'MAX(CASE WHEN object_type = \'host\' AND state = 2 AND acknowledged + in_downtime != 0 THEN state_change ELSE 0 END)',
|
||||
'hosts_down_last_state_change_unhandled' => 'MAX(CASE WHEN object_type = \'host\' AND state = 1 AND acknowledged + in_downtime = 0 THEN state_change ELSE 0 END)',
|
||||
'hosts_unreachable_last_state_change_unhandled' => 'MAX(CASE WHEN object_type = \'host\' AND state = 2 AND acknowledged + in_downtime = 0 THEN state_change ELSE 0 END)',
|
||||
'hostgroup_name' => 'hostgroup_name',
|
||||
'hostgroup_alias' => 'hostgroup_alias',
|
||||
'hostgroup' => 'hostgroup'
|
||||
'hosts_up_last_state_change' => 'MAX(CASE WHEN object_type = \'host\' AND state = 0 THEN state_change ELSE 0 END)'
|
||||
),
|
||||
'servicestatussummary' => array(
|
||||
'services_total' => 'SUM(CASE WHEN object_type = \'service\' THEN 1 ELSE 0 END)',
|
||||
'services_ok' => 'SUM(CASE WHEN object_type = \'service\' AND state = 0 THEN 1 ELSE 0 END)',
|
||||
'services_pending' => 'SUM(CASE WHEN object_type = \'service\' AND state = 99 THEN 1 ELSE 0 END)',
|
||||
'services_warning' => 'SUM(CASE WHEN object_type = \'service\' AND state = 1 THEN 1 ELSE 0 END)',
|
||||
'services_warning_handled' => 'SUM(CASE WHEN object_type = \'service\' AND state = 1 AND acknowledged + in_downtime + host_state > 0 THEN 1 ELSE 0 END)',
|
||||
'servicegroup' => 'servicegroup COLLATE latin1_general_ci',
|
||||
'servicegroup_alias' => 'servicegroup_alias COLLATE latin1_general_ci',
|
||||
'servicegroup_name' => 'servicegroup_name',
|
||||
'services_critical' => 'SUM(CASE WHEN object_type = \'service\' AND state = 2 THEN 1 ELSE 0 END)',
|
||||
'services_critical_handled' => 'SUM(CASE WHEN object_type = \'service\' AND state = 2 AND acknowledged + in_downtime + host_state > 0 THEN 1 ELSE 0 END)',
|
||||
'services_critical_last_state_change_handled' => 'MAX(CASE WHEN object_type = \'service\' AND state = 2 AND acknowledged + in_downtime + host_state > 0 THEN state_change ELSE 0 END)',
|
||||
'services_critical_last_state_change_unhandled' => 'MAX(CASE WHEN object_type = \'service\' AND state = 2 AND acknowledged + in_downtime + host_state = 0 THEN state_change ELSE 0 END)',
|
||||
'services_critical_unhandled' => 'SUM(CASE WHEN object_type = \'service\' AND state = 2 AND acknowledged + in_downtime + host_state = 0 THEN 1 ELSE 0 END)',
|
||||
'services_ok' => 'SUM(CASE WHEN object_type = \'service\' AND state = 0 THEN 1 ELSE 0 END)',
|
||||
'services_ok_last_state_change' => 'MAX(CASE WHEN object_type = \'service\' AND state = 0 THEN state_change ELSE 0 END)',
|
||||
'services_pending' => 'SUM(CASE WHEN object_type = \'service\' AND state = 99 THEN 1 ELSE 0 END)',
|
||||
'services_pending_last_state_change' => 'MAX(CASE WHEN object_type = \'service\' AND state = 99 THEN state_change ELSE 0 END)',
|
||||
'services_severity' => 'MAX(CASE WHEN object_type = \'service\' THEN severity ELSE 0 END)',
|
||||
'services_total' => 'SUM(CASE WHEN object_type = \'service\' THEN 1 ELSE 0 END)',
|
||||
'services_unknown' => 'SUM(CASE WHEN object_type = \'service\' AND state = 3 THEN 1 ELSE 0 END)',
|
||||
'services_unknown_handled' => 'SUM(CASE WHEN object_type = \'service\' AND state = 3 AND acknowledged + in_downtime + host_state > 0 THEN 1 ELSE 0 END)',
|
||||
'services_warning_unhandled' => 'SUM(CASE WHEN object_type = \'service\' AND state = 1 AND acknowledged + in_downtime + host_state = 0 THEN 1 ELSE 0 END)',
|
||||
'services_critical_unhandled' => 'SUM(CASE WHEN object_type = \'service\' AND state = 2 AND acknowledged + in_downtime + host_state = 0 THEN 1 ELSE 0 END)',
|
||||
'services_unknown_unhandled' => 'SUM(CASE WHEN object_type = \'service\' AND state = 3 AND acknowledged + in_downtime + host_state = 0 THEN 1 ELSE 0 END)',
|
||||
'services_severity' => 'MAX(CASE WHEN object_type = \'service\' THEN severity ELSE 0 END)',
|
||||
'services_ok_last_state_change' => 'MAX(CASE WHEN object_type = \'service\' AND state = 0 THEN state_change ELSE 0 END)',
|
||||
'services_pending_last_state_change' => 'MAX(CASE WHEN object_type = \'service\' AND state = 99 THEN state_change ELSE 0 END)',
|
||||
'services_warning_last_state_change_handled' => 'MAX(CASE WHEN object_type = \'service\' AND state = 1 AND acknowledged + in_downtime + host_state > 0 THEN state_change ELSE 0 END)',
|
||||
'services_critical_last_state_change_handled' => 'MAX(CASE WHEN object_type = \'service\' AND state = 2 AND acknowledged + in_downtime + host_state > 0 THEN state_change ELSE 0 END)',
|
||||
'services_unknown_last_state_change_handled' => 'MAX(CASE WHEN object_type = \'service\' AND state = 3 AND acknowledged + in_downtime + host_state > 0 THEN state_change ELSE 0 END)',
|
||||
'services_warning_last_state_change_unhandled' => 'MAX(CASE WHEN object_type = \'service\' AND state = 1 AND acknowledged + in_downtime + host_state = 0 THEN state_change ELSE 0 END)',
|
||||
'services_critical_last_state_change_unhandled' => 'MAX(CASE WHEN object_type = \'service\' AND state = 2 AND acknowledged + in_downtime + host_state = 0 THEN state_change ELSE 0 END)',
|
||||
'services_unknown_last_state_change_unhandled' => 'MAX(CASE WHEN object_type = \'service\' AND state = 3 AND acknowledged + in_downtime + host_state = 0 THEN state_change ELSE 0 END)',
|
||||
'servicegroup_name' => 'servicegroup_name',
|
||||
'servicegroup_alias' => 'servicegroup_alias',
|
||||
'servicegroup' => 'servicegroup'
|
||||
'services_unknown_unhandled' => 'SUM(CASE WHEN object_type = \'service\' AND state = 3 AND acknowledged + in_downtime + host_state = 0 THEN 1 ELSE 0 END)',
|
||||
'services_warning' => 'SUM(CASE WHEN object_type = \'service\' AND state = 1 THEN 1 ELSE 0 END)',
|
||||
'services_warning_handled' => 'SUM(CASE WHEN object_type = \'service\' AND state = 1 AND acknowledged + in_downtime + host_state > 0 THEN 1 ELSE 0 END)',
|
||||
'services_warning_last_state_change_handled' => 'MAX(CASE WHEN object_type = \'service\' AND state = 1 AND acknowledged + in_downtime + host_state > 0 THEN state_change ELSE 0 END)',
|
||||
'services_warning_last_state_change_unhandled' => 'MAX(CASE WHEN object_type = \'service\' AND state = 1 AND acknowledged + in_downtime + host_state = 0 THEN state_change ELSE 0 END)',
|
||||
'services_warning_unhandled' => 'SUM(CASE WHEN object_type = \'service\' AND state = 1 AND acknowledged + in_downtime + host_state = 0 THEN 1 ELSE 0 END)'
|
||||
)
|
||||
);
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected $useSubqueryCount = true;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function joinBaseTables()
|
||||
{
|
||||
$columns = array(
|
||||
|
@ -79,11 +92,11 @@ class GroupSummaryQuery extends IdoQuery
|
|||
$hosts = $this->createSubQuery(
|
||||
'Hoststatus',
|
||||
$columns + array(
|
||||
'state' => 'host_state',
|
||||
'acknowledged' => 'host_acknowledged',
|
||||
'in_downtime' => 'host_in_downtime',
|
||||
'state_change' => 'host_last_state_change',
|
||||
'severity' => 'host_severity'
|
||||
'state' => 'host_state',
|
||||
'acknowledged' => 'host_acknowledged',
|
||||
'in_downtime' => 'host_in_downtime',
|
||||
'state_change' => 'host_last_state_change',
|
||||
'severity' => 'host_severity'
|
||||
)
|
||||
);
|
||||
if (in_array('servicegroup_name', $this->desiredColumns)) {
|
||||
|
@ -101,11 +114,11 @@ class GroupSummaryQuery extends IdoQuery
|
|||
$services = $this->createSubQuery(
|
||||
'Status',
|
||||
$columns + array(
|
||||
'state' => 'service_state',
|
||||
'acknowledged' => 'service_acknowledged',
|
||||
'in_downtime' => 'service_in_downtime',
|
||||
'state_change' => 'service_last_state_change',
|
||||
'severity' => 'service_severity'
|
||||
'state' => 'service_state',
|
||||
'acknowledged' => 'service_acknowledged',
|
||||
'in_downtime' => 'service_in_downtime',
|
||||
'state_change' => 'service_last_state_change',
|
||||
'severity' => 'service_severity'
|
||||
)
|
||||
);
|
||||
$union = $this->db->select()->union(array($hosts, $services), Zend_Db_Select::SQL_UNION_ALL);
|
||||
|
|
|
@ -11,7 +11,7 @@ class HoststatusQuery extends IdoQuery
|
|||
'hosts' => array(
|
||||
'host' => 'ho.name1 COLLATE latin1_general_ci',
|
||||
'host_name' => 'ho.name1 COLLATE latin1_general_ci',
|
||||
'host_display_name' => 'h.display_name',
|
||||
'host_display_name' => 'h.display_name COLLATE latin1_general_ci',
|
||||
'host_alias' => 'h.alias',
|
||||
'host_address' => 'h.address',
|
||||
'host_ipv4' => 'INET_ATON(h.address)',
|
||||
|
@ -85,7 +85,7 @@ class HoststatusQuery extends IdoQuery
|
|||
'hostgroups' => array(
|
||||
'hostgroup' => 'hgo.name1 COLLATE latin1_general_ci',
|
||||
'hostgroup_name' => 'hgo.name1',
|
||||
'hostgroup_alias' => 'hg.alias'
|
||||
'hostgroup_alias' => 'hg.alias COLLATE latin1_general_ci'
|
||||
),
|
||||
'servicegroups' => array(
|
||||
'servicegroup' => 'sgo.name1 COLLATE latin1_general_ci',
|
||||
|
|
|
@ -86,6 +86,18 @@ abstract class IdoQuery extends DbQuery
|
|||
*/
|
||||
protected $customVars = array();
|
||||
|
||||
/**
|
||||
* Printf compatible string to joins custom vars
|
||||
*
|
||||
* - %1$s Source field, contain the object_id
|
||||
* - %2$s Alias used for the relation
|
||||
* - %3$s Name of the CustomVariable
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $customVarsJoinTemplate =
|
||||
'%1$s = %2$s.object_id AND %2$s.varname = %3$s COLLATE latin1_general_ci';
|
||||
|
||||
/**
|
||||
* An array with all 'virtual' tables that are already joined
|
||||
*
|
||||
|
@ -351,6 +363,8 @@ abstract class IdoQuery extends DbQuery
|
|||
$this->object_id = $this->host_id = $this->service_id
|
||||
= $this->hostgroup_id = $this->servicegroup_id
|
||||
= $this->contact_id = $this->contactgroup_id = 'id';
|
||||
$this->customVarsJoinTemplate =
|
||||
'%1$s = %2$s.object_id AND LOWER(%2$s.varname) = %3$s';
|
||||
foreach ($this->columnMap as &$columns) {
|
||||
foreach ($columns as &$value) {
|
||||
$value = preg_replace('/UNIX_TIMESTAMP/', 'localts2unixts', $value);
|
||||
|
@ -364,6 +378,8 @@ abstract class IdoQuery extends DbQuery
|
|||
*/
|
||||
private function initializeForPostgres()
|
||||
{
|
||||
$this->customVarsJoinTemplate =
|
||||
'%1$s = %2$s.object_id AND LOWER(%2$s.varname) = %3$s';
|
||||
foreach ($this->columnMap as $table => & $columns) {
|
||||
foreach ($columns as $key => & $value) {
|
||||
$value = preg_replace('/ COLLATE .+$/', '', $value, -1, $count);
|
||||
|
@ -393,14 +409,13 @@ abstract class IdoQuery extends DbQuery
|
|||
{
|
||||
parent::init();
|
||||
$this->prefix = $this->ds->getTablePrefix();
|
||||
|
||||
if ($this->ds->getDbType() === 'oracle') {
|
||||
$dbType = $this->ds->getDbType();
|
||||
if ($dbType === 'oracle') {
|
||||
$this->initializeForOracle();
|
||||
} elseif ($this->ds->getDbType() === 'pgsql') {
|
||||
} elseif ($dbType === 'pgsql') {
|
||||
$this->initializeForPostgres();
|
||||
}
|
||||
$this->dbSelect();
|
||||
|
||||
$this->select->columns($this->columns);
|
||||
//$this->joinBaseTables();
|
||||
$this->prepareAliasIndexes();
|
||||
|
@ -604,14 +619,14 @@ abstract class IdoQuery extends DbQuery
|
|||
|
||||
protected function hasCustomvar($customvar)
|
||||
{
|
||||
return array_key_exists($customvar, $this->customVars);
|
||||
return array_key_exists(strtolower($customvar), $this->customVars);
|
||||
}
|
||||
|
||||
protected function joinCustomvar($customvar)
|
||||
{
|
||||
// TODO: This is not generic enough yet
|
||||
list($type, $name) = $this->customvarNameToTypeName($customvar);
|
||||
$alias = ($type === 'host' ? 'hcv_' : 'scv_') . strtolower($name);
|
||||
$alias = ($type === 'host' ? 'hcv_' : 'scv_') . $name;
|
||||
|
||||
$this->customVars[$customvar] = $alias;
|
||||
|
||||
|
@ -622,12 +637,12 @@ abstract class IdoQuery extends DbQuery
|
|||
} else {
|
||||
$leftcol = 'h.' . $type . '_object_id';
|
||||
}
|
||||
|
||||
$joinOn = sprintf(
|
||||
'%s = %s.object_id AND %s.varname = %s',
|
||||
$this->customVarsJoinTemplate,
|
||||
$leftcol,
|
||||
$alias,
|
||||
$alias,
|
||||
$this->db->quote(strtoupper($name))
|
||||
$this->db->quote($name)
|
||||
);
|
||||
|
||||
$this->select->joinLeft(
|
||||
|
@ -641,6 +656,7 @@ abstract class IdoQuery extends DbQuery
|
|||
|
||||
protected function customvarNameToTypeName($customvar)
|
||||
{
|
||||
$customvar = strtolower($customvar);
|
||||
// TODO: Improve this:
|
||||
if (! preg_match('~^_(host|service)_([a-zA-Z0-9_]+)$~', $customvar, $m)) {
|
||||
throw new ProgrammingError(
|
||||
|
@ -658,7 +674,7 @@ abstract class IdoQuery extends DbQuery
|
|||
|
||||
protected function getCustomvarColumnName($customvar)
|
||||
{
|
||||
return $this->customVars[$customvar] . '.varvalue';
|
||||
return $this->customVars[strtolower($customvar)] . '.varvalue';
|
||||
}
|
||||
|
||||
public function aliasToColumnName($alias)
|
||||
|
|
|
@ -36,11 +36,12 @@ class StatusQuery extends IdoQuery
|
|||
'hosts' => array(
|
||||
'host' => 'ho.name1 COLLATE latin1_general_ci',
|
||||
'host_name' => 'ho.name1',
|
||||
'host_display_name' => 'h.display_name',
|
||||
'host_display_name' => 'h.display_name COLLATE latin1_general_ci',
|
||||
'host_alias' => 'h.alias',
|
||||
'host_address' => 'h.address',
|
||||
'host_ipv4' => 'INET_ATON(h.address)',
|
||||
'host_icon_image' => 'h.icon_image',
|
||||
'host_icon_image_alt' => 'h.icon_image_alt',
|
||||
'host_action_url' => 'h.action_url',
|
||||
'host_notes_url' => 'h.notes_url'
|
||||
),
|
||||
|
@ -162,20 +163,21 @@ class StatusQuery extends IdoQuery
|
|||
'hostgroups' => array(
|
||||
'hostgroup' => 'hgo.name1 COLLATE latin1_general_ci',
|
||||
'hostgroup_name' => 'hgo.name1',
|
||||
'hostgroup_alias' => 'hg.alias'
|
||||
'hostgroup_alias' => 'hg.alias COLLATE latin1_general_ci'
|
||||
),
|
||||
'servicegroups' => array(
|
||||
'servicegroup' => 'sgo.name1 COLLATE latin1_general_ci',
|
||||
'servicegroup_name' => 'sgo.name1',
|
||||
'servicegroup_alias' => 'sg.alias'
|
||||
'servicegroup_alias' => 'sg.alias COLLATE latin1_general_ci'
|
||||
),
|
||||
'services' => array(
|
||||
'service_host' => 'so.name1 COLLATE latin1_general_ci',
|
||||
'service_host_name' => 'so.name1',
|
||||
'service' => 'so.name2 COLLATE latin1_general_ci',
|
||||
'service_description' => 'so.name2',
|
||||
'service_display_name' => 's.display_name',
|
||||
'service_display_name' => 's.display_name COLLATE latin1_general_ci',
|
||||
'service_icon_image' => 's.icon_image',
|
||||
'service_icon_image_alt' => 's.icon_image_alt',
|
||||
'service_action_url' => 's.action_url',
|
||||
'service_notes_url' => 's.notes_url',
|
||||
'object_type' => '(\'service\')'
|
||||
|
|
|
@ -247,11 +247,11 @@ abstract class DataView implements QueryInterface, IteratorAggregate
|
|||
};
|
||||
}
|
||||
|
||||
$globalDefaultOrder = isset($sortColumns['order']) ? $sortColumns['order'] : static::SORT_ASC;
|
||||
$globalDefaultOrder = (strtoupper($globalDefaultOrder) === static::SORT_ASC) ? 'ASC' : 'DESC';
|
||||
$order = $order === null ? (isset($sortColumns['order']) ? $sortColumns['order'] : static::SORT_ASC) : $order;
|
||||
$order = (strtoupper($order) === static::SORT_ASC) ? 'ASC' : 'DESC';
|
||||
|
||||
foreach ($sortColumns['columns'] as $column) {
|
||||
list($column, $specificDefaultOrder) = $this->query->splitOrder($column);
|
||||
list($column, $direction) = $this->query->splitOrder($column);
|
||||
if (! $this->isValidFilterTarget($column)) {
|
||||
throw new QueryException(
|
||||
mt('monitoring', 'The sort column "%s" is not allowed in "%s".'),
|
||||
|
@ -259,10 +259,7 @@ abstract class DataView implements QueryInterface, IteratorAggregate
|
|||
get_class($this)
|
||||
);
|
||||
}
|
||||
$this->query->order(
|
||||
$column,
|
||||
$order === null && $specificDefaultOrder !== null ? $specificDefaultOrder : $globalDefaultOrder
|
||||
);
|
||||
$this->query->order($column, $direction !== null ? $direction : $order);
|
||||
}
|
||||
$this->isSorted = true;
|
||||
return $this;
|
||||
|
@ -378,6 +375,16 @@ abstract class DataView implements QueryInterface, IteratorAggregate
|
|||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the view's search columns
|
||||
*
|
||||
* @return string[]
|
||||
*/
|
||||
public function getSearchColumns()
|
||||
{
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated(EL): Only use DataView::applyFilter() for applying filter because all other functions are missing
|
||||
* column validation.
|
||||
|
|
|
@ -94,10 +94,11 @@ class HostStatus extends DataView
|
|||
),
|
||||
'host_severity' => array(
|
||||
'columns' => array(
|
||||
'host_severity DESC',
|
||||
'host_severity',
|
||||
'host_last_state_change DESC',
|
||||
'host_display_name ASC'
|
||||
)
|
||||
),
|
||||
'order' => self::SORT_DESC
|
||||
),
|
||||
'host_address' => array(
|
||||
'columns' => array(
|
||||
|
@ -125,4 +126,12 @@ class HostStatus extends DataView
|
|||
}
|
||||
return parent::isValidFilterTarget($column);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getSearchColumns()
|
||||
{
|
||||
return array('host', 'host_display_name');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,101 @@
|
|||
<?php
|
||||
/* Icinga Web 2 | (c) 2013-2015 Icinga Development Team | GPLv2+ */
|
||||
|
||||
namespace Icinga\Module\Monitoring\DataView;
|
||||
|
||||
/**
|
||||
* Data view for the host group summary
|
||||
*/
|
||||
class Hostgroupsummary extends DataView
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getColumns()
|
||||
{
|
||||
return array(
|
||||
'hostgroup_alias',
|
||||
'hostgroup_name',
|
||||
'hosts_down_handled',
|
||||
'hosts_down_last_state_change_handled',
|
||||
'hosts_down_last_state_change_unhandled',
|
||||
'hosts_down_unhandled',
|
||||
'hosts_pending',
|
||||
'hosts_pending_last_state_change',
|
||||
'hosts_severity',
|
||||
'hosts_total',
|
||||
'hosts_unreachable_handled',
|
||||
'hosts_unreachable_last_state_change_handled',
|
||||
'hosts_unreachable_last_state_change_unhandled',
|
||||
'hosts_unreachable_unhandled',
|
||||
'hosts_up',
|
||||
'hosts_up_last_state_change',
|
||||
'services_critical_handled',
|
||||
'services_critical_unhandled',
|
||||
'services_ok',
|
||||
'services_pending',
|
||||
'services_total',
|
||||
'services_unknown_handled',
|
||||
'services_unknown_unhandled',
|
||||
'services_warning_handled',
|
||||
'services_warning_unhandled'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getFilterColumns()
|
||||
{
|
||||
return array('hostgroup');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function getQueryName()
|
||||
{
|
||||
return 'groupsummary';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getSearchColumns()
|
||||
{
|
||||
return array('hostgroup', 'hostgroup_alias');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getSortRules()
|
||||
{
|
||||
return array(
|
||||
'hostgroup_alias' => array(
|
||||
'order' => self::SORT_ASC
|
||||
),
|
||||
'hosts_severity' => array(
|
||||
'columns' => array(
|
||||
'hosts_severity',
|
||||
'hostgroup_alias ASC'
|
||||
),
|
||||
'order' => self::SORT_DESC
|
||||
),
|
||||
'hosts_total' => array(
|
||||
'columns' => array(
|
||||
'hosts_total',
|
||||
'hostgroup_alias ASC'
|
||||
),
|
||||
'order' => self::SORT_ASC
|
||||
),
|
||||
'services_total' => array(
|
||||
'columns' => array(
|
||||
'services_total',
|
||||
'hostgroup_alias ASC'
|
||||
),
|
||||
'order' => self::SORT_ASC
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
|
@ -40,7 +40,6 @@ class ServiceStatus extends DataView
|
|||
'service_unhandled',
|
||||
'service_output',
|
||||
'service_last_state_change',
|
||||
'service_icon_image',
|
||||
'service_long_output',
|
||||
'service_is_flapping',
|
||||
'service_state_type',
|
||||
|
@ -60,7 +59,6 @@ class ServiceStatus extends DataView
|
|||
'service_last_notification',
|
||||
'service_check_command',
|
||||
'service_current_notification_number',
|
||||
'host_icon_image',
|
||||
'host_acknowledged',
|
||||
'host_output',
|
||||
'host_long_output',
|
||||
|
@ -130,19 +128,21 @@ class ServiceStatus extends DataView
|
|||
),
|
||||
'service_severity' => array(
|
||||
'columns' => array(
|
||||
'service_severity DESC',
|
||||
'service_severity',
|
||||
'service_last_state_change DESC',
|
||||
'service_display_name ASC',
|
||||
'host_display_name ASC'
|
||||
)
|
||||
),
|
||||
'order' => self::SORT_DESC
|
||||
),
|
||||
'host_severity' => array(
|
||||
'columns' => array(
|
||||
'host_severity DESC',
|
||||
'host_severity',
|
||||
'host_last_state_change DESC',
|
||||
'host_display_name ASC',
|
||||
'service_display_name ASC'
|
||||
)
|
||||
),
|
||||
'order' => self::SORT_DESC
|
||||
),
|
||||
'host_display_name' => array(
|
||||
'columns' => array(
|
||||
|
@ -183,4 +183,12 @@ class ServiceStatus extends DataView
|
|||
}
|
||||
return parent::isValidFilterTarget($column);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getSearchColumns()
|
||||
{
|
||||
return array('service', 'service_display_name');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,71 +3,90 @@
|
|||
|
||||
namespace Icinga\Module\Monitoring\DataView;
|
||||
|
||||
class Groupsummary extends DataView
|
||||
class Servicegroupsummary extends DataView
|
||||
{
|
||||
/**
|
||||
* Retrieve columns provided by this view
|
||||
*
|
||||
* @return array
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getColumns()
|
||||
{
|
||||
return array(
|
||||
'servicegroup_name',
|
||||
'servicegroup_alias',
|
||||
'hostgroup_name',
|
||||
'hostgroup_alias',
|
||||
'hosts_total',
|
||||
'hosts_up',
|
||||
'hosts_unreachable',
|
||||
'hosts_unreachable_handled',
|
||||
'hosts_unreachable_unhandled',
|
||||
'hosts_down',
|
||||
'hosts_down_handled',
|
||||
'hosts_down_unhandled',
|
||||
'hosts_pending',
|
||||
'hosts_up_last_state_change',
|
||||
'hosts_pending_last_state_change',
|
||||
'hosts_down_last_state_change_handled',
|
||||
'hosts_unreachable_last_state_change_handled',
|
||||
'hosts_down_last_state_change_unhandled',
|
||||
'hosts_unreachable_last_state_change_unhandled',
|
||||
'services_total',
|
||||
'services_ok',
|
||||
'services_unknown',
|
||||
'services_unknown_handled',
|
||||
'services_unknown_unhandled',
|
||||
'services_critical',
|
||||
'hosts_unreachable_handled',
|
||||
'hosts_unreachable_unhandled',
|
||||
'hosts_up',
|
||||
'servicegroup_alias',
|
||||
'servicegroup_name',
|
||||
'services_critical_handled',
|
||||
'services_critical_unhandled',
|
||||
'services_warning',
|
||||
'services_warning_handled',
|
||||
'services_warning_unhandled',
|
||||
'services_pending',
|
||||
'services_severity',
|
||||
'services_ok_last_state_change',
|
||||
'services_pending_last_state_change',
|
||||
'services_warning_last_state_change_handled',
|
||||
'services_critical_last_state_change_handled',
|
||||
'services_unknown_last_state_change_handled',
|
||||
'services_warning_last_state_change_unhandled',
|
||||
'services_critical_last_state_change_unhandled',
|
||||
'services_unknown_last_state_change_unhandled'
|
||||
'services_critical_unhandled',
|
||||
'services_ok',
|
||||
'services_ok_last_state_change',
|
||||
'services_pending',
|
||||
'services_pending_last_state_change',
|
||||
'services_severity',
|
||||
'services_total',
|
||||
'services_unknown_handled',
|
||||
'services_unknown_last_state_change_handled',
|
||||
'services_unknown_last_state_change_unhandled',
|
||||
'services_unknown_unhandled',
|
||||
'services_warning_handled',
|
||||
'services_warning_last_state_change_handled',
|
||||
'services_warning_last_state_change_unhandled',
|
||||
'services_warning_unhandled'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getFilterColumns()
|
||||
{
|
||||
return array('servicegroup');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function getQueryName()
|
||||
{
|
||||
return 'groupsummary';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getSearchColumns()
|
||||
{
|
||||
return array('servicegroup', 'servicegroup_alias');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getSortRules()
|
||||
{
|
||||
return array(
|
||||
'servicegroup_alias' => array(
|
||||
'order' => self::SORT_ASC
|
||||
),
|
||||
'services_severity' => array(
|
||||
'columns' => array('services_severity'),
|
||||
'order' => self::SORT_DESC
|
||||
'columns' => array(
|
||||
'services_severity',
|
||||
'servicegroup_alias ASC'
|
||||
),
|
||||
'order' => self::SORT_DESC
|
||||
),
|
||||
'services_total' => array(
|
||||
'columns' => array(
|
||||
'services_total',
|
||||
'servicegroup_alias ASC'
|
||||
),
|
||||
'order' => self::SORT_ASC
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public function getFilterColumns()
|
||||
{
|
||||
return array('hostgroup', 'servicegroup');
|
||||
}
|
||||
}
|
|
@ -89,6 +89,8 @@ class Host extends MonitoredObject
|
|||
protected function getDataView()
|
||||
{
|
||||
$columns = array(
|
||||
'host_icon_image',
|
||||
'host_icon_image_alt',
|
||||
'host_acknowledged',
|
||||
'host_action_url',
|
||||
'host_active_checks_enabled',
|
||||
|
|
|
@ -106,6 +106,8 @@ class Service extends MonitoredObject
|
|||
protected function getDataView()
|
||||
{
|
||||
return $this->backend->select()->from('serviceStatus', array(
|
||||
'host_icon_image',
|
||||
'host_icon_image_alt',
|
||||
'host_acknowledged',
|
||||
'host_active_checks_enabled',
|
||||
'host_address',
|
||||
|
@ -118,6 +120,8 @@ class Service extends MonitoredObject
|
|||
'host_notifications_enabled',
|
||||
'host_passive_checks_enabled',
|
||||
'host_state',
|
||||
'service_icon_image',
|
||||
'service_icon_image_alt',
|
||||
'service_acknowledged',
|
||||
'service_action_url',
|
||||
'service_active_checks_enabled',
|
||||
|
|
|
@ -23,7 +23,7 @@ table.action {
|
|||
border-collapse: separate;
|
||||
border-spacing: 1px;
|
||||
width: 100%;
|
||||
table-layout: fixed;
|
||||
table-layout: fixed !important;
|
||||
margin: 0;
|
||||
color: @colorTextDefault;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue