Open bensig opened 2 years ago
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\""
I have also tried this
serviceFilter = [ "service.state==state && match(pattern,service.name)", "filter_vars": { "state": 2, "pattern": "*API*" } ]
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?
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
Sorry for the long delay, would you mind sharing your edited jobs/icinga2.rb
and dashboards/icinga2.erb
?
Not a problem, thanks for the reply. Here are the files: jobs/icinga2.rb dashboards/icinga2.erb
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.
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:
For example, I tried to define:
serviceFilter = "groups.service == mainnet"
but it results in an error: