Use the Host and Service object class helpers instead of MonitoringState

This also ensures that all state names that are shown to the user are
properly translated.

refs #7996
This commit is contained in:
Johannes Meyer 2014-12-12 10:38:21 +01:00
parent e63252cb04
commit 87664ffef9
5 changed files with 32 additions and 13 deletions

View File

@ -3,7 +3,7 @@
// {{{ICINGA_LICENSE_HEADER}}}
/**
* @deprecated Crap.
* @deprecated Most of these helpers are currently only used in the MultiController, which is probably obsolete
*/
class Zend_View_Helper_MonitoringState extends Zend_View_Helper_Abstract
{
@ -11,7 +11,7 @@ class Zend_View_Helper_MonitoringState extends Zend_View_Helper_Abstract
private $hoststates = array('up', 'down', 'unreachable', 99 => 'pending', null => 'pending');
/**
* @deprecated The host or service object must know it's possible states.
* @deprecated Not used anywhere.
*/
public function monitoringState($object, $type = 'service')
{
@ -22,6 +22,9 @@ class Zend_View_Helper_MonitoringState extends Zend_View_Helper_Abstract
}
}
/**
* @deprecated Not used anywhere.
*/
public function monitoringStateById($id, $type = 'service')
{
if ($type === 'service') {
@ -91,7 +94,7 @@ class Zend_View_Helper_MonitoringState extends Zend_View_Helper_Abstract
}
/**
* @deprecated Not translated.
* @deprecated Not used anywhere.
*/
public function getStateTitle($object, $type)
{

View File

@ -1,4 +1,6 @@
<?php
use Icinga\Module\Monitoring\Object\Host;
$helper = $this->getHelper('MonitoringState');
if ($this->compact): ?>
@ -79,8 +81,8 @@ if ($hosts->count() === 0) {
?>
<tr class="state <?= $hostStateName ?><?= $host->host_handled ? ' handled' : '' ?>">
<!-- State -->
<td class="state" title="<?= $helper->getStateTitle($host, 'host') ?>">
<strong><?= ucfirst($helper->monitoringState($host, 'host')) ?></strong><br />
<td class="state">
<strong><?= strtoupper(Host::getStateText($host->host_state, true)); ?></strong><br />
<?php if ((int) $host->host_state !== 99): ?>
<?= $this->prefixedTimeSince($host->host_last_state_change, true) ?>
<?php if ($host->host_state > 0 && (int) $host->host_state_type === 0): ?>

View File

@ -1,3 +1,8 @@
<?php
use Icinga\Module\Monitoring\Object\Service;
?>
<?php if (!$this->compact): ?>
<div class="controls">
<?= $this->tabs; ?>
@ -63,7 +68,7 @@ $hostFilter = '(host_name=' . implode('|host_name=', array_keys($pivotData)) . '
<a href="<?= $this->href('monitoring/show/service', array(
'host' => $service->host_name,
'service' => $service->service_description
)); ?>" title="<?= $this->escape($service->service_output); ?>" class="state_<?= $this->monitoringState($service, 'service'); ?> <?= $service->service_handled ? 'handled' : ''; ?>"></a>
)); ?>" title="<?= $this->escape($service->service_output); ?>" class="state_<?= Service::getStateText($service->service_state); ?> <?= $service->service_handled ? 'handled' : ''; ?>"></a>
</td>
<?php else: ?>
<td>&middot;</td>

View File

@ -1,4 +1,7 @@
<?php
use Icinga\Module\Monitoring\Object\Host;
use Icinga\Module\Monitoring\Object\Service;
$helper = $this->getHelper('MonitoringState');
$selfUrl = 'monitoring/list/services';
@ -54,9 +57,8 @@ foreach ($services as $service):
$serviceStateName = strtolower($this->util()->getServiceStateName($service->service_state));
?>
<tr class="state <?= $serviceStateName ?><?= $service->service_handled ? ' handled' : '' ?>">
<td class="state" title="<?= $helper->getStateTitle($service, 'service'); ?>">
<strong><?= $this->translate(strtoupper($helper->monitoringState($service, 'service'))) ?></strong><br />
<td class="state">
<strong><?= strtoupper(Service::getStateText($service->service_state, true)); ?></strong><br />
<?php if (!$this->compact): ?><?= $this->prefixedTimeSince($service->service_last_state_change); ?><?php else: ?><?= $this->timeSince($service->service_last_state_change); ?><?php endif ?>
<?php if ($service->service_state > 0 && (int) $service->service_state_type === 0): ?>
<br />
@ -106,7 +108,7 @@ foreach ($services as $service):
<?php endif ?>
<a href="<?= $serviceLink ?>"><?= $service->service_display_name ?></a><?php if ($this->showHost): ?> on <a href="<?= $hostLink ?>"><?= $service->host_name; ?>
<?php if ($service->host_state != 0): ?>
(<?= ucfirst($helper->monitoringState($service, 'host')); ?>)
(<?= strtoupper(Host::getStateText($service->host_state, true)); ?>)
<?php endif ?>
</a><?php endif ?><br />
<p class="pluginoutput"><?= $this->escape(substr(strip_tags($service->service_output), 0, 10000)); ?></p>

View File

@ -1,9 +1,16 @@
<?php $showService = $object->getType() === $object::TYPE_SERVICE ?>
<?php
use Icinga\Module\Monitoring\Object\Host;
use Icinga\Module\Monitoring\Object\Service;
$showService = $object->getType() === $object::TYPE_SERVICE;
?>
<?php if (!$this->compact): ?>
<?= $tabs ?>
<?php endif ?>
<table class="objectstate">
<tr class="state <?= $this->monitoringState($object, 'host') ?><?= $object->host_handled ? ' handled' : '' ?>">
<tr class="state <?= Host::getStateText($object->host_state); ?><?= $object->host_handled ? ' handled' : '' ?>">
<td class="state"<?= $showService ? '' : ' rowspan="2"' ?>>
<strong><?= $this->translate($this->util()->getHostStateName($object->host_state)) ?></strong><br />
<?= $this->prefixedTimeSince($object->host_last_state_change, true) ?>
@ -15,7 +22,7 @@
</td>
</tr>
<?php if ($showService): ?>
<tr class="state <?= $this->monitoringState($object, 'service') ?><?= $object->service_handled ? ' handled' : '' ?>">
<tr class="state <?= Service::getStateText($object->service_state); ?><?= $object->service_handled ? ' handled' : '' ?>">
<td class="state">
<strong><?= $this->translate($this->util()->getServiceStateName($object->service_state)) ?></strong><br />
<?= $this->prefixedTimeSince($object->service_last_state_change, true) ?>