Skip to content

Commit 9c0bf4b

Browse files
author
Pavel Pulec
committed
add --http-error-critical
Throw critical when connection to HAProxy is refused or returns error code Signed-off-by: Pavel Pulec <[email protected]>
1 parent 1e3b0fa commit 9c0bf4b

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

Diff for: check_haproxy.rb

+7-2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
@errors = []
1818
@perfdata = []
1919
exit_code = OK
20+
http_error_critical = false
2021

2122
options = OpenStruct.new
2223
options.proxies = []
@@ -67,6 +68,10 @@
6768
OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE
6869
end
6970

71+
opts.on( '--http-error-critical', 'Throw critical when connection to HAProxy is refused or returns error code' ) do
72+
http_error_critical = true
73+
end
74+
7075
opts.on( '-h', '--help', 'Display this screen' ) do
7176
puts opts
7277
exit 3
@@ -106,10 +111,10 @@
106111
f = open(options.url, :http_basic_authentication => [options.user, options.password])
107112
rescue OpenURI::HTTPError => e
108113
puts "ERROR: #{e.message}"
109-
exit CRITICAL
114+
http_error_critical ? exit CRITICAL : exit UNKNOWN
110115
rescue Errno::ECONNREFUSED => e
111116
puts "ERROR: #{e.message}"
112-
exit CRITICAL
117+
http_error_critical ? exit CRITICAL : exit UNKNOWN
113118
rescue Exception => e
114119
if e.message =~ /redirection forbidden/
115120
options.url = e.message.gsub(/.*-> (.*)/, '\1') # extract redirect URL

0 commit comments

Comments
 (0)