Skip to content

Commit 4f18dc5

Browse files
committed
Add cookie argument to check_haproxy. Fixes #15
1 parent 6ac61ef commit 4f18dc5

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

Diff for: check_haproxy.rb

+7-2
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@
6060
options.http_error_critical = true
6161
end
6262

63+
opts.on('--cookie [COOKIE]', 'Login/Session cookie') do |v|
64+
options.cookie = v
65+
end
66+
6367
opts.on( '-h', '--help', 'Display this screen' ) do
6468
puts opts
6569
exit 3
@@ -96,14 +100,15 @@ def open_options(options)
96100
open_opts = {
97101
:http_basic_authentication => [options.user, options.password]
98102
}
103+
open_opts['Cookie'] = options.cookie if options.cookie
99104

100105
# allows https with invalid certificate on ruby 1.9
101106
# src: http://snippets.aktagon.com/snippets/370-hack-for-using-openuri-with-ssl
102107
if options.insecure_ssl && RUBY_VERSION =~ /1\.9/
103108
open_opts[:ssl_verify_mode] = OpenSSL::SSL::VERIFY_NONE
104109
end
105110

106-
open_opts
111+
return open_opts
107112
end
108113

109114
def haproxy_response(options)
@@ -119,7 +124,7 @@ def haproxy_response(options)
119124
end
120125

121126
begin
122-
open(options.url, open_options(options))
127+
return URI.open(options.url, open_options(options))
123128
rescue OpenURI::HTTPError => e
124129
puts "ERROR: #{e.message}"
125130
options.http_error_critical ? exit(CRITICAL) : exit(UNKNOWN)

Diff for: test/test_check_haproxy.sh

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#!/bin/bash
22

3+
set -e
4+
35
echo -n "testing nothing smokes..."
46
for f in test/haproxy/*; do
57
./check_haproxy.rb -u "$f" |head -n1
@@ -23,3 +25,5 @@ echo "OK"
2325
echo -n "testing crit limit..."
2426
./check_haproxy.rb -u "test/haproxy/fedoraproject_org.csv;" -w 1 -c2 -p fedmsg-raw-zmq-outbound-backend |grep 'CRIT.*too many sessions' > /dev/null
2527
echo "OK"
28+
29+
echo "SUCCESS! ALL TESTS PASSED"

0 commit comments

Comments
 (0)