From ead0a642444c8718c3ca1475e205421a1f01239c Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Wed, 13 May 2015 18:10:18 +0200 Subject: [PATCH 01/15] GroupsummaryQuery: add column `hosts_total' refs #8054 --- .../library/Monitoring/Backend/Ido/Query/GroupsummaryQuery.php | 1 + modules/monitoring/library/Monitoring/DataView/Groupsummary.php | 1 + 2 files changed, 2 insertions(+) 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', From e879ba445dc308c5524bb83e6cddb9c73b32071e Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Wed, 13 May 2015 18:15:04 +0200 Subject: [PATCH 02/15] List number of hosts in host groups refs #8054 --- .../application/controllers/ListController.php | 1 + .../application/views/scripts/list/hostgroups.phtml | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/modules/monitoring/application/controllers/ListController.php b/modules/monitoring/application/controllers/ListController.php index 948050db6..540f21bae 100644 --- a/modules/monitoring/application/controllers/ListController.php +++ b/modules/monitoring/application/controllers/ListController.php @@ -534,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', diff --git a/modules/monitoring/application/views/scripts/list/hostgroups.phtml b/modules/monitoring/application/views/scripts/list/hostgroups.phtml index 90e96e660..89045d9ab 100644 --- a/modules/monitoring/application/views/scripts/list/hostgroups.phtml +++ b/modules/monitoring/application/views/scripts/list/hostgroups.phtml @@ -22,6 +22,7 @@ if (count($hostgroups) === 0) { translate('Last Problem'); ?> translate('Host Group'); ?> + translate('Total Hosts'); ?> translate('Total Services'); ?> translate('Service States'); ?> @@ -68,6 +69,17 @@ 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 + )) + ); ?> + qlink( $h->services_total, From c7d1a7211f63510c0bb9f932f2bccbfdc4dfc705 Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Fri, 15 May 2015 11:28:16 +0200 Subject: [PATCH 03/15] Show host states in host groups --- .../views/scripts/list/hostgroups.phtml | 157 ++++++++++++++++++ 1 file changed, 157 insertions(+) diff --git a/modules/monitoring/application/views/scripts/list/hostgroups.phtml b/modules/monitoring/application/views/scripts/list/hostgroups.phtml index 89045d9ab..23d031b3f 100644 --- a/modules/monitoring/application/views/scripts/list/hostgroups.phtml +++ b/modules/monitoring/application/views/scripts/list/hostgroups.phtml @@ -23,6 +23,7 @@ if (count($hostgroups) === 0) { translate('Last Problem'); ?> translate('Host Group'); ?> translate('Total Hosts'); ?> + translate('Host States'); ?> translate('Total Services'); ?> translate('Service States'); ?> @@ -80,6 +81,162 @@ if (count($hostgroups) === 0) { )) ); ?> + + 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, From 8b084733413b74131100abf6a31efc02793695c5 Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Fri, 15 May 2015 12:34:59 +0200 Subject: [PATCH 04/15] Hostgroups view: reduce "Last Problem" column's width --- .../application/views/scripts/list/hostgroups.phtml | 2 +- public/css/icinga/main-content.less | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/modules/monitoring/application/views/scripts/list/hostgroups.phtml b/modules/monitoring/application/views/scripts/list/hostgroups.phtml index 23d031b3f..e75359b23 100644 --- a/modules/monitoring/application/views/scripts/list/hostgroups.phtml +++ b/modules/monitoring/application/views/scripts/list/hostgroups.phtml @@ -20,7 +20,7 @@ if (count($hostgroups) === 0) { ?> - + diff --git a/public/css/icinga/main-content.less b/public/css/icinga/main-content.less index b442723cb..59c7830da 100644 --- a/public/css/icinga/main-content.less +++ b/public/css/icinga/main-content.less @@ -169,6 +169,10 @@ table.benchmark { width: 96%; } +table.groupview th.state { + width: 9em; +} + .dashboard h1 { font-size: 1em; } From afe07f48148c6ab0ee3742c00f320090946b6303 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Tue, 19 May 2015 13:42:57 +0200 Subject: [PATCH 05/15] Revert "Hostgroups view: reduce "Last Problem" column's width" This reverts commit 8b084733413b74131100abf6a31efc02793695c5. Common table style is subject of #8935. refs #8054 --- .../application/views/scripts/list/hostgroups.phtml | 2 +- public/css/icinga/main-content.less | 4 ---- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/modules/monitoring/application/views/scripts/list/hostgroups.phtml b/modules/monitoring/application/views/scripts/list/hostgroups.phtml index e75359b23..23d031b3f 100644 --- a/modules/monitoring/application/views/scripts/list/hostgroups.phtml +++ b/modules/monitoring/application/views/scripts/list/hostgroups.phtml @@ -20,7 +20,7 @@ if (count($hostgroups) === 0) { ?>
translate('Last Problem'); ?>translate('Last Problem'); ?> translate('Host Group'); ?> translate('Total Hosts'); ?> translate('Host States'); ?>
- + diff --git a/public/css/icinga/main-content.less b/public/css/icinga/main-content.less index 59c7830da..b442723cb 100644 --- a/public/css/icinga/main-content.less +++ b/public/css/icinga/main-content.less @@ -169,10 +169,6 @@ table.benchmark { width: 96%; } -table.groupview th.state { - width: 9em; -} - .dashboard h1 { font-size: 1em; } From 94bdb8b4b072c9fadac77830325f727a14f93f85 Mon Sep 17 00:00:00 2001 From: Matthias Jentsch Date: Tue, 19 May 2015 16:35:44 +0200 Subject: [PATCH 06/15] Abort pending AJAX requests before page unload Abort all pending requests before the page unload, to avoid confusing error messages during page reloads. Avoid rendering the site unusable in cases where the site is still being used after the beforeunload event. fixes #7759 --- public/js/icinga/events.js | 13 +++++++++++-- public/js/icinga/loader.js | 14 ++++++++++---- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/public/js/icinga/events.js b/public/js/icinga/events.js index cc927feb6..d458ab7fc 100644 --- a/public/js/icinga/events.js +++ b/public/js/icinga/events.js @@ -100,7 +100,7 @@ // Destroy Icinga, clean up and interrupt pending requests on unload $( window ).on('unload', { self: this }, this.onUnload); - $( window ).on('beforeunload', { self: this }, this.onUnload); + $( window ).on('beforeunload', { self: this }, this.onBeforeUnload); // We catch scroll events in our containers $('.container').on('scroll', { self: this }, this.icinga.events.onContainerScroll); @@ -153,6 +153,15 @@ icinga.destroy(); }, + onBeforeUnload: function (event) { + var icinga = event.data.self.icinga; + + // Browsers may call the error handler on all pending AJAX requests, when the page is reloaded, + // which could in turn cause needless error messages to show up in the frontend until the page is loaded. + // To circumvent this cancel all pending requests. + icinga.loader.cancelRequests(); + }, + /** * A scroll event happened in one of our containers */ @@ -560,7 +569,7 @@ $(window).off('resize', this.onWindowResize); $(window).off('load', this.onLoad); $(window).off('unload', this.onUnload); - $(window).off('beforeunload', this.onUnload); + $(window).off('beforeunload', this.onBeforeUnload); $(document).off('scroll', '.container', this.onContainerScroll); $(document).off('click', 'a', this.linkClicked); $(document).off('click', 'table.action tr[href]', this.rowSelected); diff --git a/public/js/icinga/loader.js b/public/js/icinga/loader.js index 99667ac1c..e01e03cec 100644 --- a/public/js/icinga/loader.js +++ b/public/js/icinga/loader.js @@ -793,16 +793,22 @@ }, /** - * On shutdown we kill all pending requests + * Cancel and dereference all pending requests and dereference this object */ destroy: function() { + this.icinga.loader.cancelRequests(); + this.icinga = null; + this.requests = {}; + }, + + /** + * Cancel all pendings ajax requests + */ + cancelRequests: function() { $.each(this.requests, function(id, request) { request.abort(); }); - this.icinga = null; - this.requests = {}; } - }; }(Icinga, jQuery)); From 54207d34275fc1bfed0adc31365c00fc98645be0 Mon Sep 17 00:00:00 2001 From: Matthias Jentsch Date: Tue, 19 May 2015 17:05:04 +0200 Subject: [PATCH 07/15] Revert "Abort pending AJAX requests before page unload" This reverts commit 94bdb8b4b072c9fadac77830325f727a14f93f85. After the patch, Firefox shows an error message on each reload for an unknown reason. refs #7759 --- public/js/icinga/events.js | 13 ++----------- public/js/icinga/loader.js | 14 ++++---------- 2 files changed, 6 insertions(+), 21 deletions(-) diff --git a/public/js/icinga/events.js b/public/js/icinga/events.js index d458ab7fc..cc927feb6 100644 --- a/public/js/icinga/events.js +++ b/public/js/icinga/events.js @@ -100,7 +100,7 @@ // Destroy Icinga, clean up and interrupt pending requests on unload $( window ).on('unload', { self: this }, this.onUnload); - $( window ).on('beforeunload', { self: this }, this.onBeforeUnload); + $( window ).on('beforeunload', { self: this }, this.onUnload); // We catch scroll events in our containers $('.container').on('scroll', { self: this }, this.icinga.events.onContainerScroll); @@ -153,15 +153,6 @@ icinga.destroy(); }, - onBeforeUnload: function (event) { - var icinga = event.data.self.icinga; - - // Browsers may call the error handler on all pending AJAX requests, when the page is reloaded, - // which could in turn cause needless error messages to show up in the frontend until the page is loaded. - // To circumvent this cancel all pending requests. - icinga.loader.cancelRequests(); - }, - /** * A scroll event happened in one of our containers */ @@ -569,7 +560,7 @@ $(window).off('resize', this.onWindowResize); $(window).off('load', this.onLoad); $(window).off('unload', this.onUnload); - $(window).off('beforeunload', this.onBeforeUnload); + $(window).off('beforeunload', this.onUnload); $(document).off('scroll', '.container', this.onContainerScroll); $(document).off('click', 'a', this.linkClicked); $(document).off('click', 'table.action tr[href]', this.rowSelected); diff --git a/public/js/icinga/loader.js b/public/js/icinga/loader.js index e01e03cec..99667ac1c 100644 --- a/public/js/icinga/loader.js +++ b/public/js/icinga/loader.js @@ -793,22 +793,16 @@ }, /** - * Cancel and dereference all pending requests and dereference this object + * On shutdown we kill all pending requests */ destroy: function() { - this.icinga.loader.cancelRequests(); - this.icinga = null; - this.requests = {}; - }, - - /** - * Cancel all pendings ajax requests - */ - cancelRequests: function() { $.each(this.requests, function(id, request) { request.abort(); }); + this.icinga = null; + this.requests = {}; } + }; }(Icinga, jQuery)); From b1b2e3fc21f3a66cc5b30dc8ab6b72359df48253 Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Tue, 19 May 2015 17:13:46 +0200 Subject: [PATCH 08/15] Revert "Merge branch 'bugfix/Take-display_name-into-account-when-searching-for-host-and-service-names-8241'" This reverts commit 75b004dc429a3ef32b113ebd0fb3791896ebf89b, reversing changes made to bd7c7f963663cc570f378f395863d99e9a1c3d7d. --- .../controllers/ListController.php | 26 +++++-------------- 1 file changed, 7 insertions(+), 19 deletions(-) diff --git a/modules/monitoring/application/controllers/ListController.php b/modules/monitoring/application/controllers/ListController.php index 656b59032..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(); @@ -556,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(); @@ -627,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) @@ -643,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); From 3a2238f737ca228a21d5a9225924a909f8658c5d Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Tue, 19 May 2015 17:12:18 +0200 Subject: [PATCH 09/15] Rename UrlParams::req() to ::getRequired() req() seems mysterious :) --- library/Icinga/Web/UrlParams.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/Icinga/Web/UrlParams.php b/library/Icinga/Web/UrlParams.php index e25fa7e6c..df5162459 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); From 3d1c3609c026b6f24c68230f236a7f01168d1a58 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Tue, 19 May 2015 17:21:53 +0200 Subject: [PATCH 10/15] lib: Add UrlParams::shiftRequired() --- library/Icinga/Web/UrlParams.php | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/library/Icinga/Web/UrlParams.php b/library/Icinga/Web/UrlParams.php index df5162459..d97f83b39 100644 --- a/library/Icinga/Web/UrlParams.php +++ b/library/Icinga/Web/UrlParams.php @@ -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)); From ccaebd1d73e8ad7195e98ad159422c79da92f5bd Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Tue, 19 May 2015 17:22:23 +0200 Subject: [PATCH 11/15] cli: Rename Params::req() to ::getRequired() --- library/Icinga/Cli/Params.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/Icinga/Cli/Params.php b/library/Icinga/Cli/Params.php index 507c50e3b..d51e912e2 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); From 338fad5da95bbe4c5513ac899bf9b96a3f127aa4 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Tue, 19 May 2015 17:23:37 +0200 Subject: [PATCH 12/15] cli: Add Params::shiftRequired() --- library/Icinga/Cli/Params.php | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/library/Icinga/Cli/Params.php b/library/Icinga/Cli/Params.php index d51e912e2..9e30cf19e 100644 --- a/library/Icinga/Cli/Params.php +++ b/library/Icinga/Cli/Params.php @@ -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 * From 5a69c26d2cd3667ee7c4d535a92e11c4e261af21 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Tue, 19 May 2015 17:24:05 +0200 Subject: [PATCH 13/15] Fix typo in PHPDoc of ConfirmRemovalForm::init() --- application/forms/ConfirmRemovalForm.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/forms/ConfirmRemovalForm.php b/application/forms/ConfirmRemovalForm.php index 985413907..5d9ca86b4 100644 --- a/application/forms/ConfirmRemovalForm.php +++ b/application/forms/ConfirmRemovalForm.php @@ -11,7 +11,7 @@ use Icinga\Web\Form; class ConfirmRemovalForm extends Form { /** - * Initalize this form + * Initialize this form */ public function init() { From bd54784496d4d522d4693d3246d9f5e2d7ed19f3 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Tue, 19 May 2015 17:25:48 +0200 Subject: [PATCH 14/15] Don't override submit label in the ConfirmRemovalForm --- application/forms/ConfirmRemovalForm.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/forms/ConfirmRemovalForm.php b/application/forms/ConfirmRemovalForm.php index 5d9ca86b4..357928cd0 100644 --- a/application/forms/ConfirmRemovalForm.php +++ b/application/forms/ConfirmRemovalForm.php @@ -16,6 +16,6 @@ class ConfirmRemovalForm extends Form public function init() { $this->setName('form_confirm_removal'); - $this->setSubmitLabel($this->translate('Confirm Removal')); + $this->getSubmitLabel() ?: $this->setSubmitLabel($this->translate('Confirm Removal')); } } From 902c00e836fad029ee2279f1712e31abf382779a Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Tue, 19 May 2015 17:29:34 +0200 Subject: [PATCH 15/15] lib: Introduce Controller::httpNotFound() Many actions require loading specific objects from database or any other storage. If the object isn't found, Controller::httpNotFound($message) should be used for immediately returning w/ HTTP 404. --- library/Icinga/Web/Controller.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) 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 *
translate('Last Problem'); ?>translate('Last Problem'); ?> translate('Host Group'); ?> translate('Total Hosts'); ?> translate('Host States'); ?>