From bc54d5914663f7b8fbadcea37d62d366287c7751 Mon Sep 17 00:00:00 2001 From: Matthias Date: Fri, 15 Jun 2018 11:35:38 +0200 Subject: [PATCH] Added Grapher --- .../Businessprocess/ProvidedHook/Grapher.php | 81 +++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 library/Businessprocess/ProvidedHook/Grapher.php diff --git a/library/Businessprocess/ProvidedHook/Grapher.php b/library/Businessprocess/ProvidedHook/Grapher.php new file mode 100644 index 0000000..a911f45 --- /dev/null +++ b/library/Businessprocess/ProvidedHook/Grapher.php @@ -0,0 +1,81 @@ +storage = new LegacyStorage( + Config::module('businessprocess')->getSection('global') + ); + } catch (\Exception $e) { + // Ignore and don't display anything + } + + $this->hasPreviews = true; + } + + /** + * Returns false if the MonitoredObject is not a service or the check_command is not icingacli-businessprocess + * + * @param MonitoredObject $object + * @return bool + */ + public function has(MonitoredObject $object) + { + return $object instanceof Service && $object->check_command == 'icingacli-businessprocess'; + } + + + /** + * Returns the rendered Tree-/TileRenderer HTML + * + * @param MonitoredObject $object + * @return string + * @throws \Icinga\Exception\ProgrammingError + */ + public function getPreviewHtml(MonitoredObject $object) + { + if (!$this->has($object) || !$this->storage) { + return ''; + } + + $bpName = $object->_service_icingacli_businessprocess_process; + $bp = $this->storage->loadProcess($bpName); + + MonitoringState::apply($bp); + + if (filter_var($object->_service_icingacli_businessprocess_grapher_tree, FILTER_VALIDATE_BOOLEAN)) { + $renderer = new TreeRenderer($bp); + } else { + $renderer = new TileRenderer($bp); + } + + $renderer->setBaseUrl(Url::fromPath('businessprocess/process/show?config=' . $bpName . '&node=' . $bpName)); + + $html = '

Business Process

'; + $html = $html . $renderer->render() . '
'; + return $html; + } +}