list/hosts: cleanup, should look like list/services

Quite some changes here:

* Compact view should show icons too
* Ignore host icons with legacy HTML hacks
* Remove duplicate code
* Reduce HTML
* Reduce intendation for better readability
* Show attempts on soft states only, even in compact view
* Use the same HTML tags and styles as in list/services
* Fixes nesting error on compact view
This commit is contained in:
Thomas Gelf 2014-08-22 11:06:45 +02:00
parent 09412d03b6
commit 49cd55eddd

View File

@ -1,27 +1,31 @@
<?php <?php
$helper = $this->getHelper('MonitoringState'); $helper = $this->getHelper('MonitoringState');
if (! $this->compact): ?> if ($this->compact): ?>
<div class="controls"> <div class="content">
<?= $this->tabs ?> <?php else: ?>
<div style="margin: 1em;" class="dontprint"> <div class="controls">
<?= $this->translate('Sort by') ?> <?= $this->sortControl->render($this) ?> <?= $this->tabs ?>
<?php if (! $this->filterEditor): ?> <div style="margin: 1em;" class="dontprint">
<?= $this->filterPreview ?> <?= $this->translate('Sort by') ?> <?= $this->sortControl->render($this) ?>
<?php endif; ?> <?php if (! $this->filterEditor): ?>
</div> <?= $this->filterPreview ?>
<?php endif; ?>
</div>
<?= $this->widget('limiter')->setMaxLimit($this->hosts->count()) ?> <?= $this->widget('limiter')->setMaxLimit($this->hosts->count()) ?>
<?= $this->paginationControl($hosts, null, null, array('preserve' => $this->preserve)) ?> <?= $this->paginationControl($hosts, null, null, array('preserve' => $this->preserve)) ?>
<?= $this->selectionToolbar('multi', $this->href('monitoring/multi/host?' . $this->filter->toQueryString())) ?> <?= $this->selectionToolbar('multi', $this->href('monitoring/multi/host?' . $this->filter->toQueryString())) ?>
</div> </div>
<div class="content">
<?= $this->filterEditor ?> <div class="content">
<?= $this->filterEditor ?>
<?php <?php
endif; endif;
if ($hosts->count() === 0) { if ($hosts->count() === 0) {
echo t('No hosts matching the filter'); echo $this->translate('No hosts matching the filter');
if (! $this->compact) { if (! $this->compact) {
echo '</div>'; echo '</div>';
} }
@ -32,107 +36,90 @@ if ($hosts->count() === 0) {
<table <table
data-base-target="_next" data-base-target="_next"
class="action multiselect" class="action multiselect"
data-icinga-multiselect-url="<?= $this->href("/monitoring/multi/host") ?>" data-icinga-multiselect-url="<?= $this->href('/monitoring/multi/host') ?>"
data-icinga-multiselect-data="host" data-icinga-multiselect-data="host"
> >
<tbody> <tbody>
<?php foreach($hosts as $host): <?php foreach($hosts as $host):
$hostStateName = strtolower($this->util()->getHostStateName($host->host_state)); $hostStateName = strtolower($this->util()->getHostStateName($host->host_state));
$hostLink = $this->href('/monitoring/show/host', array('host' => $host->host_name)); $hostLink = $this->href('/monitoring/show/host', array('host' => $host->host_name));
if (! $this->compact) { $icons = array();
$icons = array(); if (! $host->host_handled && $host->host_state > 0){
if (! $host->host_handled && $host->host_state > 0){ $icons[] = $this->icon('unhandled.png', 'Unhandled');
$icons[] = $this->icon('unhandled.png', 'Unhandled'); }
}
if ($host->host_acknowledged) { if ($host->host_acknowledged) {
$icons[] = $this->icon('acknowledgement.png', 'Acknowledged'); $icons[] = $this->icon('acknowledgement.png', 'Acknowledged');
} }
if ($host->host_is_flapping) { if ($host->host_is_flapping) {
$icons[] = $this->icon('flapping.png', 'Flapping'); $icons[] = $this->icon('flapping.png', 'Flapping');
} }
if (! $host->host_notifications_enabled) { if (! $host->host_notifications_enabled) {
$icons[] = $this->icon('notification_disabled.png', 'Notifications Disabled'); $icons[] = $this->icon('notification_disabled.png', 'Notifications Disabled');
} }
if ($host->host_in_downtime) { if ($host->host_in_downtime) {
$icons[] = $this->icon('in_downtime.png', 'In Downtime'); $icons[] = $this->icon('in_downtime.png', 'In Downtime');
} }
if (! $host->host_active_checks_enabled) { if (! $host->host_active_checks_enabled) {
if (! $host->host_passive_checks_enabled) { if (! $host->host_passive_checks_enabled) {
$icons[] = $this->icon('active_passive_checks_disabled.png', 'Active And Passive Checks Disabled'); $icons[] = $this->icon('active_passive_checks_disabled.png', 'Active And Passive Checks Disabled');
} else { } else {
$icons[] = $this->icon('active_checks_disabled.png', 'Active Checks Disabled'); $icons[] = $this->icon('active_checks_disabled.png', 'Active Checks Disabled');
}
}
if (isset($host->host_last_comment) && $host->host_last_comment !== null) {
$icons[] = $this->icon('comment.png', 'Comment: ' . $host->host_last_comment);
}
} }
?> }
<tr class="state <?= $hostStateName ?><?= $host->host_handled ? ' handled' : '' ?>">
<!-- State -->
<td class="state" title="<?= $helper->getStateTitle($host, 'host') ?>">
<?php if (! $this->compact): ?>
<div>
<strong><?= ucfirst($helper->monitoringState($host, 'host')) ?></strong><br />
<div class="small-row">
<?php endif; ?>
<?= $this->prefixedTimeSince($host->host_last_state_change, true) ?>
<?php if (! $this->compact): ?>
<?php if ($host->host_state > 0): ?>
<br />
<strong><?= $this->translate(
($host->host_state_type === '1') ? 'Hard' : 'Soft'
) ?> </strong> <!--
--><?= $host->host_current_check_attempt ?>/<?= $host->host_max_check_attempts ?>
<?php endif; ?>
</div>
</div>
<?php endif; ?>
</td>
<!-- Host / Status / Output --> if (isset($host->host_last_comment) && $host->host_last_comment !== null) {
<td> $icons[] = $this->icon('comment.png', 'Comment: ' . $host->host_last_comment);
<?php if (! $this->compact): ?> }
<?php if ($host->host_icon_image): ?> ?>
<?= $this->img( <tr class="state <?= $hostStateName ?><?= $host->host_handled ? ' handled' : '' ?>">
$this->resolveMacros($host->host_icon_image, $host), <!-- State -->
array('align' => 'right') <td class="state" title="<?= $helper->getStateTitle($host, 'host') ?>">
) ?> <?php if (! $this->compact): ?>
<?php endif; ?> <strong><?= ucfirst($helper->monitoringState($host, 'host')) ?></strong><br />
<?= implode(' ', $icons) ?> <?php endif ?>
<?php endif ?> <?= $this->prefixedTimeSince($host->host_last_state_change, true) ?>
<a href="<?= $this->compact ? $hostLink : $this->href( <?php if ($host->host_state > 0 && (int) $host->host_state_type === 0): ?>
'monitoring/show/host', <br />
array('host' => $host->host_name) <strong>Soft <?= $host->host_attempt ?></strong>
) ?>"><?= $host->host_name ?></a> <?php endif ?>
<?php if (isset($host->host_unhandled_services) && $host->host_unhandled_services > 0): ?> </td>
<span style="font-weight: normal" title="<?=
$host->host_unhandled_services <!-- Host / Status / Output -->
?> Service Problems on Host"> (<?= $this->qlink( <td>
sprintf($this->translate('%d unhandled services'), $host->host_unhandled_services), <?php if ($host->host_icon_image && ! preg_match('/[\'"]/', $host->host_icon_image)): ?>
'monitoring/show/services', <?= $this->icon($this->resolveMacros($host->host_icon_image, $host)) ?>
array( <?php endif ?>
'host' => $host->host_name, <?= implode(' ', $icons) ?>
'service_problem' => 1, <a href="<?= $hostLink ?>"><?= $host->host_name ?></a>
'service_acknowledged' => 0, <?php if (isset($host->host_unhandled_services) && $host->host_unhandled_services > 0): ?>
'service_in_downtime' => 0 <span title="<?=
), $host->host_unhandled_services
array('style' => 'font-weight: normal') ?> Service Problems on Host"> (<?= $this->qlink(
) ?>)</span> sprintf($this->translate('%d unhandled services'), $host->host_unhandled_services),
<?php endif ?> 'monitoring/show/services',
<br /> array(
<?= $this->escape(substr(strip_tags($host->host_output), 0, 10000)) ?> 'host' => $host->host_name,
</td> 'service_problem' => 1,
</tr> 'service_acknowledged' => 0,
<?php endforeach; ?> 'service_in_downtime' => 0
</tbody> ),
array('style' => 'font-weight: normal')
) ?>)</span>
<?php endif ?>
<p class="pluginoutput"><?= $this->escape(substr(strip_tags($host->host_output), 0, 10000)) ?></p>
</td>
<?php foreach($this->extraColumns as $col): ?>
<td><?= $this->escape($host->$col) ?></td>
<?php endforeach ?>
</tr>
<?php endforeach ?>
</tbody>
</table> </table>
</div> </div>