Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Guidance modifying dashlet #127

Open
bensig opened this issue Aug 4, 2022 · 7 comments
Open

Guidance modifying dashlet #127

bensig opened this issue Aug 4, 2022 · 7 comments

Comments

@bensig
Copy link

bensig commented Aug 4, 2022

I could use a little guidance here. I want to create a public dashboard to show the status of various APIs that we have.

I am looking to modify the "Service Problems" to just show a list of hosts instead. I have a service group defined, but I cannot get the filter to work in the test/icinga.rb - and I'm not sure how I could adapt your "Service Problems" to be a list of "Main Services".

This works using the API to get the list that I want to use:

curl -k -s -S -i -u 'root:icinga' -H 'Accept: application/json' \
 -H 'X-HTTP-Method-Override: GET' -X POST \
 'https://localhost:5665/v1/objects/services' \
 -d '{ "filter": "group in service.groups", "filter_vars": { "group": "main" }, "pretty": true }'

For example, I tried to define:

serviceFilter = "groups.service == mainnet"

but it results in an error:

Traceback (most recent call last):
	11: from ./test/icinga2.rb:44:in `<main>'
	10: from /home/ubuntu/src/dashing-icinga2/lib/icinga2.rb:362:in `getServiceObjects'
	 9: from /home/ubuntu/src/dashing-icinga2/lib/icinga2.rb:256:in `getApiData'
	 8: from /var/lib/gems/2.7.0/gems/rest-client-2.1.0/lib/restclient/resource.rb:69:in `post'
	 7: from /var/lib/gems/2.7.0/gems/rest-client-2.1.0/lib/restclient/request.rb:63:in `execute'
	 6: from /var/lib/gems/2.7.0/gems/rest-client-2.1.0/lib/restclient/request.rb:163:in `execute'
	 5: from /var/lib/gems/2.7.0/gems/rest-client-2.1.0/lib/restclient/request.rb:727:in `transmit'
	 4: from /usr/lib/ruby/2.7.0/net/http.rb:933:in `start'
	 3: from /var/lib/gems/2.7.0/gems/rest-client-2.1.0/lib/restclient/request.rb:743:in `block in transmit'
	 2: from /var/lib/gems/2.7.0/gems/rest-client-2.1.0/lib/restclient/request.rb:836:in `process_result'
	 1: from /var/lib/gems/2.7.0/gems/rest-client-2.1.0/lib/restclient/abstract_response.rb:129:in `return!'
/var/lib/gems/2.7.0/gems/rest-client-2.1.0/lib/restclient/abstract_response.rb:249:in `exception_with_response': 404 Not Found (RestClient::NotFound)
@bensig
Copy link
Author

bensig commented Aug 4, 2022

I have also tried to use a host group, but it returns no result even though it works on the curl

puts "Host listing: " + host_stats.to_s

hostFilter = "host.groups==\"API\""

@bensig
Copy link
Author

bensig commented Aug 4, 2022

I have also tried this

serviceFilter = [ "service.state==state && match(pattern,service.name)", "filter_vars": { "state": 2, "pattern": "*API*" } ]

@mocdaniel
Copy link
Owner

mocdaniel commented Aug 6, 2022

Hey Ben,

from what I gathered, you want a widget showing a list of all host problems, is that right? You could do something like this:

./dashboards/icinga2.erb

[...]
<li data-row="3" data-col="1" data-sizex="2" data-sizey="2">
      <div data-id="icinga-host-severity" data-view="List" data-unordered="true" data-title="Problems"></div>
    </li>

This goes within the huge SCHEDULER loop, basically wherever you want:

./jobs/icinga2.rb

[...]
# host problems
  host_severity_stats = []
  icinga.getHostObjects().each do |host|
    if host['attrs']['groups'].include? 'dummy-hosts'
      name = host['attrs']['__name']
      state = host['attrs']['state']
      host_severity_stats.push({
        "label" => name,
        "color" => icinga.stateToColor(state.to_int, false),
        "state" => state.to_int
      })
    end
  end

  order = [ 2,1,3 ]
  host_result = host_severity_stats.sort do |a, b|
    order.index(a['state'].to_int) <=> order.index(b['state'].to_int)
  end

  send_event('icinga-host-severity', {
    items: host_result,
    color: 'blue'
  })
[...]

This example will display all non-OK host states of hosts within the group dummy-hosts.

Does this help?

@bensig
Copy link
Author

bensig commented Aug 9, 2022

Thank you for the response. Very helpful to see how you did this... However, I have tried using this to substitute my own HostGroup instead of 'dummy-hosts' and it does not seem to limit to just that group.

It's still displaying service issues from all hosts. The actual hostgroup is defined in groups.conf and it loads correctly in Icinga2web with this filter:

/monitoring/list/hosts?hostgroup_name=mainnet-hosts&sort=host_severity&limit=50

@mocdaniel
Copy link
Owner

Sorry for the long delay, would you mind sharing your edited jobs/icinga2.rb and dashboards/icinga2.erb?

@bensig
Copy link
Author

bensig commented Sep 7, 2022

Not a problem, thanks for the reply. Here are the files:
jobs/icinga2.rb
dashboards/icinga2.erb

@mocdaniel
Copy link
Owner

mocdaniel commented Sep 7, 2022

Seems like you never actually use the data you prepare in your jobs/icinga2.rb - for this you'd need to rename the data-id property of one of the widgets of type List to point to icinga-host-severity (as you named the data being pushed by the backend job like this) in your dashboards/icinga2.erb.

You might have to rearrange/uncomment some of the widgets, too. Let me know if I can be of further help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants