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 if ($stats->services_ok): ?>
<span class="state ok<?= $currentUrl === Url::fromPath($selfUrl, array('service_state' => 0))->getRelativeUrl() ? ' active' : ''; ?>">
<?=
$this->qlink(
$stats->services_ok,
Url::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',
$stats->services_ok
),
$stats->services_ok
))
);
?>
</span>
<?php endif ?>
<?php <?php
foreach (array(2 => 'critical', 3 => 'unknown', 1 => 'warning') as $stateId => $state) { $stateBadges = new StateBadges();
$pre = 'services_' . $state; $stateBadges
if ($stats->$pre) { ->setUrl('monitoring/list/services')
$handled = $pre . '_handled'; ->add(
$unhandled = $pre . '_unhandled'; StateBadges::STATE_OK,
$paramsHandled = Filter::matchAll( $stats->services_ok,
Filter::where('service_state', $stateId), array(
Filter::where('service_handled', 1) 'service_state' => 0
); ),
$paramsUnhandled = Filter::matchAll( 'List %u service that is currently in state OK',
Filter::where('service_state', $stateId), 'List %u services which are currently in state OK',
Filter::where('service_handled', 0) array($stats->services_ok)
); )
if ($stats->$unhandled) { ->add(
$compareUrl = Url::fromPath($selfUrl)->setQueryString($paramsUnhandled->toQueryString())->getRelativeUrl(); StateBadges::STATE_CRITICAL,
} else { $stats->services_critical_unhandled,
$compareUrl = Url::fromPath($selfUrl)->setQueryString($paramsUnhandled->toQueryString())->getRelativeUrl(); array(
} 'service_state' => 2,
'service_handled' => 0
),
'List %u service that is currently in state CRITICAL',
'List %u services which are currently in state CRITICAL',
array($stats->services_critical_unhandled)
)
->add(
StateBadges::STATE_CRITICAL_HANDLED,
$stats->services_critical_handled,
array(
'service_state' => 2,
'service_handled' => 1
),
'List %u handled service that is currently in state CRITICAL',
'List %u handled services which are currently in state CRITICAL',
array($stats->services_critical_unhandled)
)
->add(
StateBadges::STATE_UNKNOWN,
$stats->services_unknown_unhandled,
array(
'service_state' => 3,
'service_handled' => 0
),
'List %u service that is currently in state UNKNOWN',
'List %u services which are currently in state UNKNOWN',
array($stats->services_unknown_unhandled)
)
->add(
StateBadges::STATE_UNKNOWN_HANDLED,
$stats->services_unknown_handled,
array(
'service_state' => 3,
'service_handled' => 1
),
'List %u handled service that is currently in state UNKNOWN',
'List %u handled services which are currently in state UNKNOWN',
array($stats->services_unknown_handled)
if ($compareUrl === $currentUrl) { )
$active = ' active'; ->add(
} else { StateBadges::STATE_WARNING,
$active = ''; $stats->services_warning_unhandled,
} array(
'service_state' => 1,
echo '<span class="state ' . $state . $active . ($stats->$unhandled ? '' : ' handled') . '">'; 'service_handled' => 0
if ($stats->$unhandled) { ),
'List %u service that is currently in state WARNING',
echo $this->qlink( 'List %u services which are currently in state WARNING',
$stats->$unhandled, array($stats->services_warning_unhandled)
Url::urlAddFilterOptional($selfUrl, $paramsUnhandled, $this->baseFilter), )
null, ->add(
array('title' => sprintf( StateBadges::STATE_WARNING_HANDLED,
$this->translatePlural( $stats->services_warning_handled,
'List %u service that is currently in state %s', array(
'List %u services which are currently in state %s', 'service_state' => 1,
$stats->$unhandled 'service_handled' => 1
), ),
$stats->$unhandled, 'List %u handled service that is currently in state WARNING',
Service::getStateText($stateId, true) 'List %u handled services which are currently in state WARNING',
)) array($stats->services_warning_handled)
); )
} ->add(
if ($stats->$handled) { StateBadges::STATE_PENDING,
if (Url::fromPath($selfUrl)->setQueryString($paramsHandled->toQueryString())->getRelativeUrl() === $currentUrl) {
$active = ' active';
} else {
$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,
Service::getStateText($stateId, true)
))
);
if ($stats->$unhandled) {
echo "</span>\n";
}
}
echo "</span>\n";
}
}
?>
<?php if ($stats->services_pending): ?>
<span class="state pending<?= $currentUrl === Url::fromPath($selfUrl, array('service_state' => 99))->getRelativeUrl() ? ' active' : ''; ?>">
<?= $this->qlink(
$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 handled service that is currently in state PENDING',
'List %u service that is currently in state PENDING', 'List %u handled services which are currently in state PENDING',
'List %u services which are currently in state PENDING', array($stats->services_pending)
$stats->services_pending );
), echo $stateBadges->render();
$stats->services_pending ?>
)) </div>
); ?>
</span>
<?php endif ?>
</span>