diff --git a/modules/monitoring/application/views/scripts/partials/object/detail-content.phtml b/modules/monitoring/application/views/scripts/partials/object/detail-content.phtml index c7d454a0b..5fa2a46c0 100644 --- a/modules/monitoring/application/views/scripts/partials/object/detail-content.phtml +++ b/modules/monitoring/application/views/scripts/partials/object/detail-content.phtml @@ -1,6 +1,7 @@
render('show/components/output.phtml') ?> render('show/components/grapher.phtml') ?> + render('show/components/extensions.phtml') ?>

translate('Problem handling') ?>

diff --git a/modules/monitoring/application/views/scripts/show/components/extensions.phtml b/modules/monitoring/application/views/scripts/show/components/extensions.phtml new file mode 100644 index 000000000..263b7e472 --- /dev/null +++ b/modules/monitoring/application/views/scripts/show/components/extensions.phtml @@ -0,0 +1,4 @@ + Detail View Extension Hook + +## About + +This hook can be used to easily extend the detail view of monitored objects (hosts and services). + +## How it works + +### Directory structure + +* `icingaweb2/modules/example` + * `library/Example/ProvidedHook/Monitoring/DetailviewExtension/Simple.php` + * `run.php` + +### Files + +#### run.php + +```php +provideHook( + 'monitoring/DetailviewExtension', + 'Icinga\Module\Example\ProvidedHook\Monitoring\DetailviewExtension\Simple' +); +``` + +#### Simple.php + +```php +name) as $c) { + if (isset($stats[$c])) { + ++$stats[$c]; + } else { + $stats[$c] = 1; + } + } + + ksort($stats); + + $view = $this->getView(); + + $thead = ''; + $tbody = ''; + foreach ($stats as $c => $amount) { + $thead .= ''; + $tbody .= ''; + } + + return '

' + . $view->escape(sprintf($view->translate('A %s named "%s"'), $object->getType(), $object->name)) + . '

' + . '

Character stats

' + . '
' . $view->escape($c) . '' . $amount . '
' + . '' . $thead . '' + . '' . $tbody . '' + . '
'; + } +} +``` + +## How it looks like + +![Screenshot](res/detailviewextension-01.png) diff --git a/modules/monitoring/doc/res/detailviewextension-01.png b/modules/monitoring/doc/res/detailviewextension-01.png new file mode 100644 index 000000000..a5ddaf188 Binary files /dev/null and b/modules/monitoring/doc/res/detailviewextension-01.png differ diff --git a/modules/monitoring/library/Monitoring/Hook/DetailviewExtensionHook.php b/modules/monitoring/library/Monitoring/Hook/DetailviewExtensionHook.php new file mode 100644 index 000000000..b86573f9c --- /dev/null +++ b/modules/monitoring/library/Monitoring/Hook/DetailviewExtensionHook.php @@ -0,0 +1,71 @@ +init(); + } + + /** + * Overwrite this function for hook initialization, e.g. loading the hook's config + */ + protected function init() + { + } + + /** + * Shall return valid HTML to include in the detail view + * + * @param MonitoredObject $object The object to generate HTML for + * + * @return string + */ + abstract public function getHtmlForObject(MonitoredObject $object); + + /** + * Get {@link view} + * + * @return View + */ + public function getView() + { + return $this->view; + } + + /** + * Set {@link view} + * + * @param View $view + * + * @return $this + */ + public function setView($view) + { + $this->view = $view; + return $this; + } +} diff --git a/modules/monitoring/library/Monitoring/Web/Controller/MonitoredObjectController.php b/modules/monitoring/library/Monitoring/Web/Controller/MonitoredObjectController.php index 9ea05f02b..52cd4afbd 100644 --- a/modules/monitoring/library/Monitoring/Web/Controller/MonitoredObjectController.php +++ b/modules/monitoring/library/Monitoring/Web/Controller/MonitoredObjectController.php @@ -10,6 +10,7 @@ use Icinga\Module\Monitoring\Forms\Command\Object\DeleteDowntimeCommandForm; use Icinga\Module\Monitoring\Forms\Command\Object\ObjectsCommandForm; use Icinga\Module\Monitoring\Forms\Command\Object\RemoveAcknowledgementCommandForm; use Icinga\Module\Monitoring\Forms\Command\Object\ToggleObjectFeaturesCommandForm; +use Icinga\Module\Monitoring\Hook\DetailviewExtensionHook; use Icinga\Web\Hook; use Icinga\Web\Url; use Icinga\Web\Widget\Tabextension\DashboardAction; @@ -96,6 +97,12 @@ abstract class MonitoredObjectController extends Controller } $this->view->showInstance = $this->backend->select()->from('instance')->count() > 1; $this->view->object = $this->object; + + $this->view->extensionsHtml = array(); + foreach (Hook::all('Monitoring\DetailviewExtension') as $hook) { + /** @var DetailviewExtensionHook $hook */ + $this->view->extensionsHtml[] = $hook->setView($this->view)->getHtmlForObject($this->object); + } } /**