Custom icingaweb2 module div refresh autoreload issue

I’m working on a custom icingaweb2 module that will pull information about the host and service in realtime from our management database system using custom php.

Since I don’t want this to block the loading of the icingaweb2 page I’m doing this via a div that I’m using javascript to populate.
However, the default for the div icinga-module is to run on a refresh (it appears to be 10 seconds due to the global ‘enable auto refresh’ set to yes and default, we don’t want to change that!) and so the content keeps getting re-polled (i/o heavy) and takes time to keep repopulating.

What I need to do is set the module data, which is in Host/Service detail view and extended using the “DetailviewExtensionhook” method to be non autorefreshing.
I’ve tried every way I can to modify the div, container, content box, etc and cannot stop the refresh.
What I’ve also noticed is by default when I extend the “getHtmlForObject” by default it’s wrapped around a div that I think has the autorefresh being triggered on it, so if I can either avoid that, or force a non refresh that would be ideal.

I’m populating the page data like this (ProvidedHook/Monitoring/DetailviewExtension.php):

namespace Icinga\Module\MyApp\ProvidedHook\Monitoring;

use Icinga\Module\Monitoring\Hook\DetailviewExtensionHook;
use Icinga\Module\Monitoring\Object\MonitoredObject;
use Icinga\Module\Monitoring\Object\Host;
use Icinga\Module\Monitoring\Object\Service;

use Icinga\Module\Myapp\Myapp;

class DetailviewExtension extends DetailviewExtensionHook {

        public function getHtmlForObject(MonitoredObject $object) {
                $return_data="";
                $return_data.="<div class=\"content icinga-module module-myapp\" data-icinga-refresh=\"0\">";
                $return_data.="<span class=\"container data-no-icinga-ajax\" data-icinga-refresh=\"0\" id=\"icinga-module-myapp-dataloader\">Loading...</span>";
                $return_data.="<BR><BR>HELLO";
                $return_data.="</div>";
                return $return_data;
        }
}

This keeps reloading unfortunately due to what I think is the public/js/icinga/loader.js and function “autorefresh” but I cannot see how I can stop this.
In the above code, there is another DIV wrapped around my code automatically by the framework which creates another div like this:

<div class="icinga-module module-myapp" data-icinga-module="myapp">

Which I think is the one that’s being targetted and the one that I need to create the relevant data tags to stop refresh (? is that right?)

Any help please!

I think the grafana module has some magic of reattaching content:

and as a workaround you could iframe “/icingaweb2/yourcontroller/youraction?host=xx&service=yyy”
which loads the data from your cmdb.
an iframe would also prevent the loading time blockage

or you create some cache like writing the polled data to a file (json) or a local database. which can be read instantly after initial load.
so load it, write it to disk, use loaded data, if file age > some threshold => refresh cache

or if you use icinga director you could create a sync job that fetches these data and write it to the custom vars. this can be rendered in a custom detailedview too.

2 Likes

Hey there,
Thank you! Yes I’d seen the grafana method, I’ve been trying to avoid iframe (Old habits as iframes have always been a no-no in web content) so been trying to work around it using div’s.
So far everything fails so you might be right and going down the iframe route.

(I did think of data/store/fetch but this needs to be in realtime so can’t use stored/cached data)

Is your javascript in the public/js folder? Because if it is inline in your php code it will break as soon as you enable the IcingaWeb2 CSP policy.

Yep, js is in ./public/js/module.js
So should be ok, I’ve tried to use module framework and used others as examples to try to use correct structure!

1 Like

I am personally not a fan of what the grafana module does, although I’m personally responsible, but it does that for a good reason: Not to disable autorefresh, but to avoid flickering graphs.

Without JS you cannot disable autorefresh, as the entire container gets refreshed, i.e. the entire detail view, and this happens to include your div/iframe.

If you’d extend Icinga DB Web, I’d advise you to provide a custom detail tab instead. That’s not integrated in the detail, but then has the full height of content available and: no autorefresh.

2 Likes