From 67e31c730af109f3f1b1cc4fd9a4fe8788cea069 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Tue, 23 Jun 2015 08:49:11 +0200 Subject: [PATCH] Fetch host and service statistics not until they are required fixes #9472 --- .../controllers/ListController.php | 4 +- .../list/components/hostssummary.phtml | 60 ++++++++++--------- .../list/components/servicesummary.phtml | 51 ++++++++-------- 3 files changed, 59 insertions(+), 56 deletions(-) diff --git a/modules/monitoring/application/controllers/ListController.php b/modules/monitoring/application/controllers/ListController.php index 7399487ea..fe65fe595 100644 --- a/modules/monitoring/application/controllers/ListController.php +++ b/modules/monitoring/application/controllers/ListController.php @@ -111,7 +111,7 @@ class Monitoring_ListController extends Controller 'hosts_pending', )); $this->applyRestriction('monitoring/filter/objects', $stats); - $this->view->stats = $stats->fetchRow(); + $this->view->stats = $stats; $this->setupLimitControl(); $this->setupPaginationControl($this->view->hosts); $this->setupSortControl(array( @@ -214,7 +214,7 @@ class Monitoring_ListController extends Controller 'services_warning_unhandled' )); $this->applyRestriction('monitoring/filter/objects', $stats); - $this->view->stats = $stats->fetchRow(); + $this->view->stats = $stats; } /** diff --git a/modules/monitoring/application/views/scripts/list/components/hostssummary.phtml b/modules/monitoring/application/views/scripts/list/components/hostssummary.phtml index 58d410a0d..22f84b583 100644 --- a/modules/monitoring/application/views/scripts/list/components/hostssummary.phtml +++ b/modules/monitoring/application/views/scripts/list/components/hostssummary.phtml @@ -12,23 +12,25 @@ function urlAddFilterOptional($url, $filter, $optional) { return $url->setQueryString($f->toQueryString()); } $this->baseFilter = isset($this->baseFilter) ? $this->baseFilter : null; + +$stats = $stats->fetchRow(); $selfUrl = 'monitoring/list/hosts'; $currentUrl = Url::fromRequest()->getRelativeUrl(); ?>

