From 1da7ea9c3672e159f1c581d1d3f80b320ec4f8bb Mon Sep 17 00:00:00 2001 From: Marius Hein Date: Mon, 8 Jul 2013 14:50:18 +0200 Subject: [PATCH] Host detail view: Add object properties Add property component and helper which output all information about an object (host or service). refs #4182 --- .../views/helpers/MonitoringProperties.php | 250 ++++++++++++++++++ .../scripts/show/components/properties.phtml | 19 ++ .../views/scripts/show/header.phtml | 6 + .../application/views/scripts/show/host.phtml | 9 + .../Monitoring/Backend/AbstractBackend.php | 3 +- .../Backend/Ido/Query/StatusQuery.php | 1 + 6 files changed, 287 insertions(+), 1 deletion(-) create mode 100644 modules/monitoring/application/views/helpers/MonitoringProperties.php create mode 100644 modules/monitoring/application/views/scripts/show/components/properties.phtml diff --git a/modules/monitoring/application/views/helpers/MonitoringProperties.php b/modules/monitoring/application/views/helpers/MonitoringProperties.php new file mode 100644 index 000000000..8fc621d1e --- /dev/null +++ b/modules/monitoring/application/views/helpers/MonitoringProperties.php @@ -0,0 +1,250 @@ + 'Current Attempt', + 'last_check' => 'Last check time', + 'buildCheckType' => 'Check type', + 'buildLatency' => 'Check latency / duration', + 'buildNextCheck' => 'Next scheduled active check', + 'buildLastStateChange' => 'Last state change', + 'buildLastNotification' => 'Last notification', + 'buildFlapping' => 'Is this %s flapping?', + 'buildScheduledDowntime' => 'In scheduled downtime?', + 'status_update_time' => 'Last update' + ); + + /** + * Return the object type + * @param stdClass $object + * @return mixed + */ + private function getObjectType(\stdClass $object) + { + return array_shift(explode('_', array_shift(array_keys(get_object_vars($object))), 2)); + } + + /** + * Drop all object specific attribute prefixes + * @param stdClass $object + * @param $type + * @return object + */ + private function dropObjectType(\stdClass $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(\stdClass $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(\stdClass $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(\stdClass $object) + { + $val = ''; + + if ($this->buildCheckType($object) === self::CHECK_PASSIVE) { + $val .= self::VALUE_NA; + } else { + $val .= $this->floatFormatter($object->latency); + } + + $val .= ' / '. $this->floatFormatter($object->execution_time). ' seconds'; + + return $val; + } + + /** + * Get string for next check + * @param stdClass $object + * @return string + */ + private function buildNextCheck(\stdClass $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(\stdClass $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(\stdClass $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(\stdClass $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(\stdClass $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(\stdClass $object) + { + $type = $this->getObjectType($object); + $object = $this->dropObjectType($object, $type); + + $out = array(); + + foreach (self::$keys as $property => $label) { + $label = sprintf($label, $type); + if (is_callable(array(&$this, $property))) { + $out[$label] = $this->$property($object); + } elseif (isset($object->{$property})) { + $out[$label] = $object->{$property}; + } + } + + return $out; + } +} diff --git a/modules/monitoring/application/views/scripts/show/components/properties.phtml b/modules/monitoring/application/views/scripts/show/components/properties.phtml new file mode 100644 index 000000000..8d43736ad --- /dev/null +++ b/modules/monitoring/application/views/scripts/show/components/properties.phtml @@ -0,0 +1,19 @@ +service)) { + $object = $this->service; +} elseif (isset($this->host)) { + $object = $this->host; +} + +$properties = $this->monitoringProperties($object); +?> + + $value) { ?> + + + + + +
\ No newline at end of file diff --git a/modules/monitoring/application/views/scripts/show/header.phtml b/modules/monitoring/application/views/scripts/show/header.phtml index cc691ab4f..d2cf62f90 100644 --- a/modules/monitoring/application/views/scripts/show/header.phtml +++ b/modules/monitoring/application/views/scripts/show/header.phtml @@ -45,6 +45,9 @@ if (!$this->compact) { > util()->getHostStateName($this->host->host_state); ?> since timeSince($this->host->host_last_state_change); ?> + host->host_acknowledged === '1') { ?> + (Has been acknowledged) + @@ -57,6 +60,9 @@ if (!$this->compact) { util()->getServiceStateName($this->service->service_state); ?> since timeSince($this->service->service_last_state_change); ?> + host->service_acknowledged === '1') { ?> + (Has been acknowledged) + diff --git a/modules/monitoring/application/views/scripts/show/host.phtml b/modules/monitoring/application/views/scripts/show/host.phtml index 35cafbfed..cc41be532 100644 --- a/modules/monitoring/application/views/scripts/show/host.phtml +++ b/modules/monitoring/application/views/scripts/show/host.phtml @@ -86,6 +86,15 @@ +
+
+ Properties +
+
+ render('show/components/properties.phtml'); ?> +
+
+
Commands diff --git a/modules/monitoring/library/Monitoring/Backend/AbstractBackend.php b/modules/monitoring/library/Monitoring/Backend/AbstractBackend.php index f9799590c..7834f0b35 100644 --- a/modules/monitoring/library/Monitoring/Backend/AbstractBackend.php +++ b/modules/monitoring/library/Monitoring/Backend/AbstractBackend.php @@ -149,7 +149,8 @@ class AbstractBackend implements DatasourceInterface 'host_check_command', 'host_normal_check_interval', 'host_retry_check_interval', - 'host_check_timeperiod_object_id' + 'host_check_timeperiod_object_id', + 'host_status_update_time' ) ); } diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/StatusQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/StatusQuery.php index ae6375977..383a06aff 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/StatusQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/StatusQuery.php @@ -66,6 +66,7 @@ class StatusQuery extends AbstractQuery '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_status_update_time' => 'hs.status_update_time', 'host_problems' => 'CASE WHEN hs.current_state = 0 THEN 0 ELSE 1 END', 'host_severity' => 'CASE WHEN hs.current_state = 0