Skip to content

Commit

Permalink
Simplified display of host names to fix the issue described in #120, …
Browse files Browse the repository at this point in the history
…fixed a bug regarding the configuration option. (Icinga2's API seems to have changed)
  • Loading branch information
mocdaniel committed Jul 1, 2021
1 parent 76ee239 commit 95c5b6d
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions lib/icinga2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ def countProblems(objects, states = nil)
end

if @showOnlyHardStateProblems
if (compStates.include?(d["state"]) && d["downtime_depth"] == 0 && d["acknowledgement"] == 0 && d['last_hard_state'] != 0.0)
if (compStates.include?(d["state"]) && d["downtime_depth"] == 0 && d["acknowledgement"] == 0 && d['state_type'] != 0.0)
problems = problems + 1
end
else
Expand Down Expand Up @@ -477,7 +477,7 @@ def countProblemsServices(objects, states = nil)
end

if @showOnlyHardStateProblems
if (compStates.include?(d["state"]) && d["downtime_depth"] == 0 && d["acknowledgement"] == 0 && d['last_hard_state'] != 0.0)
if (compStates.include?(d["state"]) && d["downtime_depth"] == 0 && d["acknowledgement"] == 0 && d['state_type'] != 0.0)
if (item["joins"]["host"]["state"] == 0.0)
problems = problems + 1
end
Expand Down Expand Up @@ -607,7 +607,7 @@ def getProblemServices(all_services_data, all_hosts_data, max_items = 30)
next
end

if @showOnlyHardStateProblems and (service["attrs"]["last_hard_state"] == 0.0)
if @showOnlyHardStateProblems and (service["attrs"]["state_type"] == 0.0)
next
end

Expand All @@ -624,16 +624,12 @@ def getProblemServices(all_services_data, all_hosts_data, max_items = 30)
next
end

if @showOnlyHardStateProblems and (host["attrs"]["last_hard_state"] == 0.0)
if @showOnlyHardStateProblems and (host["attrs"]["state_type"] == 0.0)
next
end

host_display_name = host["attrs"]["display_name"]
host_display_name_clean = host_display_name.split('(')[0].split('|')[0]
host_display_name_clean_split = host_display_name_clean.split(': ')
host_display_name_for_display = host_display_name_clean_split[0] + ' (' + host_display_name_clean_split[1] + ')'

service_problems_severity[host_display_name_for_display + " is DOWN"] = 2.0
service_problems_severity[host_display_name + " is DOWN"] = 2.0
end

service_problems.sort_by {|k, v| v}.reverse.each do |obj, severity|
Expand Down Expand Up @@ -814,8 +810,8 @@ def run
all_services_data = nil

if @showOnlyHardStateProblems
all_hosts_data = getHostObjects([ "name", "display_name", "state", "acknowledgement", "downtime_depth", "last_check", "last_hard_state" ], nil, nil)
all_services_data = getServiceObjects([ "name", "display_name", "host_name", "state", "acknowledgement", "downtime_depth", "last_check", "last_hard_state" ], nil, [ "host.name", "host.display_name", "host.state", "host.acknowledgement", "host.downtime_depth", "host.last_check" ])
all_hosts_data = getHostObjects([ "name", "display_name", "state", "acknowledgement", "downtime_depth", "last_check", "state_type" ], nil, nil)
all_services_data = getServiceObjects([ "name", "display_name", "host_name", "state", "acknowledgement", "downtime_depth", "last_check", "state_type" ], nil, [ "host.name", "host.display_name", "host.state", "host.acknowledgement", "host.downtime_depth", "host.last_check" ])
else
all_hosts_data = getHostObjects([ "name", "display_name", "state", "acknowledgement", "downtime_depth", "last_check" ], nil, nil)
all_services_data = getServiceObjects([ "name", "display_name", "host_name", "state", "acknowledgement", "downtime_depth", "last_check" ], nil, [ "host.name", "host.display_name", "host.state", "host.acknowledgement", "host.downtime_depth", "host.last_check" ])
Expand Down

0 comments on commit 95c5b6d

Please sign in to comment.