Trying to add multiple Grapher Hooks fails
I'm currently trying to create a poc for implementing the business process tile renderer as a grapher in Icingaweb2.
To achieve that I created businessprocess/library/Businessprocess/ProvidedHook/Grapher.php:
<?php
namespace Icinga\Module\Businessprocess\ProvidedHook;
use Icinga\Application\Config;
use Icinga\Application\Hook\GrapherHook;
use Icinga\Module\Businessprocess\Renderer\TileRenderer;
use Icinga\Module\Businessprocess\State\MonitoringState;
use Icinga\Module\Businessprocess\Storage\LegacyStorage;
use Icinga\Module\Businessprocess\Web\Url;
use Icinga\Module\Monitoring\Object\MonitoredObject;
use Icinga\Module\Monitoring\Object\Service;
class Grapher extends GrapherHook
{
private $storage;
public function init()
{
try {
$this->storage = new LegacyStorage(
Config::module('businessprocess')->getSection('global')
);
} catch (Exception $e) {
// Ignore and don't display anything
}
$this->hasPreviews = true;
}
public function has(MonitoredObject $object)
{
return $object instanceof Service && $object->check_command == 'icingacli-businessprocess';
}
public function getPreviewHtml(MonitoredObject $object)
{
if (!$this->has($object) || !$this->storage) {
return '';
}
$bpName = $object->_service_icingacli_businessprocess_process;
$bp = $this->storage->loadProcess($bpName);
$node = $bp->getNode($bpName);
MonitoringState::apply($bp);
$renderer = new TileRenderer($bp, $node);
$renderer->setBaseUrl(Url::fromPath('businessprocess/process/show?config=' . $bpName . '&node=' . $bpName));
return '<div class="icinga-module module-businessprocess"><h2>Business Process</h2>' . $renderer->render() . '</div>';
}
}
And added this line to run.php:
$this->provideHook('grapher');
The result works well:

Expected Behavior
Issues arise when trying to enable the Grafana module which brings it's own Grapher: Grafana graphs and business process tiles are both rendered.
Current Behavior
Only the business process is rendered. Grafana is not visible even on services where my grapher's has() method returns false.
When renaming my Grapher class to anything else Grafana shows up again but I can't get my tile to render. Even when disabling Grafana again my hook only seems to work, when the class is precisely named Grapher.
Possible Solution
Not sure. There seems to be an issue with how the Grapher objects are created and rendered.
Steps to Reproduce (for bugs)
- See my initial description. Just create/edit the two files
- Create a service with the icingacli-businessprocess command (the business process needs to have the same name as the root node. It's a poc and I haven't found out how to get the business process the node referenced in the check command belongs to).
- Experiment with en-/disabling the Grafana module and renaming the Grapher fil.e
Your Environment
- Icinga Web 2 version and modules (System - About): 2.5.3
- Business Process: 2.1.0
- Grafana: 1.2.1
- Version used (
icinga2 --version): 2.8.4 - Operating System and version: Debian 9.4, PHP 7.0
After digging some more I found out Icingaweb2 only seems to support a single active grapher hook. That's pretty restrictive. It would be great if you could add multiple graphers.
I created a pull request for this: #3475