parent
ffc1a2b43f
commit
f455b32464
|
@ -0,0 +1,56 @@
|
||||||
|
<?php
|
||||||
|
// {{{ICINGA_LICENSE_HEADER}}}
|
||||||
|
// {{{ICINGA_LICENSE_HEADER}}}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class Zend_View_Helper_MonitoringFlags
|
||||||
|
*
|
||||||
|
* Rendering helper for flags depending on objects
|
||||||
|
*/
|
||||||
|
class Zend_View_Helper_MonitoringFlags extends Zend_View_Helper_Abstract
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Key of flags without prefix (e.g. host or service)
|
||||||
|
* @var string[]
|
||||||
|
*/
|
||||||
|
private static $keys = array(
|
||||||
|
'passive_checks_enabled' => 'Passive checks',
|
||||||
|
'active_checks_enabled' => 'Active checks',
|
||||||
|
'obsess_over_host' => 'Obsessing',
|
||||||
|
'notifications_enabled' => 'Notifications',
|
||||||
|
'event_handler_enabled' => 'Event handler',
|
||||||
|
'flap_detection_enabled' => 'Flap detection',
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Type prefix
|
||||||
|
* @param array $vars
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
private function getObjectType(array $vars)
|
||||||
|
{
|
||||||
|
return array_shift(explode('_', array_shift(array_keys($vars)), 2));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Build all existing flags to a readable array
|
||||||
|
* @param stdClass $object
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function monitoringFlags(\stdClass $object)
|
||||||
|
{
|
||||||
|
$vars = (array)$object;
|
||||||
|
$type = $this->getObjectType($vars);
|
||||||
|
$out = array();
|
||||||
|
|
||||||
|
foreach (self::$keys as $key => $name) {
|
||||||
|
$value = false;
|
||||||
|
if (array_key_exists(($realKey = $type. '_'. $key), $vars)) {
|
||||||
|
$value = $vars[$realKey] === '1' ? true : false;
|
||||||
|
}
|
||||||
|
$out[$name] = $value;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $out;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,25 @@
|
||||||
|
<?php
|
||||||
|
$object = null;
|
||||||
|
|
||||||
|
if (isset($this->service)) {
|
||||||
|
$object = $this->service;
|
||||||
|
} elseif (isset($this->host)) {
|
||||||
|
$object = $this->host;
|
||||||
|
}
|
||||||
|
|
||||||
|
$flags = $this->monitoringFlags($object);
|
||||||
|
?>
|
||||||
|
<table class="flag-container">
|
||||||
|
<?php foreach ($flags as $name => $value) { ?>
|
||||||
|
<tr>
|
||||||
|
<th><?= $name; ?></th>
|
||||||
|
<td>
|
||||||
|
<?php if ($value === true) { ?>
|
||||||
|
<span class="flag flag-enabled">ENABLED</span>
|
||||||
|
<?php } else { ?>
|
||||||
|
<span class="flag flag-disabled">DISABLED</span>
|
||||||
|
<?php } ?>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<?php } ?>
|
||||||
|
</table>
|
|
@ -11,8 +11,6 @@
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var_dump($this->host);
|
|
||||||
?>
|
?>
|
||||||
<?=
|
<?=
|
||||||
$this->partial(
|
$this->partial(
|
||||||
|
@ -75,4 +73,13 @@ var_dump($this->host);
|
||||||
<?= $this->perfdata($this->host->host_perfdata); ?>
|
<?= $this->perfdata($this->host->host_perfdata); ?>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
|
|
||||||
|
<div class="information-container">
|
||||||
|
<div class="head">
|
||||||
|
<span>Flags</span>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<?= $this->render('show/components/flags.phtml'); ?>
|
||||||
|
</div>
|
||||||
|
</div>
|
|
@ -84,7 +84,13 @@ class AbstractBackend implements DatasourceInterface
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// UGLY temporary host fetch
|
/**
|
||||||
|
* UGLY temporary host fetch
|
||||||
|
*
|
||||||
|
* @param string $host
|
||||||
|
* @param bool $fetchAll
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
public function fetchHost($host, $fetchAll = false)
|
public function fetchHost($host, $fetchAll = false)
|
||||||
{
|
{
|
||||||
$fields = array(
|
$fields = array(
|
||||||
|
@ -102,49 +108,51 @@ class AbstractBackend implements DatasourceInterface
|
||||||
'host_perfdata'
|
'host_perfdata'
|
||||||
);
|
);
|
||||||
|
|
||||||
$fields = array_merge(
|
if ($fetchAll === true) {
|
||||||
$fields,
|
$fields = array_merge(
|
||||||
array(
|
$fields,
|
||||||
'current_check_attempt',
|
array(
|
||||||
'max_check_attempts',
|
'host_current_check_attempt',
|
||||||
'attempt',
|
'host_max_check_attempts',
|
||||||
'last_check',
|
'host_attempt',
|
||||||
'next_check',
|
'host_last_check',
|
||||||
'check_type',
|
'host_next_check',
|
||||||
'last_state_change',
|
'host_check_type',
|
||||||
'last_hard_state_change',
|
'host_last_state_change',
|
||||||
'last_hard_state',
|
'host_last_hard_state_change',
|
||||||
'last_time_up',
|
'host_last_hard_state',
|
||||||
'last_time_down',
|
'host_last_time_up',
|
||||||
'last_time_unreachable',
|
'host_last_time_down',
|
||||||
'state_type',
|
'host_last_time_unreachable',
|
||||||
'last_notification',
|
'host_state_type',
|
||||||
'next_notification',
|
'host_last_notification',
|
||||||
'no_more_notifications',
|
'host_next_notification',
|
||||||
'notifications_enabled',
|
'host_no_more_notifications',
|
||||||
'problem_has_been_acknowledged',
|
'host_notifications_enabled',
|
||||||
'acknowledgement_type',
|
'host_problem_has_been_acknowledged',
|
||||||
'current_notification_number',
|
'host_acknowledgement_type',
|
||||||
'passive_checks_enabled',
|
'host_current_notification_number',
|
||||||
'active_checks_enabled',
|
'host_passive_checks_enabled',
|
||||||
'event_handler_enabled',
|
'host_active_checks_enabled',
|
||||||
'flap_detection_enabled',
|
'host_event_handler_enabled',
|
||||||
'is_flapping',
|
'host_flap_detection_enabled',
|
||||||
'percent_state_change',
|
'host_is_flapping',
|
||||||
'latency',
|
'host_percent_state_change',
|
||||||
'execution_time',
|
'host_latency',
|
||||||
'scheduled_downtime_depth',
|
'host_execution_time',
|
||||||
'failure_prediction_enabled',
|
'host_scheduled_downtime_depth',
|
||||||
'process_performance_data',
|
'host_failure_prediction_enabled',
|
||||||
'obsess_over_host',
|
'host_process_performance_data',
|
||||||
'modified_host_attributes',
|
'host_obsess_over_host',
|
||||||
'event_handler',
|
'host_modified_host_attributes',
|
||||||
'check_command',
|
'host_event_handler',
|
||||||
'normal_check_interval',
|
'host_check_command',
|
||||||
'retry_check_interval',
|
'host_normal_check_interval',
|
||||||
'check_timeperiod_object_id'
|
'host_retry_check_interval',
|
||||||
)
|
'host_check_timeperiod_object_id'
|
||||||
);
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
$select = $this->select()
|
$select = $this->select()
|
||||||
->from('status', $fields)
|
->from('status', $fields)
|
||||||
|
|
|
@ -29,44 +29,43 @@ class StatusQuery extends AbstractQuery
|
||||||
'host_last_state_change' => 'UNIX_TIMESTAMP(hs.last_state_change)',
|
'host_last_state_change' => 'UNIX_TIMESTAMP(hs.last_state_change)',
|
||||||
'host_check_command' => 'hs.check_command',
|
'host_check_command' => 'hs.check_command',
|
||||||
|
|
||||||
'current_check_attempt' => 'hs.current_check_attempt',
|
'host_current_check_attempt' => 'hs.current_check_attempt',
|
||||||
'max_check_attempts' => 'hs.max_check_attempts',
|
'host_max_check_attempts' => 'hs.max_check_attempts',
|
||||||
'attempt' => 'CONCAT(hs.current_check_attempt, "/", hs.max_check_attempts)',
|
'host_attempt' => 'CONCAT(hs.current_check_attempt, "/", hs.max_check_attempts)',
|
||||||
'last_check' => 'hs.last_check',
|
'host_last_check' => 'hs.last_check',
|
||||||
'next_check' => 'hs.next_check',
|
'host_next_check' => 'hs.next_check',
|
||||||
'check_type' => 'hs.check_type',
|
'host_check_type' => 'hs.check_type',
|
||||||
'last_state_change' => 'hs.last_state_change',
|
'host_last_hard_state_change' => 'hs.last_hard_state_change',
|
||||||
'last_hard_state_change' => 'hs.last_hard_state_change',
|
'host_last_hard_state' => 'hs.last_hard_state',
|
||||||
'last_hard_state' => 'hs.last_hard_state',
|
'host_last_time_up' => 'hs.last_time_up',
|
||||||
'last_time_up' => 'hs.last_time_up',
|
'host_last_time_down' => 'hs.last_time_down',
|
||||||
'last_time_down' => 'hs.last_time_down',
|
'host_last_time_unreachable' => 'hs.last_time_unreachable',
|
||||||
'last_time_unreachable' => 'hs.last_time_unreachable',
|
'host_state_type' => 'hs.state_type',
|
||||||
'state_type' => 'hs.state_type',
|
'host_last_notification' => 'hs.last_notification',
|
||||||
'last_notification' => 'hs.last_notification',
|
'host_next_notification' => 'hs.next_notification',
|
||||||
'next_notification' => 'hs.next_notification',
|
'host_no_more_notifications' => 'hs.no_more_notifications',
|
||||||
'no_more_notifications' => 'hs.no_more_notifications',
|
'host_notifications_enabled' => 'hs.notifications_enabled',
|
||||||
'notifications_enabled' => 'hs.notifications_enabled',
|
'host_problem_has_been_acknowledged' => 'hs.problem_has_been_acknowledged',
|
||||||
'problem_has_been_acknowledged' => 'hs.problem_has_been_acknowledged',
|
'host_acknowledgement_type' => 'hs.acknowledgement_type',
|
||||||
'acknowledgement_type' => 'hs.acknowledgement_type',
|
'host_current_notification_number' => 'hs.current_notification_number',
|
||||||
'current_notification_number' => 'hs.current_notification_number',
|
'host_passive_checks_enabled' => 'hs.passive_checks_enabled',
|
||||||
'passive_checks_enabled' => 'hs.passive_checks_enabled',
|
'host_active_checks_enabled' => 'hs.active_checks_enabled',
|
||||||
'active_checks_enabled' => 'hs.active_checks_enabled',
|
'host_event_handler_enabled' => 'hs.event_handler_enabled',
|
||||||
'event_handler_enabled' => 'hs.event_handler_enabled',
|
'host_flap_detection_enabled' => 'hs.flap_detection_enabled',
|
||||||
'flap_detection_enabled' => 'hs.flap_detection_enabled',
|
'host_is_flapping' => 'hs.is_flapping',
|
||||||
'is_flapping' => 'hs.is_flapping',
|
'host_percent_state_change' => 'hs.percent_state_change',
|
||||||
'percent_state_change' => 'hs.percent_state_change',
|
'host_latency' => 'hs.latency',
|
||||||
'latency' => 'hs.latency',
|
'host_execution_time' => 'hs.execution_time',
|
||||||
'execution_time' => 'hs.execution_time',
|
'host_scheduled_downtime_depth' => 'hs.scheduled_downtime_depth',
|
||||||
'scheduled_downtime_depth' => 'hs.scheduled_downtime_depth',
|
'host_failure_prediction_enabled' => 'hs.failure_prediction_enabled',
|
||||||
'failure_prediction_enabled' => 'hs.failure_prediction_enabled',
|
'host_process_performance_data' => 'hs.process_performance_data',
|
||||||
'process_performance_data' => 'hs.process_performance_data',
|
'host_obsess_over_host' => 'hs.obsess_over_host',
|
||||||
'obsess_over_host' => 'hs.obsess_over_host',
|
'host_modified_host_attributes' => 'hs.modified_host_attributes',
|
||||||
'modified_host_attributes' => 'hs.modified_host_attributes',
|
'host_event_handler' => 'hs.event_handler',
|
||||||
'event_handler' => 'hs.event_handler',
|
'host_check_command' => 'hs.check_command',
|
||||||
'check_command' => 'hs.check_command',
|
'host_normal_check_interval' => 'hs.normal_check_interval',
|
||||||
'normal_check_interval' => 'hs.normal_check_interval',
|
'host_retry_check_interval' => 'hs.retry_check_interval',
|
||||||
'retry_check_interval' => 'hs.retry_check_interval',
|
'host_check_timeperiod_object_id' => 'hs.check_timeperiod_object_id',
|
||||||
'check_timeperiod_object_id' => 'hs.check_timeperiod_object_id',
|
|
||||||
|
|
||||||
'host_problems' => 'CASE WHEN hs.current_state = 0 THEN 0 ELSE 1 END',
|
'host_problems' => 'CASE WHEN hs.current_state = 0 THEN 0 ELSE 1 END',
|
||||||
'host_severity' => 'CASE WHEN hs.current_state = 0
|
'host_severity' => 'CASE WHEN hs.current_state = 0
|
||||||
|
|
|
@ -104,4 +104,27 @@ font-size: 12px;
|
||||||
.container-spacer {
|
.container-spacer {
|
||||||
margin: 10px 0 0 0;
|
margin: 10px 0 0 0;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.flag-container {
|
||||||
|
.flag {
|
||||||
|
display: inline-block;
|
||||||
|
padding: 2px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.flag-enabled {
|
||||||
|
background-color: #00ff00;
|
||||||
|
}
|
||||||
|
|
||||||
|
th {
|
||||||
|
text-align: left;
|
||||||
|
}
|
||||||
|
|
||||||
|
table {
|
||||||
|
border-collapse: collapse;
|
||||||
|
}
|
||||||
|
|
||||||
|
td, th {
|
||||||
|
border: 1px #ff0000 solid;
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -0,0 +1,116 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Test\Modules\Monitoring\Application\Views\Helpers;
|
||||||
|
|
||||||
|
require_once 'Zend/View/Helper/Abstract.php';
|
||||||
|
require_once 'Zend/View.php';
|
||||||
|
require_once __DIR__. '/../../../../../../../modules/monitoring/application/views/helpers/MonitoringFlags.php';
|
||||||
|
|
||||||
|
class MonitoringFlagsTest extends \PHPUnit_Framework_TestCase
|
||||||
|
{
|
||||||
|
public function testHosts1()
|
||||||
|
{
|
||||||
|
$testArray = array(
|
||||||
|
'host_passive_checks_enabled' => '0',
|
||||||
|
'host_active_checks_enabled' => '0',
|
||||||
|
'host_obsess_over_host' => '1',
|
||||||
|
'host_notifications_enabled' => '0',
|
||||||
|
'host_event_handler_enabled' => '1',
|
||||||
|
'host_flap_detection_enabled' => '1',
|
||||||
|
);
|
||||||
|
|
||||||
|
$monitoringFlags = new \Zend_View_Helper_MonitoringFlags();
|
||||||
|
$returnArray = $monitoringFlags->monitoringFlags((object)$testArray);
|
||||||
|
|
||||||
|
$this->assertCount(6, $returnArray);
|
||||||
|
|
||||||
|
$expected = array(
|
||||||
|
'Passive checks' => false,
|
||||||
|
'Active checks' => false,
|
||||||
|
'Obsessing' => true,
|
||||||
|
'Notifications' => false,
|
||||||
|
'Event handler' => true,
|
||||||
|
'Flap detection' => true
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->assertEquals($expected, $returnArray);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testService1()
|
||||||
|
{
|
||||||
|
$testArray = array(
|
||||||
|
'service_passive_checks_enabled' => '0',
|
||||||
|
'service_active_checks_enabled' => '1',
|
||||||
|
'service_obsess_over_host' => '0',
|
||||||
|
'service_notifications_enabled' => '1',
|
||||||
|
'service_event_handler_enabled' => '1',
|
||||||
|
'service_flap_detection_enabled' => '0',
|
||||||
|
);
|
||||||
|
|
||||||
|
$monitoringFlags = new \Zend_View_Helper_MonitoringFlags();
|
||||||
|
$returnArray = $monitoringFlags->monitoringFlags((object)$testArray);
|
||||||
|
|
||||||
|
$this->assertCount(6, $returnArray);
|
||||||
|
|
||||||
|
$expected = array(
|
||||||
|
'Passive checks' => false,
|
||||||
|
'Active checks' => true,
|
||||||
|
'Obsessing' => false,
|
||||||
|
'Notifications' => true,
|
||||||
|
'Event handler' => true,
|
||||||
|
'Flap detection' => false
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->assertEquals($expected, $returnArray);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testUglyConditions1()
|
||||||
|
{
|
||||||
|
$testArray = array(
|
||||||
|
'service_active_checks_enabled' => '1',
|
||||||
|
'service_obsess_over_host' => '1',
|
||||||
|
'DING DING' => '$$$',
|
||||||
|
'DONG DONG' => '###'
|
||||||
|
);
|
||||||
|
|
||||||
|
$monitoringFlags = new \Zend_View_Helper_MonitoringFlags();
|
||||||
|
$returnArray = $monitoringFlags->monitoringFlags((object)$testArray);
|
||||||
|
|
||||||
|
$this->assertCount(6, $returnArray);
|
||||||
|
|
||||||
|
$expected = array(
|
||||||
|
'Passive checks' => false,
|
||||||
|
'Active checks' => true,
|
||||||
|
'Obsessing' => true,
|
||||||
|
'Notifications' => false,
|
||||||
|
'Event handler' => false,
|
||||||
|
'Flap detection' => false
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->assertEquals($expected, $returnArray);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testUglyConditions2()
|
||||||
|
{
|
||||||
|
$testArray = array(
|
||||||
|
'DING DING' => '$$$',
|
||||||
|
'DONG DONG' => '###'
|
||||||
|
);
|
||||||
|
|
||||||
|
$monitoringFlags = new \Zend_View_Helper_MonitoringFlags();
|
||||||
|
$returnArray = $monitoringFlags->monitoringFlags((object)$testArray);
|
||||||
|
|
||||||
|
$this->assertCount(6, $returnArray);
|
||||||
|
|
||||||
|
$expected = array(
|
||||||
|
'Passive checks' => false,
|
||||||
|
'Active checks' => false,
|
||||||
|
'Obsessing' => false,
|
||||||
|
'Notifications' => false,
|
||||||
|
'Event handler' => false,
|
||||||
|
'Flap detection' => false
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->assertEquals($expected, $returnArray);
|
||||||
|
}
|
||||||
|
}
|
|
@ -8,6 +8,7 @@
|
||||||
<directory>application/</directory>
|
<directory>application/</directory>
|
||||||
<directory>bin/</directory>
|
<directory>bin/</directory>
|
||||||
<directory>library/</directory>
|
<directory>library/</directory>
|
||||||
|
<directory>modules/</directory>
|
||||||
</testsuite>
|
</testsuite>
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
|
|
Loading…
Reference in New Issue