From 4ac7557c2ff93c82cd8aa1b15e789443c0958079 Mon Sep 17 00:00:00 2001 From: Matthias Jentsch Date: Tue, 26 May 2015 15:47:01 +0200 Subject: [PATCH 1/2] Show host and service notes in the host and service detail view refs #8235 --- .../application/views/scripts/host/show.phtml | 1 + .../views/scripts/service/show.phtml | 1 + .../scripts/show/components/actions.phtml | 12 ------ .../views/scripts/show/components/notes.phtml | 28 +++++++++++++ .../Backend/Ido/Query/StatusQuery.php | 2 + .../library/Monitoring/Object/Host.php | 11 +++++ .../Monitoring/Object/MonitoredObject.php | 40 +++++++++++++++++++ .../library/Monitoring/Object/Service.php | 11 +++++ 8 files changed, 94 insertions(+), 12 deletions(-) create mode 100644 modules/monitoring/application/views/scripts/show/components/notes.phtml diff --git a/modules/monitoring/application/views/scripts/host/show.phtml b/modules/monitoring/application/views/scripts/host/show.phtml index 32389515b..76d8c1b55 100644 --- a/modules/monitoring/application/views/scripts/host/show.phtml +++ b/modules/monitoring/application/views/scripts/host/show.phtml @@ -11,6 +11,7 @@ + render('show/components/notes.phtml') ?> render('show/components/acknowledgement.phtml') ?> render('show/components/comments.phtml') ?> render('show/components/notifications.phtml') ?> diff --git a/modules/monitoring/application/views/scripts/service/show.phtml b/modules/monitoring/application/views/scripts/service/show.phtml index 4d33644ce..43dc77030 100644 --- a/modules/monitoring/application/views/scripts/service/show.phtml +++ b/modules/monitoring/application/views/scripts/service/show.phtml @@ -11,6 +11,7 @@
+ render('show/components/notes.phtml') ?> render('show/components/acknowledgement.phtml') ?> render('show/components/comments.phtml') ?> render('show/components/notifications.phtml') ?> diff --git a/modules/monitoring/application/views/scripts/show/components/actions.phtml b/modules/monitoring/application/views/scripts/show/components/actions.phtml index 0681d5d91..35077abc0 100644 --- a/modules/monitoring/application/views/scripts/show/components/actions.phtml +++ b/modules/monitoring/application/views/scripts/show/components/actions.phtml @@ -8,18 +8,6 @@ $newTabInfo = sprintf(' %s ', $th $linkText = '%s ' . $newTabInfo . ''; $localLinkText = '%s'; -if ($object->notes_url) { - if (strpos($object->notes_url, "' ") === false) { - $links[] = sprintf($linkText, $this->resolveMacros($object->notes_url, $object), 'Notes'); - } else { - // TODO: We should find out document what's going on here. Looks strange :p - foreach(explode("' ", $object->notes_url) as $url) { - $url = strpos($url, "'") === 0 ? substr($url, 1) : $url; - $url = strrpos($url, "'") === strlen($url) - 1 ? substr($url, 0, strlen($url) - 1) : $url; - $links[] = sprintf($linkText, $this->resolveMacros($url, $object), 'Notes'); - } - } -} if ($object->action_url) { if (strpos($object->action_url, "' ") === false) { $links[] = sprintf($linkText, $this->resolveMacros($object->action_url, $object), 'Action'); diff --git a/modules/monitoring/application/views/scripts/show/components/notes.phtml b/modules/monitoring/application/views/scripts/show/components/notes.phtml new file mode 100644 index 000000000..cdc379184 --- /dev/null +++ b/modules/monitoring/application/views/scripts/show/components/notes.phtml @@ -0,0 +1,28 @@ +getNotes()); +$links = $object->getNotesUrls(); +?> + + + + + + + \ No newline at end of file diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/StatusQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/StatusQuery.php index 2aad7d31c..7181e8b89 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/StatusQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/StatusQuery.php @@ -43,6 +43,7 @@ class StatusQuery extends IdoQuery 'host_icon_image' => 'h.icon_image', 'host_icon_image_alt' => 'h.icon_image_alt', 'host_action_url' => 'h.action_url', + 'host_notes' => 'h.notes', 'host_notes_url' => 'h.notes_url' ), 'hoststatus' => array( @@ -179,6 +180,7 @@ class StatusQuery extends IdoQuery 'service_icon_image' => 's.icon_image', 'service_icon_image_alt' => 's.icon_image_alt', 'service_action_url' => 's.action_url', + 'service_notes' => 's.notes', 'service_notes_url' => 's.notes_url', 'object_type' => '(\'service\')' ), diff --git a/modules/monitoring/library/Monitoring/Object/Host.php b/modules/monitoring/library/Monitoring/Object/Host.php index a158625b5..6bf6b05cc 100644 --- a/modules/monitoring/library/Monitoring/Object/Host.php +++ b/modules/monitoring/library/Monitoring/Object/Host.php @@ -119,6 +119,7 @@ class Host extends MonitoredObject 'host_max_check_attempts', 'host_name', 'host_next_check', + 'host_notes', 'host_notes_url', 'host_notifications_enabled', 'host_notifications_enabled_changed', @@ -188,4 +189,14 @@ class Host extends MonitoredObject } return $text; } + + public function getNotesUrls() + { + return MonitoredObject::parseAttributeUrls($this->host_notes_url); + } + + public function getNotes() + { + return $this->host_notes; + } } diff --git a/modules/monitoring/library/Monitoring/Object/MonitoredObject.php b/modules/monitoring/library/Monitoring/Object/MonitoredObject.php index 05f201428..236ca2aaa 100644 --- a/modules/monitoring/library/Monitoring/Object/MonitoredObject.php +++ b/modules/monitoring/library/Monitoring/Object/MonitoredObject.php @@ -563,4 +563,44 @@ abstract class MonitoredObject implements Filterable } return null; } + + /** + * The notes for this monitored object + * + * @return string The notes as a string + */ + public function getNotes() {} + + /** + * Get all note urls configured for this monitored object + * + * @return array All note urls as a string + */ + public function getNotesUrls() {} + + /** + * Parse the content of the action_url or notes_url attributes + * + * @link http://docs.icinga.org/latest/de/objectdefinitions.html + * + * @param string $urlString A string containing one or more urls + * @return array Array of urls as strings + */ + public static function parseAttributeUrls($urlString) + { + if (empty($urlString)) { + return array(); + } + if (strpos($urlString, "' ") === false) { + $links[] = $urlString; + } else { + // parse notes-url format + foreach (explode("' ", $urlString) as $url) { + $url = strpos($url, "'") === 0 ? substr($url, 1) : $url; + $url = strrpos($url, "'") === strlen($url) - 1 ? substr($url, 0, strlen($url) - 1) : $url; + $links[] = $url; + } + } + return $links; + } } diff --git a/modules/monitoring/library/Monitoring/Object/Service.php b/modules/monitoring/library/Monitoring/Object/Service.php index 0e8c975f2..17fd143b5 100644 --- a/modules/monitoring/library/Monitoring/Object/Service.php +++ b/modules/monitoring/library/Monitoring/Object/Service.php @@ -147,6 +147,7 @@ class Service extends MonitoredObject 'service_last_state_change', 'service_long_output', 'service_next_check', + 'service_notes', 'service_notes_url', 'service_notifications_enabled', 'service_notifications_enabled_changed', @@ -198,4 +199,14 @@ class Service extends MonitoredObject } return $text; } + + public function getNotesUrls() + { + return MonitoredObject::parseAttributeUrls($this->service_notes_url); + } + + public function getNotes() + { + return $this->service_notes; + } } From a7135bad62b83445f298d6fcdfe5814e163b3193 Mon Sep 17 00:00:00 2001 From: Matthias Jentsch Date: Tue, 26 May 2015 16:49:08 +0200 Subject: [PATCH 2/2] Resolve runtime macros in notes too refs #8235 --- .../application/views/scripts/show/components/notes.phtml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/modules/monitoring/application/views/scripts/show/components/notes.phtml b/modules/monitoring/application/views/scripts/show/components/notes.phtml index cdc379184..678d70c90 100644 --- a/modules/monitoring/application/views/scripts/show/components/notes.phtml +++ b/modules/monitoring/application/views/scripts/show/components/notes.phtml @@ -9,6 +9,7 @@ $links = $object->getNotesUrls(); - \ No newline at end of file +
translate('Notes') ?> + '; + } + // add warning to links that open in new tabs to improve accessibility, as recommended by WCAG20 G201 + $newTabInfo = sprintf( + ' %s ', + $this->translate('opens in new window') + ); + $linkText = '%s ' . $newTabInfo . ''; + foreach ($links as $i => $link) { + $resolved = $this->resolveMacros($link, $object); + $links[$i] = sprintf($linkText, $this->escape($resolved), $this->escape($resolved)); + } + echo implode('
', $links); + ?> +
resolveMacros($notes, $object); echo $notes . '
'; } // add warning to links that open in new tabs to improve accessibility, as recommended by WCAG20 G201 @@ -25,4 +26,4 @@ $links = $object->getNotesUrls(); ?>