mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-07-28 16:24:04 +02:00
Drop Zend_View_Helper_MonitoringProperties as it's not used anywhere
This commit is contained in:
parent
06c7c4bd3e
commit
c4d17a3509
@ -1,284 +0,0 @@
|
|||||||
<?php
|
|
||||||
// {{{ICINGA_LICENSE_HEADER}}}
|
|
||||||
// {{{ICINGA_LICENSE_HEADER}}}
|
|
||||||
|
|
||||||
use Icinga\Module\Monitoring\Object\AbstractObject;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Class Zend_View_Helper_MonitoringProperties
|
|
||||||
*/
|
|
||||||
class Zend_View_Helper_MonitoringProperties extends Zend_View_Helper_Abstract
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Value for check type active
|
|
||||||
*/
|
|
||||||
const CHECK_ACTIVE = 'ACTIVE';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Value for check type passive
|
|
||||||
*/
|
|
||||||
const CHECK_PASSIVE = 'PASSIVE';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Value for check type disabled
|
|
||||||
*/
|
|
||||||
const CHECK_DISABLED = 'DISABLED';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return value for not available
|
|
||||||
*/
|
|
||||||
const VALUE_NA = 'N/A';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return value for "YES"
|
|
||||||
*/
|
|
||||||
const VALUE_YES = 'YES';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return value for "NO"
|
|
||||||
*/
|
|
||||||
const VALUE_NO = 'NO';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Label / value mapping for object keys
|
|
||||||
*
|
|
||||||
* Keys can be callables in this object
|
|
||||||
*
|
|
||||||
* @var array
|
|
||||||
*/
|
|
||||||
private static $keys = array(
|
|
||||||
'buildAttempt' => 'Current Attempt',
|
|
||||||
'buildCheckType' => 'Check Type',
|
|
||||||
'buildLatency' => 'Check Latency / Duration',
|
|
||||||
'buildLastStateChange' => 'Last State Change',
|
|
||||||
'buildLastNotification' => 'Last Notification',
|
|
||||||
'buildFlapping' => 'Is This %s Flapping?',
|
|
||||||
'buildScheduledDowntime' => 'In Scheduled Downtime?',
|
|
||||||
'status_update_time' => 'Last Update'
|
|
||||||
);
|
|
||||||
|
|
||||||
private static $notificationReasons = array(
|
|
||||||
0 => 'NORMAL',
|
|
||||||
1 => 'ACKNOWLEDGEMENT',
|
|
||||||
2 => 'FLAPPING START',
|
|
||||||
3 => 'FLAPPING STOP',
|
|
||||||
4 => 'FLAPPING DISABLED',
|
|
||||||
5 => 'DOWNTIME START',
|
|
||||||
6 => 'DOWNTIME END',
|
|
||||||
7 => 'DOWNTIME CANCELLED',
|
|
||||||
8 => 'CUSTOM',
|
|
||||||
9 => 'STALKING'
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return the object type
|
|
||||||
* @param stdClass $object
|
|
||||||
* @return mixed
|
|
||||||
*/
|
|
||||||
private function getObjectType($object)
|
|
||||||
{
|
|
||||||
$keys = array_keys(get_object_vars($object));
|
|
||||||
$keyParts = explode('_', array_shift($keys), 2);
|
|
||||||
return array_shift($keyParts);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Drop all object specific attribute prefixes
|
|
||||||
* @param stdClass $object
|
|
||||||
* @param $type
|
|
||||||
* @return object
|
|
||||||
*/
|
|
||||||
private function dropObjectType($object, $type)
|
|
||||||
{
|
|
||||||
$vars = get_object_vars($object);
|
|
||||||
$out = array();
|
|
||||||
foreach ($vars as $name => $value) {
|
|
||||||
$name = str_replace($type. '_', '', $name);
|
|
||||||
$out[$name] = $value;
|
|
||||||
}
|
|
||||||
return (object)$out;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get string for attempt
|
|
||||||
* @param stdClass $object
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
private function buildAttempt($object)
|
|
||||||
{
|
|
||||||
return sprintf(
|
|
||||||
'%s/%s (%s state)',
|
|
||||||
$object->current_check_attempt,
|
|
||||||
$object->max_check_attempts,
|
|
||||||
($object->state_type === '1') ? 'HARD' : 'SOFT'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Generic fomatter for float values
|
|
||||||
* @param $value
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
private function floatFormatter($value)
|
|
||||||
{
|
|
||||||
return sprintf('%.4F', $value);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the string for check type
|
|
||||||
* @param stdClass $object
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
private function buildCheckType($object)
|
|
||||||
{
|
|
||||||
if ($object->passive_checks_enabled === '1' && $object->active_checks_enabled === '0') {
|
|
||||||
return self::CHECK_PASSIVE;
|
|
||||||
} elseif ($object->passive_checks_enabled === '0' && $object->active_checks_enabled === '0') {
|
|
||||||
return self::CHECK_DISABLED;
|
|
||||||
}
|
|
||||||
|
|
||||||
return self::CHECK_ACTIVE;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get string for latency
|
|
||||||
* @param stdClass $object
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
private function buildLatency($object)
|
|
||||||
{
|
|
||||||
$val = '';
|
|
||||||
if ($this->buildCheckType($object) === self::CHECK_PASSIVE) {
|
|
||||||
$val .= self::VALUE_NA;
|
|
||||||
} else {
|
|
||||||
$val .= $this->floatFormatter(
|
|
||||||
(isset($object->check_latency)) ? $object->check_latency : 0
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
$val .= ' / '. $this->floatFormatter(
|
|
||||||
isset($object->check_execution_time) ? $object->check_execution_time : 0
|
|
||||||
). ' seconds';
|
|
||||||
|
|
||||||
return $val;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get string for next check
|
|
||||||
* @param stdClass $object
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
private function buildNextCheck($object)
|
|
||||||
{
|
|
||||||
if ($this->buildCheckType($object) === self::CHECK_PASSIVE) {
|
|
||||||
return self::VALUE_NA;
|
|
||||||
} else {
|
|
||||||
return $object->next_check;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get date for last state change
|
|
||||||
* @param stdClass $object
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
private function buildLastStateChange($object)
|
|
||||||
{
|
|
||||||
return strftime('%Y-%m-%d %H:%M:%S', $object->last_state_change);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get string for "last notification"
|
|
||||||
* @param stdClass $object
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
private function buildLastNotification($object)
|
|
||||||
{
|
|
||||||
$val = '';
|
|
||||||
|
|
||||||
if ($object->last_notification === '0000-00-00 00:00:00') {
|
|
||||||
$val .= self::VALUE_NA;
|
|
||||||
} else {
|
|
||||||
$val .= $object->last_notification;
|
|
||||||
}
|
|
||||||
|
|
||||||
$val .= sprintf(' (notification %d)', $object->current_notification_number);
|
|
||||||
|
|
||||||
return $val;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get string for "is flapping"
|
|
||||||
* @param stdClass $object
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
private function buildFlapping($object)
|
|
||||||
{
|
|
||||||
$val = '';
|
|
||||||
|
|
||||||
if ($object->is_flapping === '0') {
|
|
||||||
$val .= self::VALUE_NO;
|
|
||||||
} else {
|
|
||||||
$val .= self::VALUE_YES;
|
|
||||||
}
|
|
||||||
|
|
||||||
$val .= sprintf(' (%.2F%% state change)', $object->percent_state_change);
|
|
||||||
|
|
||||||
return $val;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get string for scheduled downtime
|
|
||||||
* @param stdClass $object
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
private function buildScheduledDowntime($object)
|
|
||||||
{
|
|
||||||
if ($object->in_downtime === '1') {
|
|
||||||
return self::VALUE_YES;
|
|
||||||
}
|
|
||||||
|
|
||||||
return self::VALUE_NO;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get an array which represent monitoring properties
|
|
||||||
*
|
|
||||||
* @param stdClass $object
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function monitoringProperties($object)
|
|
||||||
{
|
|
||||||
$type = $this->getObjectType($object);
|
|
||||||
//$object = $this->dropObjectType($object, $type);
|
|
||||||
|
|
||||||
$out = array();
|
|
||||||
foreach (self::$keys as $property => $label) {
|
|
||||||
$label = sprintf($label, ucfirst($type));
|
|
||||||
if (is_callable(array(&$this, $property))) {
|
|
||||||
$out[$label] = $this->$property($object);
|
|
||||||
} elseif (isset($object->{$property})) {
|
|
||||||
$out[$label] = $object->{$property};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $out;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getNotificationType($notification)
|
|
||||||
{
|
|
||||||
$reason = intval($notification->notification_reason);
|
|
||||||
if (!isset(self::$notificationReasons[$reason])) {
|
|
||||||
return 'N/A';
|
|
||||||
}
|
|
||||||
$type = self::$notificationReasons[$reason];
|
|
||||||
if ($reason === 8) {
|
|
||||||
if (intval($notification->notification_type) === 0) {
|
|
||||||
$type .= '(UP)';
|
|
||||||
} else {
|
|
||||||
$type .= '(OK)';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return $type;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,104 +0,0 @@
|
|||||||
<?php
|
|
||||||
// {{{ICINGA_LICENSE_HEADER}}}
|
|
||||||
// {{{ICINGA_LICENSE_HEADER}}}
|
|
||||||
|
|
||||||
namespace Test\Modules\Monitoring\Application\Views\Helpers;
|
|
||||||
|
|
||||||
use Zend_View_Helper_MonitoringProperties;
|
|
||||||
use Icinga\Test\BaseTestCase;
|
|
||||||
|
|
||||||
require_once realpath(BaseTestCase::$moduleDir . '/monitoring/application/views/helpers/MonitoringProperties.php');
|
|
||||||
|
|
||||||
class HostStruct4Properties
|
|
||||||
{
|
|
||||||
public $host_name = 'localhost';
|
|
||||||
public $host_address = '127.0.0.1';
|
|
||||||
public $host_state = '1';
|
|
||||||
public $host_handled = '1';
|
|
||||||
public $in_downtime = '1';
|
|
||||||
public $acknowledged = '1';
|
|
||||||
public $check_command = 'check-host-alive';
|
|
||||||
public $last_state_change = '1372937083';
|
|
||||||
public $host_alias = 'localhost';
|
|
||||||
public $output = 'DDD';
|
|
||||||
public $long_output = '';
|
|
||||||
public $perfdata = '';
|
|
||||||
public $current_check_attempt = '1';
|
|
||||||
public $max_check_attempts = '10';
|
|
||||||
public $attempt = '1/10';
|
|
||||||
public $last_check = '2013-07-04 11:24:42';
|
|
||||||
public $next_check = '2013-07-04 11:29:43';
|
|
||||||
public $heck_type = '1';
|
|
||||||
public $last_hard_state_change = '2013-07-04 11:24:43';
|
|
||||||
public $last_hard_state = '0';
|
|
||||||
public $last_time_up = '2013-07-04 11:20:23';
|
|
||||||
public $last_time_down = '2013-07-04 11:24:43';
|
|
||||||
public $last_time_unreachable = '0000-00-00 00:00:00';
|
|
||||||
public $state_type = '1';
|
|
||||||
public $last_notification = '0000-00-00 00:00:00';
|
|
||||||
public $next_notification = '0000-00-00 00:00:00';
|
|
||||||
public $no_more_notifications = '0';
|
|
||||||
public $host_notifications_enabled = '1';
|
|
||||||
public $host_problem_has_been_acknowledged = '1';
|
|
||||||
public $host_acknowledgement_type = '2';
|
|
||||||
public $current_notification_number = '0';
|
|
||||||
public $passive_checks_enabled = '1';
|
|
||||||
public $active_checks_enabled = '0';
|
|
||||||
public $event_handler_enabled = '0';
|
|
||||||
public $flap_detection_enabled = '1';
|
|
||||||
public $is_flapping = '0';
|
|
||||||
public $percent_state_change = '12.36842';
|
|
||||||
public $check_latency = '0.12041';
|
|
||||||
public $check_execution_time = '0';
|
|
||||||
public $scheduled_downtime_depth = '1';
|
|
||||||
public $host_failure_prediction_enabled = '1';
|
|
||||||
public $host_process_performance_data = '1';
|
|
||||||
public $host_obsessing = '1';
|
|
||||||
public $host_modified_host_attributes = '14';
|
|
||||||
public $host_event_handler = '';
|
|
||||||
public $host_normal_check_interval = '5';
|
|
||||||
public $host_retry_check_interval = '1';
|
|
||||||
public $host_check_timeperiod_object_id = '27';
|
|
||||||
public $host_status_update_time = '2013-07-08 10:10:10';
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @TODO(el): This test is subject to bug #4679
|
|
||||||
*/
|
|
||||||
class MonitoringPropertiesTest extends BaseTestCase
|
|
||||||
{
|
|
||||||
public function testOutput1()
|
|
||||||
{
|
|
||||||
$host = new HostStruct4Properties();
|
|
||||||
$host->current_check_attempt = '5';
|
|
||||||
|
|
||||||
$propertyHelper = new Zend_View_Helper_MonitoringProperties();
|
|
||||||
$items = $propertyHelper->monitoringProperties($host);
|
|
||||||
|
|
||||||
$this->assertEquals('5/10 (HARD state)', $items['Current Attempt']);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testOutput2()
|
|
||||||
{
|
|
||||||
$host = new HostStruct4Properties();
|
|
||||||
$host->current_check_attempt = '5';
|
|
||||||
$host->active_checks_enabled = '1';
|
|
||||||
$host->passive_checks_enabled = '0';
|
|
||||||
$host->is_flapping = '1';
|
|
||||||
|
|
||||||
$propertyHelper = new Zend_View_Helper_MonitoringProperties();
|
|
||||||
$items = $propertyHelper->monitoringProperties($host);
|
|
||||||
|
|
||||||
$test = array(
|
|
||||||
'Current Attempt' => "5/10 (HARD state)",
|
|
||||||
'Check Type' => "ACTIVE",
|
|
||||||
'Check Latency / Duration' => "0.1204 / 0.0000 seconds",
|
|
||||||
'Last State Change' => "2013-07-04 11:24:43",
|
|
||||||
'Last Notification' => "N/A (notification 0)",
|
|
||||||
'Is This Host Flapping?' => "YES (12.37% state change)",
|
|
||||||
'In Scheduled Downtime?' => "YES"
|
|
||||||
);
|
|
||||||
|
|
||||||
$this->assertEquals($test, $items);
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user