Currently I write a Module for Icingaweb2 and this Module looks like this:
namespace Icinga\Module\CeGraph;
use Icinga\Module\Monitoring\Object\MonitoredObject;
use Icinga\Module\Monitoring\Object\Host;
use Icinga\Module\Monitoring\Object\Service;
use Icinga\Application\Hook\GrapherHook;
use Icinga\Web\Url;
class Grapher extends GrapherHook{
....
public function getPreviewHtml(MonitoredObject $object){
return "myHTMLCodeForGraph";
}
The Problem: This Module is only shown with Rolle Allow Anything *" Role.
With this role everything is working fine and the IFrame with the Graph is shown.
Have I missed something with a rights Mangement? and is there any Guide where i can fetch this knowlege?
Icingaweb2 is the latest version from Repo on a Ubuntu 18.04.2 with PHP7.2
Allow to access module cegraph (module/cegraph) should be available inside the Roles configuration pane automatically. Can you share the content of configuration.php if existing?
If you need more fine granular permissions or restrictions, such as limited access to graphs, you can provide them via configuration.php and check them in the particular functions then, e.g. when rendering a graph.
The Graphite module has a debug permission for example …
… which is checked here …
Another example for filters is provided within the business process module, and others around.
=== IndexController.php ===
<?php
use Icinga\Web\Controller;
class CeGraph_IndexController extends Controller {
public function indexAction() {
$this->setViewScript('index/iframe');
}
}
=== Grapher.php ===
<?php
namespace Icinga\Module\CeGraph;
use Icinga\Module\Monitoring\Object\MonitoredObject;
use Icinga\Module\Monitoring\Object\Host;
use Icinga\Module\Monitoring\Object\Service;
use Icinga\Application\Hook\GrapherHook;
use Icinga\Web\Url;
class Grapher extends GrapherHook{
protected function init(){
die("Initialized");
}
public function getPreviewHtml(MonitoredObject $object){
return "test";
}
public function has(MonitoredObject $object){
if ($object instanceof Host) {
$service = 'Hostcheck';
} elseif ($object instanceof Service) {
$service = $object->service_description;
} else {
return false;
}
$host = $object->host_name;
return true;
}
Can it be possible that there is any permission for the Hook that is missing?
Might it be the case that the role for which your graph is not shown has also access to another module which provides graphs?
Icinga Web 2 does only render a single graphing extension to the detail view. So if another module also provides one and is loaded first, its graph is displayed instead of yours.
If that’s the case, try the DetailViewExtensionHook which doesn’t have this limitation. Though, be aware that we didn’t put this limitation there without reason. Graphing extensions tend to increase the loading times, multiple ones even further.
I have only one module that implements the GrapherHook. And if I add “Allow everything (*)” the Module is executed. If I remove the right my Plugin disappears even the Allow access to the Module is set. Initialization isn’t even called.
Try to use the namespace Icinga\Module\Cegraph instead. Note the lowercase g. There’s some matching going on and I fear it can’t cope with mixed case very well.
Additionally, consider to use the namespace Icinga\Module\Cegraph\Controllers for file IndexController.php. This way you can remove the CeGraph_ prefix in the class name.
I’ve debuged a bit into the /usr/share/php/Icinga/Application/Hook.php and I can see, that the permission is only true if the module name is in lower case letters otherwise the
Module Directory have to be in lowercase. in Run.php the Directory have to start with an upper case letter and in the library directory it have to be with an upper case letter. Namespace an in Class has lowercase letter.
cat run.php
<?php
$this->provideHook('Grapher', 'Icinga\Module\Cegraph\Grapher');
cat library/Cegraph/Grapher.php
<?php
namespace Icinga\Module\cegraph;
use Icinga\Module\Monitoring\Object\MonitoredObject;
use Icinga\Module\Monitoring\Object\Host;
use Icinga\Module\Monitoring\Object\Service;
use Icinga\Application\Hook\GrapherHook;
use Icinga\Web\Url;
use Icinga\Authentication\Auth;
use Icinga\Security\SecurityException;
class Grapher extends GrapherHook{
....