Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
monitoring: Use the state badges widget for the host summary
refs #5543
- Loading branch information
Showing
2 changed files
with
85 additions
and
162 deletions.
There are no files selected for viewing
243 changes: 84 additions & 159 deletions
243
modules/monitoring/application/views/scripts/list/components/hostssummary.phtml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,164 +1,89 @@ | ||
<?php | ||
use Icinga\Module\Monitoring\Web\Widget\StateBadges; | ||
|
||
use Icinga\Web\Url; | ||
use Icinga\Data\Filter\Filter; | ||
|
||
$this->baseFilter = isset($this->baseFilter) ? $this->baseFilter : null; | ||
|
||
// don't fetch rows until they are actually needed to improve dashlet performance | ||
if (!$stats instanceof stdClass) { | ||
// Don't fetch rows until they are actually needed to improve dashlet performance | ||
if (! $stats instanceof stdClass) { | ||
$stats = $stats->fetchRow(); | ||
} | ||
|
||
$selfUrl = 'monitoring/list/hosts'; | ||
$currentUrl = Url::fromRequest()->getRelativeUrl(); | ||
?> | ||
<?= $this->qlink( | ||
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', $stats->hosts_total), | ||
$stats->hosts_total | ||
)) | ||
) ?>: | ||
<span class="badges"> | ||
<?php if ($stats->hosts_up): ?> | ||
<span class="state ok<?= $currentUrl === Url::fromPath($selfUrl, array('host_state' => 0))->getRelativeUrl() ? ' active' : ''; ?>"> | ||
<?= $this->qlink( | ||
$stats->hosts_up, | ||
Url::urlAddFilterOptional( | ||
$selfUrl, | ||
Filter::where('host_state', 0), | ||
$this->baseFilter | ||
), | ||
null, | ||
array('title' => sprintf( | ||
$this->translatePlural( | ||
'List %u host that is currently in state UP', | ||
'List %u hosts which are currently in state UP', | ||
$stats->hosts_up | ||
), | ||
$stats->hosts_up | ||
) | ||
) | ||
); ?> | ||
</span> | ||
<?php endif; ?> | ||
|
||
<?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( | ||
$stats->hosts_down_unhandled, | ||
Url::urlAddFilterOptional( | ||
$selfUrl, | ||
Filter::matchAll(Filter::where('host_state', 1), Filter::where('host_unhandled', 1)), | ||
$this->baseFilter | ||
), | ||
null, | ||
array('title' => sprintf( | ||
$this->translatePlural( | ||
'List %u host that is currently in state DOWN', | ||
'List %u hosts which are currently in state DOWN', | ||
$stats->hosts_down_unhandled | ||
), | ||
$stats->hosts_down_unhandled | ||
)) | ||
); ?> | ||
<?php endif; ?> | ||
|
||
<?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( | ||
$stats->hosts_down_handled, | ||
Url::urlAddFilterOptional( | ||
$selfUrl, | ||
Filter::matchAll(Filter::where('host_state', 1), Filter::where('host_unhandled', 0)), | ||
$this->baseFilter | ||
), | ||
null, | ||
array('title' => sprintf( | ||
$this->translatePlural( | ||
'List %u host that is currently in state DOWN (Acknowledged)', | ||
'List %u hosts which are currently in state DOWN (Acknowledged)', | ||
$stats->hosts_down_handled | ||
), | ||
$stats->hosts_down_handled | ||
)) | ||
); ?> | ||
</span> | ||
<?php endif; ?> | ||
|
||
<?php if($stats->hosts_down): ?> | ||
</span> | ||
<?php endif; ?> | ||
|
||
<?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( | ||
$stats->hosts_unreachable_unhandled, | ||
Url::urlAddFilterOptional( | ||
$selfUrl, | ||
Filter::matchAll(Filter::where('host_state', 2), Filter::where('host_unhandled', 1)), | ||
$this->baseFilter | ||
), | ||
null, | ||
array('title' => sprintf( | ||
$this->translatePlural( | ||
'List %u host that is currently in state UNREACHABLE', | ||
'List %u hosts which are currently in state UNREACHABLE', | ||
$stats->hosts_unreachable_unhandled | ||
), | ||
$stats->hosts_unreachable_unhandled | ||
)) | ||
); ?> | ||
<?php endif; ?> | ||
|
||
<?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( | ||
$stats->hosts_unreachable_handled, | ||
Url::urlAddFilterOptional( | ||
$selfUrl, | ||
Filter::matchAll(Filter::where('host_state', 2), Filter::where('host_unhandled', 0)), | ||
$this->baseFilter | ||
), | ||
null, | ||
array('title' => sprintf( | ||
$this->translatePlural( | ||
'List %u host that is currently in state UNREACHABLE (Acknowledged)', | ||
'List %u hosts which are currently in state UNREACHABLE (Acknowledged)', | ||
$stats->hosts_unreachable_handled | ||
), | ||
$stats->hosts_unreachable_handled | ||
)) | ||
); ?> | ||
</span> | ||
<?php endif; ?> | ||
|
||
<?php if($stats->hosts_unreachable): ?> | ||
</span> | ||
<?php endif; ?> | ||
|
||
<?php if($stats->hosts_pending): ?> | ||
<span class="state pending<?= $currentUrl === Url::fromPath($selfUrl, array('host_state' => 99))->getRelativeUrl() ? ' active' : ''; ?>"> | ||
<?= $this->qlink( | ||
$stats->hosts_pending, | ||
Url::urlAddFilterOptional( | ||
$selfUrl, | ||
Filter::where('host_state', 99), | ||
$this->baseFilter | ||
), | ||
null, | ||
array('title' => sprintf( | ||
$this->translatePlural( | ||
'List %u host that is currently in state PENDING', | ||
'List %u hosts which are currently in state PENDING', | ||
$stats->hosts_pending | ||
), | ||
$stats->hosts_pending | ||
)) | ||
); ?> | ||
</span> | ||
<?php endif; ?> | ||
</span> | ||
<div> | ||
<?= $this->qlink( | ||
sprintf($this->translatePlural('%u Host', '%u Hosts', $stats->hosts_total), $stats->hosts_total), | ||
'monitoring/list/hosts', | ||
null, | ||
array('title' => sprintf( | ||
$this->translatePlural('List %u host', 'List all %u hosts', $stats->hosts_total), | ||
$stats->hosts_total | ||
)) | ||
) ?>: | ||
<?php | ||
$stateBadges = new StateBadges(); | ||
$stateBadges | ||
->setUrl('monitoring/list/hosts') | ||
->add( | ||
StateBadges::STATE_UP, | ||
$stats->hosts_up, | ||
array( | ||
'host_state' => 0 | ||
), | ||
'List %u host that is currently in state UP', | ||
'List %u hosts which are currently in state UP', | ||
array($stats->hosts_up) | ||
) | ||
->add( | ||
StateBadges::STATE_DOWN, | ||
$stats->hosts_down_unhandled, | ||
array( | ||
'host_state' => 1, | ||
'host_handled' => 0 | ||
), | ||
'List %u host that is currently in state DOWN', | ||
'List %u hosts which are currently in state DOWN', | ||
array($stats->hosts_down_unhandled) | ||
) | ||
->add( | ||
StateBadges::STATE_DOWN_HANDLED, | ||
$stats->hosts_down_handled, | ||
array( | ||
'host_state' => 1, | ||
'host_handled' => 1 | ||
), | ||
'List %u host that is currently in state DOWN (Acknowledged)', | ||
'List %u hosts which are currently in state DOWN (Acknowledged)', | ||
array($stats->hosts_down_handled) | ||
) | ||
->add( | ||
StateBadges::STATE_UNREACHABLE, | ||
$stats->hosts_unreachable_unhandled, | ||
array( | ||
'host_state' => 2, | ||
'host_handled' => 0 | ||
), | ||
'List %u host that is currently in state UNREACHABLE', | ||
'List %u hosts which are currently in state UNREACHABLE', | ||
array($stats->hosts_unreachable_unhandled) | ||
) | ||
->add( | ||
StateBadges::STATE_UNREACHABLE_HANDLED, | ||
$stats->hosts_unreachable_handled, | ||
array( | ||
'host_state' => 2, | ||
'host_handled' => 1 | ||
), | ||
'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"', | ||
array($stats->hosts_unreachable_handled) | ||
) | ||
->add( | ||
StateBadges::STATE_PENDING, | ||
$stats->hosts_pending, | ||
array( | ||
'host_state' => 99 | ||
), | ||
'List %u host that is currently in state UNREACHABLE (Acknowledged)', | ||
'List %u hosts which are currently in state UNREACHABLE (Acknowledged)', | ||
array($stats->hosts_pending) | ||
); | ||
echo $stateBadges->render(); | ||
?> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters