Fetch host and service statistics not until they are required
fixes #9472
This commit is contained in:
parent
eabcb6702f
commit
67e31c730a
|
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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();
|
||||
?><h1 class="tinystatesummary" <?= $this->compact ? ' data-base-target="col1"' : ''; ?>>
|
||||
<?= $this->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
|
||||
))
|
||||
) ?>:
|
||||
<span class="badges">
|
||||
<?php if ($this->stats->hosts_up): ?>
|
||||
<?php if ($stats->hosts_up): ?>
|
||||
<span class="state ok<?= $currentUrl === Url::fromPath($selfUrl, array('host_state' => 0))->getRelativeUrl() ? ' active' : ''; ?>">
|
||||
<?= $this->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
|
||||
)
|
||||
)
|
||||
); ?>
|
||||
</span>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if ($this->stats->hosts_down_unhandled): ?>
|
||||
<?php if ($stats->hosts_down_unhandled): ?>
|
||||
<span class="state critical<?= $currentUrl === Url::fromPath($selfUrl, array('host_state' => 1, 'host_unhandled' => 1))->getRelativeUrl() ? ' active' : ''; ?>">
|
||||
<?= $this->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
|
||||
))
|
||||
); ?>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if ($this->stats->hosts_down_handled): ?>
|
||||
<?php if ($stats->hosts_down_handled): ?>
|
||||
<span class="state handled critical<?= $currentUrl === Url::fromPath($selfUrl, array('host_state' => 1, 'host_unhandled' =>0))->getRelativeUrl() ? ' active' : ''; ?>">
|
||||
<?= $this->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
|
||||
))
|
||||
); ?>
|
||||
</span>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if($this->stats->hosts_down): ?>
|
||||
<?php if($stats->hosts_down): ?>
|
||||
</span>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if($this->stats->hosts_unreachable_unhandled): ?>
|
||||
<?php if($stats->hosts_unreachable_unhandled): ?>
|
||||
<span class="state unknown<?= $currentUrl === Url::fromPath($selfUrl, array('host_state' => 2, 'host_unhandled' => 1))->getRelativeUrl() ? ' active' : ''; ?>">
|
||||
<?= $this->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
|
||||
))
|
||||
); ?>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if($this->stats->hosts_unreachable_handled > 0): ?>
|
||||
<?php if($stats->hosts_unreachable_handled > 0): ?>
|
||||
<span class="state handled unknown<?= $currentUrl === Url::fromPath($selfUrl, array('host_state' => 2, 'host_unhandled' => 0))->getRelativeUrl() ? ' active' : '' ?>">
|
||||
<?= $this->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
|
||||
))
|
||||
); ?>
|
||||
</span>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if($this->stats->hosts_unreachable): ?>
|
||||
<?php if($stats->hosts_unreachable): ?>
|
||||
</span>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if($this->stats->hosts_pending): ?>
|
||||
<?php if($stats->hosts_pending): ?>
|
||||
<span class="state pending<?= $currentUrl === Url::fromPath($selfUrl, array('host_state' => 99))->getRelativeUrl() ? ' active' : ''; ?>">
|
||||
<?= $this->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
|
||||
))
|
||||
); ?>
|
||||
</span>
|
||||
|
|
|
@ -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();
|
||||
?><h1 class="tinystatesummary" <?= $this->compact ? ' data-base-target="col1"' : ''; ?>>
|
||||
<?= $this->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
|
||||
))
|
||||
) ?>:
|
||||
<span class="badges">
|
||||
<?php if ($this->stats->services_ok): ?>
|
||||
<?php if ($stats->services_ok): ?>
|
||||
<span class="state ok<?= $currentUrl === Url::fromPath($selfUrl, array('service_state' => 0))->getRelativeUrl() ? ' active' : ''; ?>">
|
||||
<?=
|
||||
$this->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();
|
|||
<?php
|
||||
foreach (array(2 => '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 '<span class="state ' . $state . $active . ($this->stats->$unhandled ? '' : ' handled') . '">';
|
||||
if ($this->stats->$unhandled) {
|
||||
echo '<span class="state ' . $state . $active . ($stats->$unhandled ? '' : ' handled') . '">';
|
||||
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 '<span class="state handled ' . $state . $active . '">';
|
||||
}
|
||||
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 "</span>\n";
|
||||
}
|
||||
}
|
||||
|
@ -125,19 +126,19 @@ foreach (array(2 => 'critical', 3 => 'unknown', 1 => 'warning') as $stateId => $
|
|||
}
|
||||
}
|
||||
?>
|
||||
<?php if ($this->stats->services_pending): ?>
|
||||
<?php if ($stats->services_pending): ?>
|
||||
<span class="state pending<?= $currentUrl === Url::fromPath($selfUrl, array('service_state' => 99))->getRelativeUrl() ? ' active' : ''; ?>">
|
||||
<?= $this->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
|
||||
))
|
||||
); ?>
|
||||
</span>
|
||||
|
|
Loading…
Reference in New Issue