bin/check-aggregate.rb in sensu-plugins-sensu-2.3.1 vs bin/check-aggregate.rb in sensu-plugins-sensu-2.4.0
- old
+ new
@@ -128,10 +128,17 @@
long: '--ignore-severity',
description: 'Ignore severities, all non-ok will count for critical, critical_count, warning and warning_count option',
boolean: true,
default: false
+ option :debug,
+ short: '-D',
+ long: '--debug',
+ description: 'Display results hash at end of output message',
+ boolean: true,
+ default: false
+
option :stale_percentage,
long: '--stale-percentage PERCENT',
description: 'PERCENT stale before warning',
proc: proc(&:to_i)
@@ -226,11 +233,13 @@
def compare_thresholds(aggregate)
message = config[:message] || 'Number of non-zero results exceeds threshold'
message += ' (%d%% %s)'
message += "\n" + aggregate[:outputs] if aggregate[:outputs]
-
+ if config[:debug]
+ message += "\n" + aggregate.to_s
+ end
if config[:ignore_severity]
percent_non_zero = (100 - (aggregate[:ok].to_f / aggregate[:total].to_f) * 100).to_i
if config[:critical] && percent_non_zero >= config[:critical]
critical format(message, percent_non_zero, 'non-zero')
elsif config[:warning] && percent_non_zero >= config[:warning]
@@ -249,10 +258,13 @@
def compare_pattern(aggregate)
regex = Regexp.new(config[:pattern])
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|
matched = regex.match(output.to_s)
unless matched.nil?
key = matched[1]
value = matched[2..-1]
@@ -268,11 +280,13 @@
def compare_thresholds_count(aggregate)
message = config[:message] || 'Number of nodes down exceeds threshold'
message += " (%s out of #{aggregate[:total]} nodes reporting %s)"
message += "\n" + aggregate[:outputs] if aggregate[:outputs]
-
+ if config[:debug]
+ message += "\n" + aggregate.to_s
+ end
if config[:ignore_severity]
number_of_nodes_reporting_down = aggregate[:total].to_i - aggregate[:ok].to_i
if config[:critical_count] && number_of_nodes_reporting_down >= config[:critical_count]
critical format(message, number_of_nodes_reporting_down, 'not ok')
elsif config[:warning_count] && number_of_nodes_reporting_down >= config[:warning_count]
@@ -313,15 +327,18 @@
pattern = config[:summarize] && config[:pattern]
critical 'Misconfiguration: critical || warning || (summarize && pattern) must be set' unless threshold || pattern || threshold_count
aggregate = acquire_aggregate
aggregate = honor_stash(aggregate) if config[:honor_stash]
- puts aggregate
aggregate = collect_output(aggregate) if config[:collect_output]
compare_thresholds(aggregate) if threshold
compare_pattern(aggregate) if pattern
compare_thresholds_count(aggregate) if threshold_count
compare_stale(aggregate) if config[:stale_percentage] || config[:stale_count]
- ok 'Aggregate looks GOOD'
+ if config[:debug]
+ ok "Aggregate looks GOOD\n" + aggregate.to_s
+ else
+ ok 'Aggregate looks Good'
+ end
end
end