From 7e5b5a0b30856c7904a18563e39e57c90efaa02f Mon Sep 17 00:00:00 2001 From: Marius Hein Date: Wed, 27 Aug 2014 09:35:43 +0200 Subject: [PATCH] Hook/Grapher: Rework hook interface Rework interface based on specification and changed consumer calls. refs #6932 --- library/Icinga/Web/Hook/GrapherHook.php | 63 +++++++++++++++---- .../controllers/ShowController.php | 11 ++-- 2 files changed, 59 insertions(+), 15 deletions(-) diff --git a/library/Icinga/Web/Hook/GrapherHook.php b/library/Icinga/Web/Hook/GrapherHook.php index e2fea304a..99ab8a8f6 100644 --- a/library/Icinga/Web/Hook/GrapherHook.php +++ b/library/Icinga/Web/Hook/GrapherHook.php @@ -4,6 +4,8 @@ namespace Icinga\Web\Hook; +use Icinga\Exception\ProgrammingError; + /** * Icinga Web Grapher Hook base class * @@ -14,7 +16,7 @@ namespace Icinga\Web\Hook; * @author Icinga-Web Team * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License */ -class GrapherHook +abstract class GrapherHook { /** * Whether this grapher provides preview images @@ -56,9 +58,13 @@ class GrapherHook /** * Whether a graph for the given host[, service [, plot]] exists * + * @param string $host + * @param string $service + * @param string $plot + * * @return bool */ - public function hasGraph($host, $service = null, $plot = null) + public function has($host, $service = null, $plot = null) { return false; } @@ -66,13 +72,47 @@ class GrapherHook /** * Get a preview image for the given host[, service [, plot]] exists * - * WARNING: We are not sure yet whether this will remain as is + * @param string $host + * @param string $service + * @param string $plot * - * @return string + * @return string + * + * @throws ProgrammingError */ - public function getPreviewImage($host, $service = null, $plot = null) + public function getPreviewHtml($host, $service = null, $plot = null) { - throw new Exception('This backend has no preview images'); + throw new ProgrammingError('This backend has no preview images'); + } + + /** + * Whether a tiny graph for the given host[, service [, plot]] exists + * + * @param string $host + * @param string $service + * @param string $plot + * + * @return bool + */ + public function hasTinyPreview($host, $service = null, $plot = null) + { + return false; + } + + /** + * Get a tiny preview image for the given host[, service [, plot]] exists + * + * @param string $host + * @param string $service + * @param string $plot + * + * @return string + * + * @throws ProgrammingError + */ + public function getTinyPreviewHtml($host, $service = null, $plot = null) + { + throw new ProgrammingError('This backend has no tiny preview images'); } /** @@ -80,10 +120,11 @@ class GrapherHook * * WARNING: We are not sure yet whether this will remain as is * - * @return string + * @param string $host + * @param string $service + * @param string $plot + * + * @return string */ - public function getGraphUrl($host, $service = null, $plot = null) - { - throw new Exception('This backend has no images'); - } + abstract function getGraphUrl($host, $service = null, $plot = null); } diff --git a/modules/monitoring/application/controllers/ShowController.php b/modules/monitoring/application/controllers/ShowController.php index d503ba512..55b57cd52 100644 --- a/modules/monitoring/application/controllers/ShowController.php +++ b/modules/monitoring/application/controllers/ShowController.php @@ -25,6 +25,9 @@ class Monitoring_ShowController extends Controller */ protected $backend; + /** + * @var Hook\GrapherHook + */ protected $grapher; /** @@ -61,8 +64,8 @@ class Monitoring_ShowController extends Controller . ' on ' . $o->host_name; $this->getTabs()->activate('service'); $o->populate(); - if ($this->grapher && $this->grapher->hasGraph($o->host_name, $o->service_description)) { - $this->view->grapherHtml = $this->grapher->getPreviewImage($o->host_name, $o->service_description); + if ($this->grapher && $this->grapher->hasPreviews($o->host_name, $o->service_description)) { + $this->view->grapherHtml = $this->grapher->getPreviewHtml($o->host_name, $o->service_description); } } @@ -76,8 +79,8 @@ class Monitoring_ShowController extends Controller $this->getTabs()->activate('host'); $this->view->title = $o->host_name; $o->populate(); - if ($this->grapher && $this->grapher->hasGraph($o->host_name)) { - $this->view->grapherHtml = $this->grapher->getPreviewImage($o->host_name); + if ($this->grapher && $this->grapher->hasPreviews($o->host_name)) { + $this->view->grapherHtml = $this->grapher->getPreviewHtml($o->host_name); } }