bin/check-snmp.rb in sensu-plugins-snmp-0.1.0 vs bin/check-snmp.rb in sensu-plugins-snmp-0.2.0
- old
+ new
@@ -58,21 +58,39 @@
option :comparison,
short: '-o comparison operator',
description: 'Operator used to compare data with warning/critial values. Can be set to "le" (<=), "ge" (>=).',
default: 'ge'
+ option :convert_timeticks,
+ short: '-T',
+ long: '--convert-timeticks',
+ description: 'Convert SNMP::TimeTicks to Integer for comparisons',
+ boolean: true,
+ default: false
+
option :timeout,
short: '-t timeout (seconds)',
default: '1'
+ option :debug,
+ short: '-D',
+ long: '--debug',
+ description: 'Enable debugging to assist with inspecting OID values / data.',
+ boolean: true,
+ default: false
+
def run
begin
- manager = SNMP::Manager.new(host: "#{config[:host]}",
- community: "#{config[:community]}",
+ manager = SNMP::Manager.new(host: config[:host].to_s,
+ community: config[:community].to_s,
version: config[:snmp_version].to_sym,
timeout: config[:timeout].to_i)
- response = manager.get(["#{config[:objectid]}"])
+ response = manager.get([config[:objectid].to_s])
+ if config[:debug]
+ puts 'DEBUG OUTPUT:'
+ response.each_varbind { |vb| puts vb.inspect }
+ end
rescue SNMP::RequestTimeout
unknown "#{config[:host]} not responding"
rescue => e
unknown "An unknown error occured: #{e.inspect}"
end
@@ -85,13 +103,19 @@
ok
else
critical "Value: #{vb.value} failed to match Pattern: #{config[:match]}"
end
else
- critical 'Critical state detected' if "#{vb.value}".to_i.send(symbol, "#{config[:critical]}".to_i)
+ snmp_value = if config[:convert_timeticks]
+ vb.value.is_a?(SNMP::TimeTicks) ? vb.value.to_i : vb.value
+ else
+ vb.value
+ end
+
+ critical 'Critical state detected' if snmp_value.to_s.to_i.send(symbol, config[:critical].to_s.to_i)
# #YELLOW
- warning 'Warning state detected' if ("#{vb.value}".to_i.send(symbol, "#{config[:warning]}".to_i)) && !("#{vb.value}".to_i.send(symbol, "#{config[:critical]}".to_i)) # rubocop:disable LineLength
- unless "#{vb.value}".to_i.send(symbol, "#{config[:warning]}".to_i)
+ warning 'Warning state detected' if snmp_value.to_s.to_i.send(symbol, config[:warning].to_s.to_i) && !snmp_value.to_s.to_i.send(symbol, config[:critical].to_s.to_i) # rubocop:disable LineLength
+ unless snmp_value.to_s.to_i.send(symbol, config[:warning].to_s.to_i)
ok 'All is well!'
end
end
end
manager.close