Skip to content

Commit

Permalink
Merge pull request #73 from Dambakk/suppress-flicker
Browse files Browse the repository at this point in the history
Add option to show only hard state problems
  • Loading branch information
dnsmichi committed Oct 8, 2019
2 parents 1967027 + e423cc3 commit ed4bd04
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 6 deletions.
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -208,10 +208,14 @@ vim config/icinga2.local.json
},
"icingaweb2": {
"url": "http://localhost/icingaweb2"
}
},
"show_only_hard_state_problems": false
}
```

The `show_only_hard_state_problems` option ignores NOT-OK states until they
reach a hard NOT-OK state (off by default).

If you prefer to use client certificates, set the `pki_path` attribute. The Icinga 2
job expects the certificate file names based on the local FQDN e.g. `pki/icinga2-master1.localdomain.crt`.
You can override this behaviour by specifying the `node_name` configuration option
Expand All @@ -230,6 +234,9 @@ explicitly.
},
"icingaweb2": {
"url": "http://localhost/icingaweb2"
},
"dashboard": {
"show_only_hard_state_problems": false
}
}
```
Expand All @@ -252,6 +259,7 @@ ICINGA2\_API\_PASSWORD | **Optional.** Required for basic auth as password.
ICINGA2\_API\_CERT\_PATH | **Optional.** Client certificate path.
ICINGA2\_API\_NODENAME | **Optional.** If client certificates do not match the host name, override it.
ICINGAWEB2\_URL | **Optional.** Set the Icinga Web 2 Url. Defaults to `http://localhost/icingaweb2`.
DASHBOARD_SHOW_ONLY_HARD_STATE_PROBLEMS | **Optional.** Set `show_only_hard_state_problems` configuration option, toggle with `0|1`.

> **Note**
>
Expand Down
3 changes: 3 additions & 0 deletions config/icinga2.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,8 @@
},
"icingaweb2": {
"url": "http://localhost/icingaweb2"
},
"dashboard": {
"show_only_hard_state_problems": false
}
}
34 changes: 29 additions & 5 deletions lib/icinga2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ def getConfEnv()
# external attribute
@icingaweb2_url = ENV['ICINGAWEB2_URL']

@showOnlyHardStateProblems = ENV['DASHBOARD_SHOW_ONLY_HARD_STATE_PROBLEMS']

# check for the least required variables, the rest is read later on
if [@host, @port].all? {|value| value.nil? or value == ""}
raise ArgumentError.new('Required environment variables not found!')
Expand Down Expand Up @@ -154,6 +156,7 @@ def getConfFile(configFile)
@password = @config["icinga2"]["api"]["password"]
@pkiPath = @config["icinga2"]["api"]["pki_path"]
@nodeName = @config['icinga2']['api']['node_name']
@showOnlyHardStateProblems = @config['dashboard']['show_only_hard_state_problems']
end
end

Expand All @@ -170,6 +173,7 @@ def getConfFile(configFile)
@password = "icinga2ondashingr0xx"
@pkiPath = "pki/"
@nodeName = nil
@showOnlyHardStateProblems = false

# external attribute
@icingaweb2_url = 'http://localhost/icingaweb2'
Expand Down Expand Up @@ -418,8 +422,14 @@ def countProblems(objects, states = nil)
next
end

if (compStates.include?(d["state"]) && d["downtime_depth"] == 0 && d["acknowledgement"] == 0)
problems = problems + 1
if @showOnlyHardStateProblems
if (compStates.include?(d["state"]) && d["downtime_depth"] == 0 && d["acknowledgement"] == 0 && d['last_hard_state'] != 0.0)
problems = problems + 1
end
else
if (compStates.include?(d["state"]) && d["downtime_depth"] == 0 && d["acknowledgement"] == 0)
problems = problems + 1
end
end
end
end
Expand Down Expand Up @@ -526,7 +536,13 @@ def getProblemServices(all_services_data, max_items = 20)

all_services_data.each do |service|
#puts "Severity for " + service["name"] + ": " + getServiceSeverity(service).to_s
if (service["attrs"]["state"] == 0)
if (service["attrs"]["state"] == 0) or
(service["attrs"]["downtime_depth"] > 0) or
(service["attrs"]["acknowledgement"] > 0)
next
end

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

Expand Down Expand Up @@ -698,8 +714,16 @@ def run

## Objects data
# fetch the minimal attributes for problem calculation
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.name", "host.state", "host.acknowledgement", "host.downtime_depth", "host.last_check" ])
all_hosts_data = nil
all_services_data = nil

if @showOnlyHardStateProblems
all_hosts_data = getHostObjects([ "name", "state", "acknowledgement", "downtime_depth", "last_check", "last_hard_state" ], nil, nil)
all_services_data = getServiceObjects([ "name", "state", "acknowledgement", "downtime_depth", "last_check", "last_hard_state" ], nil, [ "host.name", "host.state", "host.acknowledgement", "host.downtime_depth", "host.last_check" ])
else
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.name", "host.state", "host.acknowledgement", "host.downtime_depth", "host.last_check" ])
end

unless(all_hosts_data.nil?)
@host_count_all = all_hosts_data.size
Expand Down

0 comments on commit ed4bd04

Please sign in to comment.