Skip to content

Commit

Permalink
monitoring: Use the state badges widget for the host summary
Browse files Browse the repository at this point in the history
refs #5543
  • Loading branch information
lippserd committed Sep 29, 2015
1 parent 646d793 commit 29e66c3
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 162 deletions.
@@ -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
))
) ?>&#58;
<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
))
) ?>&#58;
<?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>
Expand Up @@ -6,9 +6,7 @@ if (! $this->compact): ?>
<?= $this->tabs ?>
<div class="dontprint">
<?= $this->render('list/components/selectioninfo.phtml') ?>
<h2 class="tinystatesummary" <?= $this->compact ? ' data-base-target="col1"' : '' ?>>
<?= $this->render('list/components/hostssummary.phtml') ?>
</h2>
<?= $this->render('list/components/hostssummary.phtml') ?>
</div>
<?= $this->sortBox ?>
<?= $this->limiter ?>
Expand Down

0 comments on commit 29e66c3

Please sign in to comment.