bin/check-aggregate.rb in sensu-plugins-sensu-3.0.0 vs bin/check-aggregate.rb in sensu-plugins-sensu-4.0.0
- old
+ new
@@ -1,6 +1,8 @@
#!/usr/bin/env ruby
+# frozen_string_literal: false
+
#
# Check Aggregate
# ===
#
# Authors
@@ -169,11 +171,11 @@
def honor_stash(aggregate)
aggregate[:results].delete_if do |entry|
begin
api_request("/stashes/silence/#{entry[:client]}/#{config[:check]}")
- if entry[:status] == 0
+ if entry[:status].zero?
aggregate[:ok] = aggregate[:ok] - 1
elsif entry[:status] == 1
aggregate[:warning] = aggregate[:warning] - 1
elsif entry[:status] == 2
aggregate[:critical] = aggregate[:critical] - 1
@@ -190,11 +192,11 @@
end
def collect_output(aggregate)
output = ''
aggregate[:results].each do |entry|
- output << entry[:output] + "\n" unless entry[:status] == 0
+ output << entry[:output] + "\n" unless entry[:status].zero?
end
aggregate[:outputs] = [output]
end
def acquire_aggregate
@@ -206,11 +208,11 @@
end
end
def named_aggregate_results
results = api_request("/aggregates/#{config[:check]}?max_age=#{config[:age]}")[:results]
- warning "No aggregates found in last #{config[:age]} seconds" if %w(ok warning critical unknown).all? { |x| results[x.to_sym] == 0 }
+ warning "No aggregates found in last #{config[:age]} seconds" if %w[ok warning critical unknown].all? { |x| results[x.to_sym].zero? }
results
end
def aggregate_results
uri = "/aggregates/#{config[:check]}"
@@ -261,10 +263,10 @@
mappings = {}
message = config[:message] || 'One of these is not like the others!'
if config[:debug]
message += "\n" + aggregate.to_s
end
- aggregate[:outputs].each do |output, _count|
+ aggregate[:outputs].each_key do |output|
matched = regex.match(output.to_s)
unless matched.nil?
key = matched[1]
value = matched[2..-1]
if mappings.key?(key)