Merge branch 'bugfix/drop-obsolete-state-helpers-7996'

fixes #7996
This commit is contained in:
Johannes Meyer 2014-12-12 12:43:16 +01:00
commit 1721936ca9
10 changed files with 87 additions and 104 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

@ -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,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

@ -1,4 +1,6 @@
<?php
use Icinga\Module\Monitoring\Object\Host;
$helper = $this->getHelper('MonitoringState');
if ($this->compact): ?>
@ -41,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();
@ -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,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

@ -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';
@ -51,12 +54,11 @@ 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" 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,11 +1,18 @@
<?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 />
<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
@ -15,9 +22,9 @@
</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 />
<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';