Use the Host and Service object class helpers instead of the Util view helper

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 12:22:20 +01:00
parent 87664ffef9
commit 7987fb3f5a
8 changed files with 55 additions and 91 deletions

View File

@ -63,64 +63,4 @@ class Zend_View_Helper_Util extends Zend_View_Helper_Abstract
}
return date('H:i d.m.Y', $timestamp);
}
/**
* @deprecated Not used. This is monitoring module stuff.
*/
public static function getHostStateClassName($state)
{
$class = 'unknown';
switch ($state) {
case null:
$class = 'error';
break;
case 0:
$class = 'ok';
break;
case 1:
case 2:
$class = 'error';
break;
}
return $class;
}
/**
* @deprecated Crap. This is monitoring module stuff.
*/
public static function getHostStateName($state)
{
$states = array(
0 => 'UP',
1 => 'DOWN',
2 => 'UNREACHABLE',
3 => 'UNKNOWN',
4 => 'PENDING', // fake
99 => 'PENDING' // fake
);
if (isset($states[$state])) {
return $states[$state];
}
return sprintf('OUT OF BOUNDS (%s)', var_export($state, 1));
}
/**
* @deprecated Crap. This is monitoring module stuff.
*/
public static function getServiceStateName($state)
{
if ($state === null) { $state = 3; } // really?
$states = array(
0 => 'OK',
1 => 'WARNING',
2 => 'CRITICAL',
3 => 'UNKNOWN',
4 => 'PENDING', // fake
99 => 'PENDING' // fake
);
if (isset($states[$state])) {
return $states[$state];
}
return sprintf('OUT OF BOUND (%d)' . $state, (int) $state);
}
}

View File

@ -1,3 +1,10 @@
<?php
use Icinga\Module\Monitoring\Object\Host;
use Icinga\Module\Monitoring\Object\Service;
?>
<?php if (false === $this->compact): ?>
<div class="controls">
<?= $this->tabs->render($this); ?>
@ -24,9 +31,9 @@
<?php foreach ($downtimes as $downtime): ?>
<?php
if (isset($downtime->service)) {
$stateName = strtolower($this->util()->getServiceStateName($downtime->service_state));
$stateName = Service::getStateText($downtime->service_state);
} else {
$stateName = strtolower($this->util()->getHostStateName($downtime->host_state));
$stateName = Host::getStateText($downtime->host_state);
}
?>
<tr class="state <?= $stateName; ?><?= $downtime->is_in_effect ? ' handled' : ''; ?>">

View File

@ -1,3 +1,10 @@
<?php
use Icinga\Module\Monitoring\Object\Host;
use Icinga\Module\Monitoring\Object\Service;
?>
<?php if (false === $this->compact): ?>
<div class="controls">
<?= $this->tabs ?>
@ -62,22 +69,22 @@
case 'hard_state':
$icon = $isService ? 'service' : 'host';
$msg = '[ ' . $event->attempt . '/' . $event->max_attempts . ' ] ' . $event->output;
$stateName = (
$stateName = $isService ? Service::getStateText($event->state) : Host::getStateText($event->state);
$title = strtoupper(
$isService
? strtolower($this->util()->getServiceStateName($event->state))
: strtolower($this->util()->getHostStateName($event->state))
? Service::getStateText($event->state, true)
: Host::getStateText($event->state, true)
);
$title = strtoupper($stateName); // TODO: Should be translatable!
break;
case 'soft_state':
$icon = 'lightbulb';
$msg = '[ ' . $event->attempt . '/' . $event->max_attempts . ' ] ' . $event->output;
$stateName = (
$stateName = $isService ? Service::getStateText($event->state) : Host::getStateText($event->state);
$title = strtoupper(
$isService
? strtolower($this->util()->getServiceStateName($event->state))
: strtolower($this->util()->getHostStateName($event->state))
? Service::getStateText($event->state, true)
: Host::getStateText($event->state, true)
);
$title = strtoupper($stateName); // TODO: Should be translatable!
break;
case 'dt_start':
$icon = 'starttime';

View File

@ -43,7 +43,7 @@ if ($hosts->count() === 0) {
<tbody>
<?php foreach($hosts as $host):
$hostStateName = strtolower($this->util()->getHostStateName($host->host_state));
$hostStateName = Host::getStateText($host->host_state);
$hostLink = $this->href('monitoring/host/show', array('host' => $host->host_name));
$icons = array();

View File

@ -1,3 +1,10 @@
<?php
use Icinga\Module\Monitoring\Object\Host;
use Icinga\Module\Monitoring\Object\Service;
?>
<?php if (!$this->compact): ?>
<div class="controls">
<?= $this->tabs ?>
@ -36,13 +43,13 @@ foreach ($notifications as $notification):
'host' => $notification->host,
'service' => $notification->service
));
$stateName = strtolower($this->util()->getServiceStateName($notification->notification_state));
$stateName = Service::getStateText($notification->notification_state);
} else {
$isService = false;
$href = $this->href('monitoring/show/host', array(
'host' => $notification->host
));
$stateName = strtolower($this->util()->getHostStateName($notification->notification_state));
$stateName = Host::getStateText($notification->notification_state);
}
?>
<tr class="state <?= $stateName ?>">

