diff --git a/library/Icinga/Web/Hook.php b/library/Icinga/Web/Hook.php index b88069da1..8e65bb33c 100644 --- a/library/Icinga/Web/Hook.php +++ b/library/Icinga/Web/Hook.php @@ -123,7 +123,12 @@ class Hook */ private static function assertValidHook($instance, $name) { - $base_class = self::$BASE_NS . ucfirst($name) . self::$classSuffix; + $base_class = self::$BASE_NS . ucfirst($name); + + if (strpos($base_class, self::$classSuffix) === false) { + $base_class .= self::$classSuffix; + } + if (!$instance instanceof $base_class) { throw new ProgrammingError( '%s is not an instance of %s', diff --git a/library/Icinga/Web/Hook/GrapherHook.php b/library/Icinga/Web/Hook/GrapherHook.php index 99ab8a8f6..a48c50ed6 100644 --- a/library/Icinga/Web/Hook/GrapherHook.php +++ b/library/Icinga/Web/Hook/GrapherHook.php @@ -5,26 +5,30 @@ namespace Icinga\Web\Hook; use Icinga\Exception\ProgrammingError; +use Icinga\Module\Monitoring\Object\MonitoredObject; /** * Icinga Web Grapher Hook base class * * Extend this class if you want to integrate your graphing solution nicely into - * Icinga Web - * - * @copyright Copyright (c) 2013 Icinga-Web Team - * @author Icinga-Web Team - * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License + * Icinga Web. */ -abstract class GrapherHook +abstract class GrapherHook extends WebBaseHook { /** - * Whether this grapher provides preview images + * Whether this grapher provides previews * * @var bool */ protected $hasPreviews = false; + /** + * Whether this grapher provides tiny previews + * + * @var bool + */ + protected $hasTinyPreviews = false; + /** * Constructor must live without arguments right now * @@ -36,16 +40,6 @@ abstract class GrapherHook $this->init(); } - /** - * Whether this grapher provides preview images - * - * @return bool - */ - public function hasPreviews() - { - return $this->hasPreviews; - } - /** * Overwrite this function if you want to do some initialization stuff * @@ -56,75 +50,63 @@ abstract class GrapherHook } /** - * Whether a graph for the given host[, service [, plot]] exists - * - * @param string $host - * @param string $service - * @param string $plot + * Whether this grapher provides previews * * @return bool */ - public function has($host, $service = null, $plot = null) + public function hasPreviews() { - return false; + return $this->hasPreviews; } /** - * Get a preview image for the given host[, service [, plot]] exists + * Whether this grapher provides tiny previews * - * @param string $host - * @param string $service - * @param string $plot - * - * @return string - * - * @throws ProgrammingError + * @return bool */ - public function getPreviewHtml($host, $service = null, $plot = null) + public function hasTinyPreviews() { - throw new ProgrammingError('This backend has no preview images'); + return $this->hasTinyPreviews; } /** - * Whether a tiny graph for the given host[, service [, plot]] exists + * Whether a graph for the monitoring object exist * - * @param string $host - * @param string $service - * @param string $plot + * @param MonitoredObject $object * * @return bool */ - public function hasTinyPreview($host, $service = null, $plot = null) - { - return false; - } + abstract public function has(MonitoredObject $object); /** - * Get a tiny preview image for the given host[, service [, plot]] exists + * Get a preview for the given object * - * @param string $host - * @param string $service - * @param string $plot + * This function must return an empty string if no graph exists. + * + * @param MonitoredObject $object * * @return string + * @throws ProgrammingError * + */ + public function getPreviewHtml(MonitoredObject $object) + { + throw new ProgrammingError('This hook provide previews but it is not implemented'); + } + + + /** + * Get a tiny preview for the given object + * + * This function must return an empty string if no graph exists. + * + * @param MonitoredObject $object + * + * @return string * @throws ProgrammingError */ - public function getTinyPreviewHtml($host, $service = null, $plot = null) + public function getTinyPreviewHtml(MonitoredObject $object) { - throw new ProgrammingError('This backend has no tiny preview images'); + throw new ProgrammingError('This hook provide tiny previews but it is not implemented'); } - - /** - * Get URL pointing to the grapher - * - * WARNING: We are not sure yet whether this will remain as is - * - * @param string $host - * @param string $service - * @param string $plot - * - * @return string - */ - 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 0200284ce..6c4d3c310 100644 --- a/modules/monitoring/application/controllers/ShowController.php +++ b/modules/monitoring/application/controllers/ShowController.php @@ -3,13 +3,13 @@ // {{{ICINGA_LICENSE_HEADER}}} use Icinga\Application\Benchmark; +use Icinga\Module\Monitoring\Object\MonitoredObject; use Icinga\Web\Hook; use Icinga\Web\Widget\Tabs; use Icinga\Web\Widget\Tabextension\OutputFormat; use Icinga\Web\Widget\Tabextension\DashboardAction; use Icinga\Module\Monitoring\Backend; use Icinga\Module\Monitoring\Controller; -use Icinga\Module\Monitoring\Object\AbstractObject; use Icinga\Module\Monitoring\Object\Host; use Icinga\Module\Monitoring\Object\Service; @@ -41,7 +41,7 @@ class Monitoring_ShowController extends Controller $this->view->object = new Service($this->params); } else { // TODO: Well... this could be done better - $this->view->object = AbstractObject::fromParams($this->params); + $this->view->object = MonitoredObject::fromParams($this->params); } if (Hook::has('ticket')) { $this->view->tickets = Hook::first('ticket'); diff --git a/modules/monitoring/application/forms/Command/ScheduleDowntimeForm.php b/modules/monitoring/application/forms/Command/ScheduleDowntimeForm.php index 593654c02..73ce2666c 100644 --- a/modules/monitoring/application/forms/Command/ScheduleDowntimeForm.php +++ b/modules/monitoring/application/forms/Command/ScheduleDowntimeForm.php @@ -4,6 +4,7 @@ namespace Icinga\Module\Monitoring\Form\Command; +use Icinga\Module\Monitoring\Object\MonitoredObject; use Zend_Form_Element_Text; use Zend_Validate_GreaterThan; use Zend_Validate_Digits; @@ -12,7 +13,6 @@ use Icinga\Protocol\Commandpipe\Comment; use Icinga\Util\DateTimeFactory; use Icinga\Module\Monitoring\Backend; use Icinga\Module\Monitoring\Command\ScheduleDowntimeCommand; -use Icinga\Module\Monitoring\Object\AbstractObject; use Icinga\Module\Monitoring\Object\Service; use Icinga\Web\Url; @@ -67,7 +67,7 @@ class ScheduleDowntimeForm extends WithChildrenCommandForm $cfg = $this->getConfiguration(); $preferences = $this->getUserPreferences(); - $object = AbstractObject::fromParams(Url::fromRequest()->getParams()); + $object = MonitoredObject::fromParams(Url::fromRequest()->getParams()); $object->fetchDowntimes(); $downtimes = $object->downtimes; /* diff --git a/modules/monitoring/application/views/helpers/MonitoringFlags.php b/modules/monitoring/application/views/helpers/MonitoringFlags.php index f543fac59..db4b8dedc 100644 --- a/modules/monitoring/application/views/helpers/MonitoringFlags.php +++ b/modules/monitoring/application/views/helpers/MonitoringFlags.php @@ -2,7 +2,7 @@ // {{{ICINGA_LICENSE_HEADER}}} // {{{ICINGA_LICENSE_HEADER}}} -/*use Icinga\Module\Monitoring\Object\AbstractObject;*/ +/* use Icinga\Module\Monitoring\Object\MonitoredObject; */ /** * Rendering helper for object's properties which may be either enabled or disabled @@ -26,11 +26,11 @@ class Zend_View_Helper_MonitoringFlags extends Zend_View_Helper_Abstract /** * Retrieve flags as array with either true or false as value * - * @param AbstractObject $object + * @param MonitoredObject $object * * @return array */ - public function monitoringFlags(/*AbstractObject*/$object) + public function monitoringFlags(/*MonitoredObject*/ $object) { $flags = array(); foreach (self::$flags as $column => $description) { diff --git a/modules/monitoring/application/views/helpers/ResolveMacros.php b/modules/monitoring/application/views/helpers/ResolveMacros.php index b0f007b19..385962a85 100644 --- a/modules/monitoring/application/views/helpers/ResolveMacros.php +++ b/modules/monitoring/application/views/helpers/ResolveMacros.php @@ -3,7 +3,7 @@ // {{{ICINGA_LICENSE_HEADER}}} use \Zend_View_Helper_Abstract; -use Icinga\Module\Monitoring\Object\AbstractObject; +use Icinga\Module\Monitoring\Object\MonitoredObject; class Zend_View_Helper_ResolveMacros extends Zend_View_Helper_Abstract { @@ -22,7 +22,7 @@ class Zend_View_Helper_ResolveMacros extends Zend_View_Helper_Abstract * Return the given string with macros being resolved * * @param string $input The string in which to look for macros - * @param AbstractObject|stdClass $object The host or service used to resolve macros + * @param MonitoredObject|stdClass $object The host or service used to resolve macros * * @return string The substituted or unchanged string */ @@ -45,7 +45,7 @@ class Zend_View_Helper_ResolveMacros extends Zend_View_Helper_Abstract * Resolve a macro based on the given object * * @param string $macro The macro to resolve - * @param AbstractObject|stdClass $object The object used to resolve the macro + * @param MonitoredObject|stdClass $object The object used to resolve the macro * * @return string The new value or the macro if it cannot be resolved */ diff --git a/modules/monitoring/library/Monitoring/Object/Host.php b/modules/monitoring/library/Monitoring/Object/Host.php index 8dbe1176e..7cbe637de 100644 --- a/modules/monitoring/library/Monitoring/Object/Host.php +++ b/modules/monitoring/library/Monitoring/Object/Host.php @@ -7,7 +7,7 @@ namespace Icinga\Module\Monitoring\Object; use Icinga\Module\Monitoring\DataView\HostStatus; use Icinga\Data\Db\DbQuery; -class Host extends AbstractObject +class Host extends MonitoredObject { public $type = 'host'; public $prefix = 'host_'; diff --git a/modules/monitoring/library/Monitoring/Object/AbstractObject.php b/modules/monitoring/library/Monitoring/Object/MonitoredObject.php similarity index 99% rename from modules/monitoring/library/Monitoring/Object/AbstractObject.php rename to modules/monitoring/library/Monitoring/Object/MonitoredObject.php index 703d05780..8ff79f7b8 100644 --- a/modules/monitoring/library/Monitoring/Object/AbstractObject.php +++ b/modules/monitoring/library/Monitoring/Object/MonitoredObject.php @@ -23,7 +23,7 @@ use Icinga\Web\UrlParams; use Icinga\Application\Config; -abstract class AbstractObject +abstract class MonitoredObject { public $type; public $prefix; diff --git a/modules/monitoring/library/Monitoring/Object/Service.php b/modules/monitoring/library/Monitoring/Object/Service.php index 598bb384d..3c9be7c2c 100644 --- a/modules/monitoring/library/Monitoring/Object/Service.php +++ b/modules/monitoring/library/Monitoring/Object/Service.php @@ -7,7 +7,7 @@ namespace Icinga\Module\Monitoring\Object; use Icinga\Module\Monitoring\DataView\ServiceStatus; use Icinga\Data\Db\DbQuery; -class Service extends AbstractObject +class Service extends MonitoredObject { public $type = 'service'; public $prefix = 'service_';