compact ? ' data-base-target="col1"' : ''; ?>> qlink( - sprintf($this->translatePlural('%u Host', '%u Hosts', $this->stats->hosts_total), $this->stats->hosts_total), + sprintf($this->translatePlural('%u Host', '%u Hosts', $stats->hosts_total), $stats->hosts_total), $selfUrl, null, array('title' => sprintf( - $this->translatePlural('List %u host', 'List all %u hosts', $this->stats->hosts_total), - $this->stats->hosts_total + $this->translatePlural('List %u host', 'List all %u hosts', $stats->hosts_total), + $stats->hosts_total )) ) ?>: - stats->hosts_up): ?> + hosts_up): ?> qlink( - $this->stats->hosts_up, + $stats->hosts_up, urlAddFilterOptional( $selfUrl, Filter::where('host_state', 0), @@ -39,19 +41,19 @@ $currentUrl = Url::fromRequest()->getRelativeUrl(); $this->translatePlural( 'List %u host that is currently in state UP', 'List %u hosts which are currently in state UP', - $this->stats->hosts_up + $stats->hosts_up ), - $this->stats->hosts_up + $stats->hosts_up ) ) ); ?> - stats->hosts_down_unhandled): ?> + hosts_down_unhandled): ?> qlink( - $this->stats->hosts_down_unhandled, + $stats->hosts_down_unhandled, urlAddFilterOptional( $selfUrl, Filter::matchAll(Filter::where('host_state', 1), Filter::where('host_unhandled', 1)), @@ -62,17 +64,17 @@ $currentUrl = Url::fromRequest()->getRelativeUrl(); $this->translatePlural( 'List %u host that is currently in state DOWN', 'List %u hosts which are currently in state DOWN', - $this->stats->hosts_down_unhandled + $stats->hosts_down_unhandled ), - $this->stats->hosts_down_unhandled + $stats->hosts_down_unhandled )) ); ?> - stats->hosts_down_handled): ?> + hosts_down_handled): ?> qlink( - $this->stats->hosts_down_handled, + $stats->hosts_down_handled, urlAddFilterOptional( $selfUrl, Filter::matchAll(Filter::where('host_state', 1), Filter::where('host_unhandled', 0)), @@ -83,22 +85,22 @@ $currentUrl = Url::fromRequest()->getRelativeUrl(); $this->translatePlural( 'List %u host that is currently in state DOWN (Acknowledged)', 'List %u hosts which are currently in state DOWN (Acknowledged)', - $this->stats->hosts_down_handled + $stats->hosts_down_handled ), - $this->stats->hosts_down_handled + $stats->hosts_down_handled )) ); ?> - stats->hosts_down): ?> + hosts_down): ?> - stats->hosts_unreachable_unhandled): ?> + hosts_unreachable_unhandled): ?> qlink( - $this->stats->hosts_unreachable_unhandled, + $stats->hosts_unreachable_unhandled, urlAddFilterOptional( $selfUrl, Filter::matchAll(Filter::where('host_state', 2), Filter::where('host_unhandled', 1)), @@ -109,17 +111,17 @@ $currentUrl = Url::fromRequest()->getRelativeUrl(); $this->translatePlural( 'List %u host that is currently in state UNREACHABLE', 'List %u hosts which are currently in state UNREACHABLE', - $this->stats->hosts_unreachable_unhandled + $stats->hosts_unreachable_unhandled ), - $this->stats->hosts_unreachable_unhandled + $stats->hosts_unreachable_unhandled )) ); ?> - stats->hosts_unreachable_handled > 0): ?> + hosts_unreachable_handled > 0): ?> qlink( - $this->stats->hosts_unreachable_handled, + $stats->hosts_unreachable_handled, urlAddFilterOptional( $selfUrl, Filter::matchAll(Filter::where('host_state', 2), Filter::where('host_unhandled', 0)), @@ -130,22 +132,22 @@ $currentUrl = Url::fromRequest()->getRelativeUrl(); $this->translatePlural( 'List %u host that is currently in state UNREACHABLE (Acknowledged)', 'List %u hosts which are currently in state UNREACHABLE (Acknowledged)', - $this->stats->hosts_unreachable_handled + $stats->hosts_unreachable_handled ), - $this->stats->hosts_unreachable_handled + $stats->hosts_unreachable_handled )) ); ?> - stats->hosts_unreachable): ?> + hosts_unreachable): ?> - stats->hosts_pending): ?> + hosts_pending): ?> qlink( - $this->stats->hosts_pending, + $stats->hosts_pending, urlAddFilterOptional( $selfUrl, Filter::where('host_state', 99), @@ -156,9 +158,9 @@ $currentUrl = Url::fromRequest()->getRelativeUrl(); $this->translatePlural( 'List %u host that is currently in state PENDING', 'List %u hosts which are currently in state PENDING', - $this->stats->hosts_pending + $stats->hosts_pending ), - $this->stats->hosts_pending + $stats->hosts_pending )) ); ?> diff --git a/modules/monitoring/application/views/scripts/list/components/servicesummary.phtml b/modules/monitoring/application/views/scripts/list/components/servicesummary.phtml index 3406cb088..9fd798a0d 100644 --- a/modules/monitoring/application/views/scripts/list/components/servicesummary.phtml +++ b/modules/monitoring/application/views/scripts/list/components/servicesummary.phtml @@ -14,36 +14,37 @@ function urlAddFilterOptional($url, $filter, $optional) { } $this->baseFilter = isset($this->baseFilter) ? $this->baseFilter : null; +$stats = $stats->fetchRow(); $selfUrl = 'monitoring/list/services'; $currentUrl = Url::fromRequest()->getRelativeUrl(); ?>

