bin/check-http.rb in sensu-plugins-http-2.0.2 vs bin/check-http.rb in sensu-plugins-http-2.1.0
- old
+ new
@@ -40,10 +40,11 @@
#
require 'sensu-plugin/check/cli'
require 'net/http'
require 'net/https'
+require 'digest'
#
# Check HTTP
#
class CheckHttp < Sensu::Plugin::Check::CLI
@@ -137,10 +138,15 @@
option :negpattern,
short: '-n PAT',
long: '--negquery PAT',
description: 'Query for a specific pattern that must be absent'
+ option :sha256checksum,
+ short: '-S CHECKSUM',
+ long: '--checksum CHECKSUM',
+ description: 'SHA-256 checksum'
+
option :timeout,
short: '-t SECS',
long: '--timeout SECS',
proc: proc(&:to_i),
description: 'Set the timeout',
@@ -317,9 +323,15 @@
elsif config[:negpattern]
if res.body =~ /#{config[:negpattern]}/
critical "#{res.code}, found /#{config[:negpattern]}/ in #{size} bytes: #{res.body[0...200]}..."
else
ok "#{res.code}, did not find /#{config[:negpattern]}/ in #{size} bytes" + body
+ end
+ elsif config[:sha256checksum]
+ if Digest::SHA256.hexdigest(res.body).eql? config[:sha256checksum]
+ ok "#{res.code}, checksum match #{config[:sha256checksum]} in #{size} bytes" + body
+ else
+ critical "#{res.code}, checksum did not match #{config[:sha256checksum]} in #{size} bytes: #{res.body[0...200]}..."
end
else
ok("#{res.code}, #{size} bytes" + body) unless config[:response_code]
end
when /^3/