View File

@ -54,7 +54,7 @@ foreach ($services as $service):
'host' => $service->host_name,
)
);
$serviceStateName = strtolower($this->util()->getServiceStateName($service->service_state));
$serviceStateName = Service::getStateText($service->service_state);
?>
<tr class="state <?= $serviceStateName ?><?= $service->service_handled ? ' handled' : '' ?>">
<td class="state">

View File

@ -12,7 +12,7 @@ $showService = $object->getType() === $object::TYPE_SERVICE;
<table class="objectstate">
<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 />
<strong><?= strtoupper(Host::getStateText($object->host_state, true)); ?></strong><br />
<?= $this->prefixedTimeSince($object->host_last_state_change, true) ?>
</td>
<td><b><?= $this->escape($object->host_name) ?></b><?php
@ -24,7 +24,7 @@ $showService = $object->getType() === $object::TYPE_SERVICE;
<?php if ($showService): ?>
<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 />
<strong><?= strtoupper(Service::getStateText($object->service_state, true)); ?></strong><br />
<?= $this->prefixedTimeSince($object->service_last_state_change, true) ?>
</td>
<td><b><?= $this->translate('Service') ?>: <?= $this->escape($object->service_description) ?></b>

View File

@ -1,3 +1,10 @@
<?php
use Icinga\Module\Monitoring\Object\Host;
use Icinga\Module\Monitoring\Object\Service;
?>
<div class="controls">
<?= $this->render('show/components/header.phtml'); ?>
<h1><?= $this->translate('This Object\'s Event History'); ?></h1>
@ -33,11 +40,7 @@ function contactsLink($match, $view) {
case 'notify':
$icon = 'notification';
$title = $this->translate('Notification');
$stateClass = (
$isService
? strtolower($this->util()->getServiceStateName($event->state))
: strtolower($this->util()->getHostStateName($event->state))
);
$stateClass = $isService ? Service::getStateText($event->state) : Host::getStateText($event->state);
$msg = preg_replace_callback(
'/^\[([^\]]+)\]/',
@ -87,23 +90,23 @@ function contactsLink($match, $view) {
break;
case 'hard_state':
$msg = '[ ' . $event->attempt . '/' . $event->max_attempts . ' ] ' . $this->escape($event->output);
$stateClass = (
$isService
? strtolower($this->util()->getServiceStateName($event->state))
: strtolower($this->util()->getHostStateName($event->state))
);
$stateClass = $isService ? Service::getStateText($event->state) : Host::getStateText($event->state);
$icon = 'attention-alt';
$title = strtoupper($stateClass); // TODO: Should be translatable!
$title = strtoupper(
$isService
? Service::getStateText($event->state)
: Host::getStateText($event->state)
);
break;
case 'soft_state':
$icon = 'spinner';
$msg = '[ ' . $event->attempt . '/' . $event->max_attempts . ' ] ' . $this->escape($event->output);
$stateClass = (
$stateClass = $isService ? Service::getStateText($event->state) : Host::getStateText($event->state);
$title = strtoupper(
$isService
? strtolower($this->util()->getServiceStateName($event->state))
: strtolower($this->util()->getHostStateName($event->state))
? Service::getStateText($event->state)
: Host::getStateText($event->state)
);
$title = strtoupper($stateClass); // TODO: Should be translatable!
break;
case 'dt_start':
$icon = 'downtime_start';