Customize Dashing - Show data only for specific Hostgroups/Servicegroups


We are starting to try a Dashing and try to show data only for some Hostgroups/Servicegroups.
Related to the iframe - we use a login with assigned 2 roles:
PROD: hostgroup_name=PROD&servicegroup_name=PROD
TEST: hostgroup_name=TEST&servicegroup_name=TEST

Now, we want to apply such filters to the Dashing.

In the article| Extend Icinga Dashing for your own needs mfriedrich refers to the lib/icinga2.rb file with the possibility to add filters:

all_hosts_data = getHostObjects([ "name", "state", "acknowledgement", "downtime_depth", "last_check" ], nil, nil)
all_services_data = getServiceObjects([ "name", "state", "acknowledgement", "downtime_depth", "last_check" ], nil, [ "", "host.state", "host.acknowledgement", "host.downtime_depth", "host.last_check" ])

Can someone provide an example of the filter and how we should apply it. For example:
all_hosts_data = getHostObjects([ "name", "state", "acknowledgement", "downtime_depth", "last_check" ], hostgroup_name=PROD&servicegroup_name=PROD, nil)

Should we just change nil to the filter from Icinga?

Thank you!

Yes. That’s how the function interface is built. You can of course create your own function and API calls when needed.

@mfriedrich, with filter or without - it shows me the same data

20 Hosts and 20 Services - anyway we have more Hosts and more Services.

Probably it may be related to my first issue [ Bug in Dashing 3.0]

Let’s try to solve it first.

@mfriedrich, the first one is solved. Now I’m trying to filter the data fro specific Hostgroup:

all_hosts_data = getHostObjects([ "name", "state", "acknowledgement", "downtime_depth", "last_check" ], "hostgroup_name=PROD", nil)

And get the following output:

scheduler caught exception:
404 Not Found
/usr/local/share/gems/gems/rest-client-2.1.0/lib/restclient/abstract_response.rb:249:in `exception_with_response'
/usr/local/share/gems/gems/rest-client-2.1.0/lib/restclient/abstract_response.rb:129:in `return!'
/usr/local/share/gems/gems/rest-client-2.1.0/lib/restclient/request.rb:836:in `process_result'
/usr/local/share/gems/gems/rest-client-2.1.0/lib/restclient/request.rb:743:in `block in transmit'
/usr/share/ruby/net/http.rb:852:in `start'
/usr/local/share/gems/gems/rest-client-2.1.0/lib/restclient/request.rb:727:in `transmit'
/usr/local/share/gems/gems/rest-client-2.1.0/lib/restclient/request.rb:163:in `execute'
/usr/local/share/gems/gems/rest-client-2.1.0/lib/restclient/request.rb:63:in `execute'
/usr/local/share/gems/gems/rest-client-2.1.0/lib/restclient/resource.rb:69:in `post'
/usr/share/dashing-icinga2/lib/icinga2.rb:253:in `getApiData'
/usr/share/dashing-icinga2/lib/icinga2.rb:326:in `getHostObjects'
/usr/share/dashing-icinga2/lib/icinga2.rb:750:in `run'
/usr/share/dashing-icinga2/jobs/icinga2.rb:27:in `block in <top (required)>'
/usr/local/share/gems/gems/rufus-scheduler-2.0.24/lib/rufus/sc/jobs.rb:230:in `call'
/usr/local/share/gems/gems/rufus-scheduler-2.0.24/lib/rufus/sc/jobs.rb:230:in `trigger_block'
/usr/local/share/gems/gems/rufus-scheduler-2.0.24/lib/rufus/sc/jobs.rb:204:in `block in trigger'
/usr/local/share/gems/gems/rufus-scheduler-2.0.24/lib/rufus/sc/scheduler.rb:430:in `call'
/usr/local/share/gems/gems/rufus-scheduler-2.0.24/lib/rufus/sc/scheduler.rb:430:in `block in trigger_job'

Can you please provide an example of the filter and how it should be used:


Or somehow else.

Arrays like the groups attribute for the host object need to use the in operator.

You can test such in the debug console.

$ icinga2 console
Icinga 2 (version: v2.11.0-430-gf62f2eb25)
Type $help to view available commands.
<1> => var hgs = [ "linux-servers", "db-servers" ]
<2> => "db-servers" in hgs

That being said, a simple filter could look like this, same as with apply rules: "linux-servers" in host.groups.


