diff --git a/application/forms/ConfirmRemovalForm.php b/application/forms/ConfirmRemovalForm.php index 985413907..357928cd0 100644 --- a/application/forms/ConfirmRemovalForm.php +++ b/application/forms/ConfirmRemovalForm.php @@ -11,11 +11,11 @@ use Icinga\Web\Form; class ConfirmRemovalForm extends Form { /** - * Initalize this form + * Initialize this form */ public function init() { $this->setName('form_confirm_removal'); - $this->setSubmitLabel($this->translate('Confirm Removal')); + $this->getSubmitLabel() ?: $this->setSubmitLabel($this->translate('Confirm Removal')); } } diff --git a/library/Icinga/Cli/Params.php b/library/Icinga/Cli/Params.php index 507c50e3b..9e30cf19e 100644 --- a/library/Icinga/Cli/Params.php +++ b/library/Icinga/Cli/Params.php @@ -167,7 +167,7 @@ class Params * * @throws MissingParameterException If the parameter was not given */ - public function req($name, $strict = true) + public function getRequired($name, $strict = true) { if ($this->has($name)) { $value = $this->get($name); @@ -258,6 +258,30 @@ class Params return $result; } + /** + * Require and remove a parameter + * + * @param string $name Name of the parameter + * @param bool $strict Whether the parameter's value must not be the empty string + * + * @return mixed + * + * @throws MissingParameterException If the parameter was not given + */ + public function shiftRequired($name, $strict = true) + { + if ($this->has($name)) { + $value = $this->get($name); + if (! $strict || strlen($value) > 0) { + $this->shift($name); + return $value; + } + } + $e = new MissingParameterException(t('Required parameter \'%s\' missing'), $name); + $e->setParameter($name); + throw $e; + } + /** * Put the given value onto the argument stack * diff --git a/library/Icinga/Web/Controller.php b/library/Icinga/Web/Controller.php index 9acf17469..0975d4c13 100644 --- a/library/Icinga/Web/Controller.php +++ b/library/Icinga/Web/Controller.php @@ -3,6 +3,7 @@ namespace Icinga\Web; +use Zend_Controller_Action_Exception; use Icinga\Data\Sortable; use Icinga\Data\QueryInterface; use Icinga\Web\Controller\ModuleActionController; @@ -49,6 +50,18 @@ class Controller extends ModuleActionController } } + /** + * Immediately respond w/ HTTP 404 + * + * @param $message + * + * @throws Zend_Controller_Action_Exception + */ + public function httpNotFound($message) + { + throw new Zend_Controller_Action_Exception($message, 404); + } + /** * Create a SortBox widget and apply its sort rules on the given query * diff --git a/library/Icinga/Web/UrlParams.php b/library/Icinga/Web/UrlParams.php index e25fa7e6c..d97f83b39 100644 --- a/library/Icinga/Web/UrlParams.php +++ b/library/Icinga/Web/UrlParams.php @@ -54,7 +54,7 @@ class UrlParams * * @throws MissingParameterException If the parameter was not given */ - public function req($name, $strict = true) + public function getRequired($name, $strict = true) { if ($this->has($name)) { $value = $this->get($name); @@ -138,6 +138,30 @@ class UrlParams return $ret; } + /** + * Require and remove a parameter + * + * @param string $name Name of the parameter + * @param bool $strict Whether the parameter's value must not be the empty string + * + * @return mixed + * + * @throws MissingParameterException If the parameter was not given + */ + public function shiftRequired($name, $strict = true) + { + if ($this->has($name)) { + $value = $this->get($name); + if (! $strict || strlen($value) > 0) { + $this->shift($name); + return $value; + } + } + $e = new MissingParameterException(t('Required parameter \'%s\' missing'), $name); + $e->setParameter($name); + throw $e; + } + public function addEncoded($param, $value = true) { $this->params[] = array($param, $this->cleanupValue($value)); diff --git a/modules/monitoring/application/controllers/ListController.php b/modules/monitoring/application/controllers/ListController.php index a793f2a0a..92c42d4ad 100644 --- a/modules/monitoring/application/controllers/ListController.php +++ b/modules/monitoring/application/controllers/ListController.php @@ -12,7 +12,6 @@ use Icinga\Web\Widget\Tabs; use Icinga\Data\Filter\Filter; use Icinga\Web\Widget; use Icinga\Module\Monitoring\Forms\StatehistoryForm; -use Icinga\Data\Filterable; class Monitoring_ListController extends Controller { @@ -96,7 +95,7 @@ class Monitoring_ListController extends Controller 'host_current_check_attempt', 'host_max_check_attempts' ), $this->addColumns())); - $this->filterQuery($query, array('host', 'host_display_name')); + $this->filterQuery($query); $this->applyRestriction('monitoring/hosts/filter', $query); $this->view->hosts = $query; @@ -180,7 +179,7 @@ class Monitoring_ListController extends Controller 'max_check_attempts' => 'service_max_check_attempts' ), $this->addColumns()); $query = $this->backend->select()->from('serviceStatus', $columns); - $this->filterQuery($query, array('service', 'service_display_name')); + $this->filterQuery($query); $this->applyRestriction('monitoring/services/filter', $query); $this->view->services = $query; @@ -498,7 +497,7 @@ class Monitoring_ListController extends Controller ))->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. - $this->filterQuery($query, array('servicegroup', 'servicegroup_alias')); + $this->filterQuery($query); $this->view->servicegroups = $query; $this->setupLimitControl(); @@ -535,6 +534,7 @@ class Monitoring_ListController extends Controller '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', @@ -555,7 +555,7 @@ class Monitoring_ListController extends Controller ))->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. - $this->filterQuery($query, array('hostgroup', 'hostgroup_alias')); + $this->filterQuery($query); $this->view->hostgroups = $query; $this->setupLimitControl(); @@ -626,15 +626,7 @@ class Monitoring_ListController extends Controller $this->view->verticalPaginator = $pivot->paginateYAxis(); } - /** - * Apply filters on a query - * - * @param Filterable $query The query to apply filters on - * @param array $searchColumns Columns to search in - * - * @return Filterable $query - */ - protected function filterQuery(Filterable $query, array $searchColumns = null) + protected function filterQuery($query) { $editor = Widget::create('filterEditor') ->setQuery($query) @@ -642,11 +634,8 @@ class Monitoring_ListController extends Controller 'limit', 'sort', 'dir', 'format', 'view', 'backend', 'stateType', 'addColumns', '_dev' ) - ->ignoreParams('page'); - if ($searchColumns !== null) { - $editor->setSearchColumns($searchColumns); - } - $editor->handleRequest($this->getRequest()); + ->ignoreParams('page') + ->handleRequest($this->getRequest()); $query->applyFilter($editor->getFilter()); $this->setupFilterControl($editor); diff --git a/modules/monitoring/application/views/scripts/list/hostgroups.phtml b/modules/monitoring/application/views/scripts/list/hostgroups.phtml index 90e96e660..23d031b3f 100644 --- a/modules/monitoring/application/views/scripts/list/hostgroups.phtml +++ b/modules/monitoring/application/views/scripts/list/hostgroups.phtml @@ -22,6 +22,8 @@ if (count($hostgroups) === 0) { translate('Last Problem'); ?> translate('Host Group'); ?> + translate('Total Hosts'); ?> + translate('Host States'); ?> translate('Total Services'); ?> translate('Service States'); ?> @@ -68,6 +70,173 @@ if (count($hostgroups) === 0) { array('title' => sprintf($this->translate('List all hosts in the group "%s"'), $h->hostgroup_alias)) ); ?> + + qlink( + $h->hosts_total, + 'monitoring/list/hosts', + array('hostgroup_name' => $h->hostgroup_name), + array('title' => sprintf( + $this->translate('List all hosts in host group "%s"'), + $h->hostgroup_alias + )) + ); ?> + + + hosts_up): ?> + + qlink( + $h->hosts_up, + 'monitoring/list/hosts', + array( + 'host_state' => 0, + 'hostgroup_name' => $h->hostgroup_name, + 'sort' => 'host_severity' + ), + array( + 'title' => sprintf( + $this->translatePlural( + 'List %u host that is currently in state UP in the host group "%s"', + 'List %u hosts which are currently in state UP in the host group "%s"', + $h->hosts_up + ), + $h->hosts_up, + $h->hostgroup_alias + ) + ) + ); ?> + + + hosts_down_unhandled): ?> + + qlink( + $h->hosts_down_unhandled, + 'monitoring/list/hosts', + array( + 'host_state' => 1, + 'host_acknowledged' => 0, + 'host_in_downtime' => 0, + 'hostgroup_name' => $h->hostgroup_name, + 'sort' => 'host_severity' + ), + array( + 'title' => sprintf( + $this->translatePlural( + 'List %u host that is currently in state DOWN in the host group "%s"', + 'List %u hosts which are currently in state DOWN in the host group "%s"', + $h->hosts_down_unhandled + ), + $h->hosts_down_unhandled, + $h->hostgroup_alias + ) + ) + ); ?> + + hosts_down_handled): ?> + + qlink( + $h->hosts_down_handled, + 'monitoring/list/hosts', + array( + 'host_state' => 1, + 'host_handled' => 1, + 'hostgroup_name' => $h->hostgroup_name, + 'sort' => 'host_severity' + ), + array( + 'title' => sprintf( + $this->translatePlural( + 'List %u host that is currently in state DOWN (Acknowledged) in the host group "%s"', + 'List %u hosts which are currently in state DOWN (Acknowledged) in the host group "%s"', + $h->hosts_down_handled + ), + $h->hosts_down_handled, + $h->hostgroup_alias + ) + ) + ); ?> + + + hosts_down_unhandled): ?> + + + hosts_unreachable_unhandled): ?> + + qlink( + $h->hosts_unreachable_unhandled, + 'monitoring/list/hosts', + array( + 'host_state' => 2, + 'host_acknowledged' => 0, + 'host_in_downtime' => 0, + 'hostgroup_name' => $h->hostgroup_name, + 'sort' => 'host_severity' + ), + array( + 'title' => sprintf( + $this->translatePlural( + 'List %u host that is currently in state UNREACHABLE in the host group "%s"', + 'List %u hosts which are currently in state UNREACHABLE in the host group "%s"', + $h->hosts_unreachable_unhandled + ), + $h->hosts_unreachable_unhandled, + $h->hostgroup_alias + ) + ) + ); ?> + + hosts_unreachable_handled): ?> + + qlink( + $h->hosts_unreachable_handled, + 'monitoring/list/hosts', + array( + 'host_state' => 2, + 'host_handled' => 1, + 'hostgroup_name' => $h->hostgroup_name, + 'sort' => 'host_severity' + ), + array( + 'title' => sprintf( + $this->translatePlural( + 'List %u host that is currently in state UNREACHABLE (Acknowledged) in the host group "%s"', + 'List %u hosts which are currently in state UNREACHABLE (Acknowledged) in the host group "%s"', + $h->hosts_unreachable_handled + ), + $h->hosts_unreachable_handled, + $h->hostgroup_alias + ) + ) + ); ?> + + + hosts_unreachable_unhandled): ?> + + + hosts_pending): ?> + + qlink( + $h->hosts_pending, + 'monitoring/list/hosts', + array( + 'host_state' => 99, + 'hostgroup_name' => $h->hostgroup_name, + 'sort' => 'host_severity' + ), + array( + 'title' => sprintf( + $this->translatePlural( + 'List %u host that is currently in state PENDING in the host group "%s"', + 'List %u hosts which are currently in state PENDING in the host group "%s"', + $h->hosts_pending + ), + $h->hosts_pending, + $h->hostgroup_alias + ) + ) + ); ?> + + + qlink( $h->services_total, diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/GroupsummaryQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/GroupsummaryQuery.php index fd389562e..392c97538 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/GroupsummaryQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/GroupsummaryQuery.php @@ -11,6 +11,7 @@ class GroupSummaryQuery extends IdoQuery protected $columnMap = array( 'hoststatussummary' => array( + 'hosts_total' => 'SUM(CASE WHEN object_type = \'host\' THEN 1 ELSE 0 END)', '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)', diff --git a/modules/monitoring/library/Monitoring/DataView/Groupsummary.php b/modules/monitoring/library/Monitoring/DataView/Groupsummary.php index d29c1c418..36174bfde 100644 --- a/modules/monitoring/library/Monitoring/DataView/Groupsummary.php +++ b/modules/monitoring/library/Monitoring/DataView/Groupsummary.php @@ -17,6 +17,7 @@ class Groupsummary extends DataView 'servicegroup_alias', 'hostgroup_name', 'hostgroup_alias', + 'hosts_total', 'hosts_up', 'hosts_unreachable', 'hosts_unreachable_handled',