monitoring: Use the state badges widget for the host summary

refs #5543
This commit is contained in:
Eric Lippmann 2015-09-29 15:26:34 +02:00
parent 646d7932de
commit 29e66c3f55
2 changed files with 85 additions and 162 deletions

View File

@ -1,164 +1,89 @@
<?php <?php
use Icinga\Module\Monitoring\Web\Widget\StateBadges;
use Icinga\Web\Url; // Don't fetch rows until they are actually needed to improve dashlet performance
use Icinga\Data\Filter\Filter; if (! $stats instanceof stdClass) {
$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) {
$stats = $stats->fetchRow(); $stats = $stats->fetchRow();
} }
$selfUrl = 'monitoring/list/hosts';
$currentUrl = Url::fromRequest()->getRelativeUrl();
?> ?>
<?= $this->qlink( <div>
sprintf($this->translatePlural('%u Host', '%u Hosts', $stats->hosts_total), $stats->hosts_total), <?= $this->qlink(
$selfUrl, sprintf($this->translatePlural('%u Host', '%u Hosts', $stats->hosts_total), $stats->hosts_total),
null, 'monitoring/list/hosts',
array('title' => sprintf( null,
$this->translatePlural('List %u host', 'List all %u hosts', $stats->hosts_total), array('title' => sprintf(
$stats->hosts_total $this->translatePlural('List %u host', 'List all %u hosts', $stats->hosts_total),
)) $stats->hosts_total
) ?>&#58; ))
<span class="badges"> ) ?>&#58;
<?php if ($stats->hosts_up): ?> <?php
<span class="state ok<?= $currentUrl === Url::fromPath($selfUrl, array('host_state' => 0))->getRelativeUrl() ? ' active' : ''; ?>"> $stateBadges = new StateBadges();
<?= $this->qlink( $stateBadges
$stats->hosts_up, ->setUrl('monitoring/list/hosts')
Url::urlAddFilterOptional( ->add(
$selfUrl, StateBadges::STATE_UP,
Filter::where('host_state', 0), $stats->hosts_up,
$this->baseFilter array(
), 'host_state' => 0
null, ),
array('title' => sprintf( 'List %u host that is currently in state UP',
$this->translatePlural( 'List %u hosts which are currently in state UP',
'List %u host that is currently in state UP', array($stats->hosts_up)
'List %u hosts which are currently in state UP', )
$stats->hosts_up ->add(
), StateBadges::STATE_DOWN,
$stats->hosts_up $stats->hosts_down_unhandled,
) array(
) 'host_state' => 1,
); ?> 'host_handled' => 0
</span> ),
<?php endif; ?> 'List %u host that is currently in state DOWN',
'List %u hosts which are currently in state DOWN',
<?php if ($stats->hosts_down_unhandled): ?> array($stats->hosts_down_unhandled)
<span class="state critical<?= $currentUrl === Url::fromPath($selfUrl, array('host_state' => 1, 'host_unhandled' => 1))->getRelativeUrl() ? ' active' : ''; ?>"> )
<?= $this->qlink( ->add(
$stats->hosts_down_unhandled, StateBadges::STATE_DOWN_HANDLED,
Url::urlAddFilterOptional( $stats->hosts_down_handled,
$selfUrl, array(
Filter::matchAll(Filter::where('host_state', 1), Filter::where('host_unhandled', 1)), 'host_state' => 1,
$this->baseFilter 'host_handled' => 1
), ),
null, 'List %u host that is currently in state DOWN (Acknowledged)',
array('title' => sprintf( 'List %u hosts which are currently in state DOWN (Acknowledged)',
$this->translatePlural( array($stats->hosts_down_handled)
'List %u host that is currently in state DOWN', )
'List %u hosts which are currently in state DOWN', ->add(
$stats->hosts_down_unhandled StateBadges::STATE_UNREACHABLE,
), $stats->hosts_unreachable_unhandled,
$stats->hosts_down_unhandled array(
)) 'host_state' => 2,
); ?> 'host_handled' => 0
<?php endif; ?> ),
'List %u host that is currently in state UNREACHABLE',
<?php if ($stats->hosts_down_handled): ?> 'List %u hosts which are currently in state UNREACHABLE',
<span class="state handled critical<?= $currentUrl === Url::fromPath($selfUrl, array('host_state' => 1, 'host_unhandled' =>0))->getRelativeUrl() ? ' active' : ''; ?>"> array($stats->hosts_unreachable_unhandled)
<?= $this->qlink( )
$stats->hosts_down_handled, ->add(
Url::urlAddFilterOptional( StateBadges::STATE_UNREACHABLE_HANDLED,
$selfUrl, $stats->hosts_unreachable_handled,
Filter::matchAll(Filter::where('host_state', 1), Filter::where('host_unhandled', 0)), array(
$this->baseFilter 'host_state' => 2,
), 'host_handled' => 1
null, ),
array('title' => sprintf( 'List %u host that is currently in state UNREACHABLE (Acknowledged) in the host group "%s"',
$this->translatePlural( 'List %u hosts which are currently in state UNREACHABLE (Acknowledged) in the host group "%s"',
'List %u host that is currently in state DOWN (Acknowledged)', array($stats->hosts_unreachable_handled)
'List %u hosts which are currently in state DOWN (Acknowledged)', )
$stats->hosts_down_handled ->add(
), StateBadges::STATE_PENDING,
$stats->hosts_down_handled $stats->hosts_pending,
)) array(
); ?> 'host_state' => 99
</span> ),
<?php endif; ?> 'List %u host that is currently in state UNREACHABLE (Acknowledged)',
'List %u hosts which are currently in state UNREACHABLE (Acknowledged)',
<?php if($stats->hosts_down): ?> array($stats->hosts_pending)
</span> );
<?php endif; ?> echo $stateBadges->render();
?>
<?php if($stats->hosts_unreachable_unhandled): ?> </div>
<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>

View File

@ -6,9 +6,7 @@ if (! $this->compact): ?>
<?= $this->tabs ?> <?= $this->tabs ?>
<div class="dontprint"> <div class="dontprint">
<?= $this->render('list/components/selectioninfo.phtml') ?> <?= $this->render('list/components/selectioninfo.phtml') ?>
<h2 class="tinystatesummary" <?= $this->compact ? ' data-base-target="col1"' : '' ?>> <?= $this->render('list/components/hostssummary.phtml') ?>
<?= $this->render('list/components/hostssummary.phtml') ?>
</h2>
</div> </div>
<?= $this->sortBox ?> <?= $this->sortBox ?>
<?= $this->limiter ?> <?= $this->limiter ?>