@mfriedrich, tried some variants and they doesn’t work:

      all_hosts_data = getHostObjects([ "name", "state", "acknowledgement", "downtime_depth", "last_check"], "PROD" in host.groups, nil)
[root@dashboard dashing-icinga2]# dashing start -p 8005
/usr/local/share/gems/gems/backports-3.15.0/lib/backports/std_lib.rb:9:in `require': /usr/share/dashing-icinga2/lib/icinga2.rb:750: syntax error, unexpected keyword_in, expecting ')' (SyntaxError)
...epth", "last_check"], "PROD" in host.groups, nil)
...                               ^
/usr/share/dashing-icinga2/lib/icinga2.rb:750: Can't assign to nil
/usr/share/dashing-icinga2/lib/icinga2.rb:750: syntax error, unexpected ')', expecting '='
	from /usr/local/share/gems/gems/backports-3.15.0/lib/backports/std_lib.rb:9:in `require_with_backports'
	from /usr/local/share/gems/gems/dashing-1.3.7/lib/dashing/app.rb:171:in `block in require_glob'
	from /usr/local/share/gems/gems/dashing-1.3.7/lib/dashing/app.rb:170:in `each'
	from /usr/local/share/gems/gems/dashing-1.3.7/lib/dashing/app.rb:170:in `require_glob'
	from /usr/local/share/gems/gems/dashing-1.3.7/lib/dashing/app.rb:180:in `<top (required)>'
	from /usr/local/share/gems/gems/dashing-1.3.7/lib/dashing.rb:3:in `require'
	from /usr/local/share/gems/gems/dashing-1.3.7/lib/dashing.rb:3:in `<top (required)>'
	from `require'
	from `block in <main>'
	from /usr/local/share/gems/gems/rack-1.5.5/lib/rack/builder.rb:55:in `instance_eval'
	from /usr/local/share/gems/gems/rack-1.5.5/lib/rack/builder.rb:55:in `initialize'
	from `new'
	from `<main>'
	from /usr/local/share/gems/gems/thin-1.6.4/lib/rack/adapter/loader.rb:33:in `eval'
	from /usr/local/share/gems/gems/thin-1.6.4/lib/rack/adapter/loader.rb:33:in `load'
	from /usr/local/share/gems/gems/thin-1.6.4/lib/thin/controllers/controller.rb:182:in `load_rackup_config'
	from /usr/local/share/gems/gems/thin-1.6.4/lib/thin/controllers/controller.rb:72:in `start'
	from /usr/local/share/gems/gems/thin-1.6.4/lib/thin/runner.rb:200:in `run_command'
	from /usr/local/share/gems/gems/thin-1.6.4/lib/thin/runner.rb:156:in `run!'
	from /usr/local/share/gems/gems/thin-1.6.4/bin/thin:6:in `<top (required)>'
	from /usr/local/bin/thin:23:in `load'
	from /usr/local/bin/thin:23:in `<main>'

In the Icinga itself such a condition working fine:

object HostGroup "Test" {
    display_name = "Test"
    assign where "PROD" in host.groups

That’s not valid Ruby code, the element needs quotes being a string argument. That’s what the Ruby parser tries to tell you.

      all_hosts_data = getHostObjects([ "name", "state", "acknowledgement", "downtime_depth", "last_check"], "PROD" in host.groups, nil)

try something like this instead:

      all_hosts_data = getHostObjects([ "name", "state", "acknowledgement", "downtime_depth", "last_check"], "\"PROD\" in host.groups", nil)

@mfriedrich, thanks. At least it started to collect the data. My filter for Hosts:

"\"PROD\" in host.groups"

Entire line is the following:

      all_hosts_data = getHostObjects([ "name", "state", "acknowledgement", "downtime_depth", "last_check"], "\"PROD\" in host.groups", nil)

But anyway, in the Hosts widget I see a total number of Hosts in Icinga - not a number of the Hosts in the PROD host.groups.

Should it show only host specified by filter?

I don’t have the code in my head, but while looking at it, I’d say it takes the global numbers from the stats endpoint.

In such a way, in our case, filter doesn’t make sense. Where it is applied?

It takes the global stats from the /v1/status/CIB url endpoint, that’s what is referred to as cib_data. If you want to apply filtered counts to that send_event call, you’ll need to collect and expose such. It isn’t easy but doable with some programming effort. I can only be guiding here, I don’t have time atm to look again into the code and fire up a test setup.