Hook/Grapher: Rework hook interface

Rework interface based on specification and changed consumer calls.

refs #6932
This commit is contained in:
Marius Hein 2014-08-27 09:35:43 +02:00
parent 376e9aa160
commit 7e5b5a0b30
2 changed files with 59 additions and 15 deletions

View File

@ -4,6 +4,8 @@
namespace Icinga\Web\Hook; namespace Icinga\Web\Hook;
use Icinga\Exception\ProgrammingError;
/** /**
* Icinga Web Grapher Hook base class * Icinga Web Grapher Hook base class
* *
@ -14,7 +16,7 @@ namespace Icinga\Web\Hook;
* @author Icinga-Web Team <info@icinga.org> * @author Icinga-Web Team <info@icinga.org>
* @license http://www.gnu.org/copyleft/gpl.html GNU General Public License * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License
*/ */
class GrapherHook abstract class GrapherHook
{ {
/** /**
* Whether this grapher provides preview images * Whether this grapher provides preview images
@ -56,9 +58,13 @@ class GrapherHook
/** /**
* Whether a graph for the given host[, service [, plot]] exists * Whether a graph for the given host[, service [, plot]] exists
* *
* @param string $host
* @param string $service
* @param string $plot
*
* @return bool * @return bool
*/ */
public function hasGraph($host, $service = null, $plot = null) public function has($host, $service = null, $plot = null)
{ {
return false; return false;
} }
@ -66,13 +72,47 @@ class GrapherHook
/** /**
* Get a preview image for the given host[, service [, plot]] exists * 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 * 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
*/ */
public function getGraphUrl($host, $service = null, $plot = null) abstract function getGraphUrl($host, $service = null, $plot = null);
{
throw new Exception('This backend has no images');
}
} }

View File

@ -25,6 +25,9 @@ class Monitoring_ShowController extends Controller
*/ */
protected $backend; protected $backend;
/**
* @var Hook\GrapherHook
*/
protected $grapher; protected $grapher;
/** /**
@ -61,8 +64,8 @@ class Monitoring_ShowController extends Controller
. ' on ' . $o->host_name; . ' on ' . $o->host_name;
$this->getTabs()->activate('service'); $this->getTabs()->activate('service');
$o->populate(); $o->populate();
if ($this->grapher && $this->grapher->hasGraph($o->host_name, $o->service_description)) { if ($this->grapher && $this->grapher->hasPreviews($o->host_name, $o->service_description)) {
$this->view->grapherHtml = $this->grapher->getPreviewImage($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->getTabs()->activate('host');
$this->view->title = $o->host_name; $this->view->title = $o->host_name;
$o->populate(); $o->populate();
if ($this->grapher && $this->grapher->hasGraph($o->host_name)) { if ($this->grapher && $this->grapher->hasPreviews($o->host_name)) {
$this->view->grapherHtml = $this->grapher->getPreviewImage($o->host_name); $this->view->grapherHtml = $this->grapher->getPreviewHtml($o->host_name);
} }
} }