diff --git a/modules/monitoring/application/controllers/EventController.php b/modules/monitoring/application/controllers/EventController.php index d0a8d3156..b2ecd0754 100644 --- a/modules/monitoring/application/controllers/EventController.php +++ b/modules/monitoring/application/controllers/EventController.php @@ -5,6 +5,8 @@ namespace Icinga\Module\Monitoring\Controllers; use DateTime; use DateTimeZone; +use Icinga\Module\Monitoring\Hook\EventDetailsExtensionHook; +use Icinga\Application\Hook; use InvalidArgumentException; use Icinga\Data\Queryable; use Icinga\Date\DateFormatter; @@ -70,6 +72,24 @@ class EventController extends Controller $this->getDetails($type, $event) ); + $this->view->extensionsHtml = array(); + /** @var EventDetailsExtensionHook $hook */ + foreach (Hook::all('Monitoring\\EventDetailsExtension') as $hook) { + try { + $html = $hook->getHtmlForEvent($object); + } catch (\Exception $e) { + $html = $this->view->escape($e->getMessage()); + } + + if ($html) { + $module = $this->view->escape($hook->getModule()->getName()); + $this->view->extensionsHtml[] = + '
' + . $html + . '
'; + } + } + $this->view->title = $this->translate('Event Overview'); $this->getTabs() ->add('event', array( diff --git a/modules/monitoring/application/views/scripts/event/show.phtml b/modules/monitoring/application/views/scripts/event/show.phtml index 63f1cb965..c844a6f1a 100644 --- a/modules/monitoring/application/views/scripts/event/show.phtml +++ b/modules/monitoring/application/views/scripts/event/show.phtml @@ -17,6 +17,12 @@ echo $object instanceof Service ?>
+ +

escape($this->translate('Event Details')) ?>

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 object $object The object to generate HTML for + * + * @return string + */ + abstract public function getHtmlForEvent($event); + + /** + * Get the module of the derived class + * + * @return Module + * @throws \Icinga\Exception\ProgrammingError + */ + public function getModule() + { + if ($this->module === null) { + $class = get_class($this); + if (ClassLoader::classBelongsToModule($class)) { + $this->module = Icinga::app()->getModuleManager()->getModule(ClassLoader::extractModuleName($class)); + } + } + return $this->module; + } + + /** + * Set the module of the derived class + * + * @param Module $module + * + * @return $this + */ + public function setModule(Module $module) + { + $this->module = $module; + return $this; + } +}