Host detail view

Add flags container to detail view

refs #4182
This commit is contained in:
Marius Hein 2013-07-03 14:37:49 +02:00
parent ffc1a2b43f
commit f455b32464
8 changed files with 320 additions and 85 deletions

View File

@ -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;
}
}

View File

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

View File

@ -11,8 +11,6 @@
);
}
}
var_dump($this->host);
?>
<?=
$this->partial(
@ -75,4 +73,13 @@ var_dump($this->host);
<?= $this->perfdata($this->host->host_perfdata); ?>
</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>

View File

@ -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)
{
$fields = array(
@ -102,49 +108,51 @@ class AbstractBackend implements DatasourceInterface
'host_perfdata'
);
$fields = array_merge(
$fields,
array(
'current_check_attempt',
'max_check_attempts',
'attempt',
'last_check',
'next_check',
'check_type',
'last_state_change',
'last_hard_state_change',
'last_hard_state',
'last_time_up',
'last_time_down',
'last_time_unreachable',
'state_type',
'last_notification',
'next_notification',
'no_more_notifications',
'notifications_enabled',
'problem_has_been_acknowledged',
'acknowledgement_type',
'current_notification_number',
'passive_checks_enabled',
'active_checks_enabled',
'event_handler_enabled',
'flap_detection_enabled',
'is_flapping',
'percent_state_change',
'latency',
'execution_time',
'scheduled_downtime_depth',
'failure_prediction_enabled',
'process_performance_data',
'obsess_over_host',
'modified_host_attributes',
'event_handler',
'check_command',
'normal_check_interval',
'retry_check_interval',
'check_timeperiod_object_id'
)
);
if ($fetchAll === true) {
$fields = array_merge(
$fields,
array(
'host_current_check_attempt',
'host_max_check_attempts',
'host_attempt',
'host_last_check',
'host_next_check',
'host_check_type',
'host_last_state_change',
'host_last_hard_state_change',
'host_last_hard_state',
'host_last_time_up',
'host_last_time_down',
'host_last_time_unreachable',
'host_state_type',
'host_last_notification',
'host_next_notification',
'host_no_more_notifications',
'host_notifications_enabled',
'host_problem_has_been_acknowledged',
'host_acknowledgement_type',
'host_current_notification_number',
'host_passive_checks_enabled',
'host_active_checks_enabled',
'host_event_handler_enabled',
'host_flap_detection_enabled',
'host_is_flapping',
'host_percent_state_change',
'host_latency',
'host_execution_time',
'host_scheduled_downtime_depth',
'host_failure_prediction_enabled',
'host_process_performance_data',
'host_obsess_over_host',
'host_modified_host_attributes',
'host_event_handler',
'host_check_command',
'host_normal_check_interval',
'host_retry_check_interval',
'host_check_timeperiod_object_id'
)
);
}
$select = $this->select()
->from('status', $fields)

View File

@ -29,44 +29,43 @@ class StatusQuery extends AbstractQuery
'host_last_state_change' => 'UNIX_TIMESTAMP(hs.last_state_change)',
'host_check_command' => 'hs.check_command',
'current_check_attempt' => 'hs.current_check_attempt',
'max_check_attempts' => 'hs.max_check_attempts',
'attempt' => 'CONCAT(hs.current_check_attempt, "/", hs.max_check_attempts)',
'last_check' => 'hs.last_check',
'next_check' => 'hs.next_check',
'check_type' => 'hs.check_type',
'last_state_change' => 'hs.last_state_change',
'last_hard_state_change' => 'hs.last_hard_state_change',
'last_hard_state' => 'hs.last_hard_state',
'last_time_up' => 'hs.last_time_up',
'last_time_down' => 'hs.last_time_down',
'last_time_unreachable' => 'hs.last_time_unreachable',
'state_type' => 'hs.state_type',
'last_notification' => 'hs.last_notification',
'next_notification' => 'hs.next_notification',
'no_more_notifications' => 'hs.no_more_notifications',
'notifications_enabled' => 'hs.notifications_enabled',
'problem_has_been_acknowledged' => 'hs.problem_has_been_acknowledged',
'acknowledgement_type' => 'hs.acknowledgement_type',
'current_notification_number' => 'hs.current_notification_number',
'passive_checks_enabled' => 'hs.passive_checks_enabled',
'active_checks_enabled' => 'hs.active_checks_enabled',
'event_handler_enabled' => 'hs.event_handler_enabled',
'flap_detection_enabled' => 'hs.flap_detection_enabled',
'is_flapping' => 'hs.is_flapping',
'percent_state_change' => 'hs.percent_state_change',
'latency' => 'hs.latency',
'execution_time' => 'hs.execution_time',
'scheduled_downtime_depth' => 'hs.scheduled_downtime_depth',
'failure_prediction_enabled' => 'hs.failure_prediction_enabled',
'process_performance_data' => 'hs.process_performance_data',
'obsess_over_host' => 'hs.obsess_over_host',
'modified_host_attributes' => 'hs.modified_host_attributes',
'event_handler' => 'hs.event_handler',
'check_command' => 'hs.check_command',
'normal_check_interval' => 'hs.normal_check_interval',
'retry_check_interval' => 'hs.retry_check_interval',
'check_timeperiod_object_id' => 'hs.check_timeperiod_object_id',
'host_current_check_attempt' => 'hs.current_check_attempt',
'host_max_check_attempts' => 'hs.max_check_attempts',
'host_attempt' => 'CONCAT(hs.current_check_attempt, "/", hs.max_check_attempts)',
'host_last_check' => 'hs.last_check',
'host_next_check' => 'hs.next_check',
'host_check_type' => 'hs.check_type',
'host_last_hard_state_change' => 'hs.last_hard_state_change',
'host_last_hard_state' => 'hs.last_hard_state',
'host_last_time_up' => 'hs.last_time_up',
'host_last_time_down' => 'hs.last_time_down',
'host_last_time_unreachable' => 'hs.last_time_unreachable',
'host_state_type' => 'hs.state_type',
'host_last_notification' => 'hs.last_notification',
'host_next_notification' => 'hs.next_notification',
'host_no_more_notifications' => 'hs.no_more_notifications',
'host_notifications_enabled' => 'hs.notifications_enabled',
'host_problem_has_been_acknowledged' => 'hs.problem_has_been_acknowledged',
'host_acknowledgement_type' => 'hs.acknowledgement_type',
'host_current_notification_number' => 'hs.current_notification_number',
'host_passive_checks_enabled' => 'hs.passive_checks_enabled',
'host_active_checks_enabled' => 'hs.active_checks_enabled',
'host_event_handler_enabled' => 'hs.event_handler_enabled',
'host_flap_detection_enabled' => 'hs.flap_detection_enabled',
'host_is_flapping' => 'hs.is_flapping',
'host_percent_state_change' => 'hs.percent_state_change',
'host_latency' => 'hs.latency',
'host_execution_time' => 'hs.execution_time',
'host_scheduled_downtime_depth' => 'hs.scheduled_downtime_depth',
'host_failure_prediction_enabled' => 'hs.failure_prediction_enabled',
'host_process_performance_data' => 'hs.process_performance_data',
'host_obsess_over_host' => 'hs.obsess_over_host',
'host_modified_host_attributes' => 'hs.modified_host_attributes',
'host_event_handler' => 'hs.event_handler',
'host_check_command' => 'hs.check_command',
'host_normal_check_interval' => 'hs.normal_check_interval',
'host_retry_check_interval' => 'hs.retry_check_interval',
'host_check_timeperiod_object_id' => 'hs.check_timeperiod_object_id',
'host_problems' => 'CASE WHEN hs.current_state = 0 THEN 0 ELSE 1 END',
'host_severity' => 'CASE WHEN hs.current_state = 0

View File

@ -104,4 +104,27 @@ font-size: 12px;
.container-spacer {
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;
}
}

View File

@ -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);
}
}

View File

@ -8,6 +8,7 @@
<directory>application/</directory>
<directory>bin/</directory>
<directory>library/</directory>
<directory>modules/</directory>
</testsuite>
<!--