My goal is to show ALL critical services in Dashing where the corresponding host is NOT currently in a downtime-state and the service is NOT acknowledged.
I verified that I am querying the right attributes of my host objects, and the code should work as well, thing is, it doesn’t.
I do not know my way around Ruby all too well, so a proofreading of the lines in question would be very nice!
services = icinga.getServiceObjects(["__name", "state", "acknowledgement", "host"], nil, ["host.downtime_depth"])
service_problems = 0
services.each do |service|
if(service["attrs"]["state"] > 0 && service["attrs"]["acknowledgement"] == 0 && service["joins"]["host.downtime_depth"] == 0.0)
service_problems += 1
end
end
‘service_problems’ gets pushed to a meter-widget within my dashboard, this is the simplest example using this filtering query, even though I intend to use it in many places throughout my code.
Shouldn’t this do the trick? Anything I’m missing?
This code snippet is implemented within icinga2.rb inside the ./jobs folder.
The send_event function is called right after this snippet in the following way:
Where service_count is the preprocessed total amount of services queried.
The error is, that it does not filter properly. With this filter applied, I am seemingly not getting ANY critical services returned anymore, not even the ones where the respective hosts are not in a downtime at the moment.
If I delete
&& service[“joins”][“downtime_depth”]
from the code, the filter works fine again and displays the correct number of non-“green” services which matches the amount of non-green services shown in icingaweb.
Thank you very much, it turned out that the value I was looking for was on a lower level of the nested json-response than I thought: service[“joins”][“host”][“downtime_depth”] contains the value.