monitoring: Use state badges widget in the service summary (WIP)

- Lacks baseFilter handling

refs #5543
This commit is contained in:
Eric Lippmann 2015-09-29 17:05:42 +02:00
parent 2d9efc3467
commit 7704c9578c
1 changed files with 99 additions and 125 deletions

View File

@ -1,141 +1,115 @@
<?php <?php
use Icinga\Module\Monitoring\Web\Widget\StateBadges;
use Icinga\Data\Filter\Filter; // Don't fetch rows until they are actually needed, to improve dashlet performance
use Icinga\Web\Url; if (! $stats instanceof stdClass) {
use Icinga\Module\Monitoring\Object\Service;
$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/services'; ?>
$currentUrl = Url::fromRequest()->getRelativeUrl(); <div class="pull-left">
<?= $this->qlink(
echo $this->qlink(
sprintf($this->translatePlural( sprintf($this->translatePlural(
'%u Service', '%u Services', $stats->services_total), '%u Service', '%u Services', $stats->services_total),
$stats->services_total $stats->services_total
), ),
$selfUrl, 'monitoring/list/services',
null, null,
array('title' => sprintf( array('title' => sprintf(
$this->translatePlural('List %u service', 'List all %u services', $stats->services_total), $this->translatePlural('List %u service', 'List all %u services', $stats->services_total),
$stats->services_total $stats->services_total
)) ))
) ?>&#58; ) ?>&#58;
<span class="badges"> <?php
<?php if ($stats->services_ok): ?> $stateBadges = new StateBadges();
<span class="state ok<?= $currentUrl === Url::fromPath($selfUrl, array('service_state' => 0))->getRelativeUrl() ? ' active' : ''; ?>"> $stateBadges
<?= ->setUrl('monitoring/list/services')
$this->qlink( ->add(
StateBadges::STATE_OK,
$stats->services_ok, $stats->services_ok,
Url::urlAddFilterOptional($selfUrl, Filter::where('service_state', 0), $this->baseFilter), array(
null, 'service_state' => 0
array('title' => sprintf( ),
$this->translatePlural(
'List %u service that is currently in state OK', 'List %u service that is currently in state OK',
'List %u services which are currently in state OK', 'List %u services which are currently in state OK',
$stats->services_ok array($stats->services_ok)
)
->add(
StateBadges::STATE_CRITICAL,
$stats->services_critical_unhandled,
array(
'service_state' => 2,
'service_handled' => 0
), ),
$stats->services_ok 'List %u service that is currently in state CRITICAL',
)) 'List %u services which are currently in state CRITICAL',
); array($stats->services_critical_unhandled)
?> )
</span> ->add(
<?php endif ?> StateBadges::STATE_CRITICAL_HANDLED,
<?php $stats->services_critical_handled,
foreach (array(2 => 'critical', 3 => 'unknown', 1 => 'warning') as $stateId => $state) { array(
$pre = 'services_' . $state; 'service_state' => 2,
if ($stats->$pre) { 'service_handled' => 1
$handled = $pre . '_handled';
$unhandled = $pre . '_unhandled';
$paramsHandled = Filter::matchAll(
Filter::where('service_state', $stateId),
Filter::where('service_handled', 1)
);
$paramsUnhandled = Filter::matchAll(
Filter::where('service_state', $stateId),
Filter::where('service_handled', 0)
);
if ($stats->$unhandled) {
$compareUrl = Url::fromPath($selfUrl)->setQueryString($paramsUnhandled->toQueryString())->getRelativeUrl();
} else {
$compareUrl = Url::fromPath($selfUrl)->setQueryString($paramsUnhandled->toQueryString())->getRelativeUrl();
}
if ($compareUrl === $currentUrl) {
$active = ' active';
} else {
$active = '';
}
echo '<span class="state ' . $state . $active . ($stats->$unhandled ? '' : ' handled') . '">';
if ($stats->$unhandled) {
echo $this->qlink(
$stats->$unhandled,
Url::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',
$stats->$unhandled
), ),
$stats->$unhandled, 'List %u handled service that is currently in state CRITICAL',
Service::getStateText($stateId, true) 'List %u handled services which are currently in state CRITICAL',
)) array($stats->services_critical_unhandled)
); )
} ->add(
if ($stats->$handled) { StateBadges::STATE_UNKNOWN,
$stats->services_unknown_unhandled,
if (Url::fromPath($selfUrl)->setQueryString($paramsHandled->toQueryString())->getRelativeUrl() === $currentUrl) { array(
$active = ' active'; 'service_state' => 3,
} else { 'service_handled' => 0
$active = '';
}
if ($stats->$unhandled) {
echo '<span class="state handled ' . $state . $active . '">';
}
echo $this->qlink(
$stats->$handled,
Url::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)',
$stats->$handled
), ),
$stats->$handled, 'List %u service that is currently in state UNKNOWN',
Service::getStateText($stateId, true) 'List %u services which are currently in state UNKNOWN',
)) array($stats->services_unknown_unhandled)
); )
if ($stats->$unhandled) { ->add(
echo "</span>\n"; StateBadges::STATE_UNKNOWN_HANDLED,
} $stats->services_unknown_handled,
} array(
echo "</span>\n"; 'service_state' => 3,
} 'service_handled' => 1
} ),
?> 'List %u handled service that is currently in state UNKNOWN',
<?php if ($stats->services_pending): ?> 'List %u handled services which are currently in state UNKNOWN',
<span class="state pending<?= $currentUrl === Url::fromPath($selfUrl, array('service_state' => 99))->getRelativeUrl() ? ' active' : ''; ?>"> array($stats->services_unknown_handled)
<?= $this->qlink(
)
->add(
StateBadges::STATE_WARNING,
$stats->services_warning_unhandled,
array(
'service_state' => 1,
'service_handled' => 0
),
'List %u service that is currently in state WARNING',
'List %u services which are currently in state WARNING',
array($stats->services_warning_unhandled)
)
->add(
StateBadges::STATE_WARNING_HANDLED,
$stats->services_warning_handled,
array(
'service_state' => 1,
'service_handled' => 1
),
'List %u handled service that is currently in state WARNING',
'List %u handled services which are currently in state WARNING',
array($stats->services_warning_handled)
)
->add(
StateBadges::STATE_PENDING,
$stats->services_pending, $stats->services_pending,
Url::urlAddFilterOptional($selfUrl, Filter::where('service_state', 99), $this->baseFilter), array(
null, 'service_state' => 99
array('title' => sprintf(
$this->translatePlural(
'List %u service that is currently in state PENDING',
'List %u services which are currently in state PENDING',
$stats->services_pending
), ),
$stats->services_pending 'List %u handled service that is currently in state PENDING',
)) 'List %u handled services which are currently in state PENDING',
); ?> array($stats->services_pending)
</span> );
<?php endif ?> echo $stateBadges->render();
</span> ?>
</div>