Skip to content

Commit

Permalink
Fix problem list ordering: Crit -> Warn -> Unknown
Browse files Browse the repository at this point in the history
Previous this was just "random" by the string comparison
with Crit > Unknown > Warn, which isn't what we expect.

Great help: https://stackoverflow.com/questions/40121932/ruby-sort-array-of-hashes-values-string-based-on-array-order

refs #41
  • Loading branch information
Michael Friedrich committed Jan 22, 2018
1 parent 2ae0f15 commit 77720b0
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions jobs/icinga2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,19 @@
severity_stats.push({
"label" => icinga.formatService(name),
"color" => icinga.stateToColor(state.to_int, false),
"state" => icinga.stateToString(state)
"state" => state.to_int
})
end
severity_stats = severity_stats.sort_by{|stat| stat["state"]}
puts "Severity: " + severity_stats.to_s

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

puts "Severity: " + result.to_s

send_event('icinga-severity', {
items: severity_stats,
items: result,
color: 'blue' })

# down, critical, warning, unknown
Expand Down

0 comments on commit 77720b0

Please sign in to comment.