compact ? ' data-base-target="col1"' : ''; ?>> qlink( sprintf($this->translatePlural( - '%u Service', '%u Services', $this->stats->services_total), - $this->stats->services_total + '%u Service', '%u Services', $stats->services_total), + $stats->services_total ), $selfUrl, null, array('title' => sprintf( - $this->translatePlural('List %u service', 'List all %u services', $this->stats->services_total), - $this->stats->services_total + $this->translatePlural('List %u service', 'List all %u services', $stats->services_total), + $stats->services_total )) ) ?>: -stats->services_ok): ?> +services_ok): ?> qlink( - $this->stats->services_ok, + $stats->services_ok, urlAddFilterOptional($selfUrl, Filter::where('service_state', 0), $this->baseFilter), null, array('title' => sprintf( $this->translatePlural( 'List %u service that is currently in state OK', 'List %u services which are currently in state OK', - $this->stats->services_ok + $stats->services_ok ), - $this->stats->services_ok + $stats->services_ok )) ); ?> @@ -52,7 +53,7 @@ $currentUrl = Url::fromRequest()->getRelativeUrl(); 'critical', 3 => 'unknown', 1 => 'warning') as $stateId => $state) { $pre = 'services_' . $state; - if ($this->stats->$pre) { + if ($stats->$pre) { $handled = $pre . '_handled'; $unhandled = $pre . '_unhandled'; $paramsHandled = Filter::matchAll( @@ -63,7 +64,7 @@ foreach (array(2 => 'critical', 3 => 'unknown', 1 => 'warning') as $stateId => $ Filter::where('service_state', $stateId), Filter::where('service_handled', 0) ); - if ($this->stats->$unhandled) { + if ($stats->$unhandled) { $compareUrl = Url::fromPath($selfUrl)->setQueryString($paramsUnhandled->toQueryString())->getRelativeUrl(); } else { $compareUrl = Url::fromPath($selfUrl)->setQueryString($paramsUnhandled->toQueryString())->getRelativeUrl(); @@ -75,49 +76,49 @@ foreach (array(2 => 'critical', 3 => 'unknown', 1 => 'warning') as $stateId => $ $active = ''; } - echo ''; - if ($this->stats->$unhandled) { + echo ''; + if ($stats->$unhandled) { echo $this->qlink( - $this->stats->$unhandled, + $stats->$unhandled, urlAddFilterOptional($selfUrl, $paramsUnhandled, $this->baseFilter), null, array('title' => sprintf( $this->translatePlural( 'List %u service that is currently in state %s', 'List %u services which are currently in state %s', - $this->stats->$unhandled + $stats->$unhandled ), - $this->stats->$unhandled, + $stats->$unhandled, Service::getStateText($stateId, true) )) ); } - if ($this->stats->$handled) { + if ($stats->$handled) { if (Url::fromPath($selfUrl)->setQueryString($paramsHandled->toQueryString())->getRelativeUrl() === $currentUrl) { $active = ' active'; } else { $active = ''; } - if ($this->stats->$unhandled) { + if ($stats->$unhandled) { echo ''; } echo $this->qlink( - $this->stats->$handled, + $stats->$handled, urlAddFilterOptional($selfUrl, $paramsHandled, $this->baseFilter), null, array('title' => sprintf( $this->translatePlural( 'List %u service that is currently in state %s (Acknowledged)', 'List %u services which are currently in state %s (Acknowledged)', - $this->stats->$handled + $stats->$handled ), - $this->stats->$handled, + $stats->$handled, Service::getStateText($stateId, true) )) ); - if ($this->stats->$unhandled) { + if ($stats->$unhandled) { echo "\n"; } } @@ -125,19 +126,19 @@ foreach (array(2 => 'critical', 3 => 'unknown', 1 => 'warning') as $stateId => $ } } ?> -stats->services_pending): ?> +services_pending): ?> qlink( - $this->stats->services_pending, + $stats->services_pending, urlAddFilterOptional($selfUrl, Filter::where('service_state', 99), $this->baseFilter), null, array('title' => sprintf( $this->translatePlural( 'List %u service that is currently in state PENDING', 'List %u services which are currently in state PENDING', - $this->stats->services_pending + $stats->services_pending ), - $this->stats->services_pending + $stats->services_pending )) ); ?>