Skip to content
This repository has been archived by the owner on Mar 29, 2021. It is now read-only.

Commit

Permalink
Add valid-http-codes option
Browse files Browse the repository at this point in the history
Add a new valid-http-codes option. By default only 2xx codes are OK now.
Be warned as 401 codes were allowed on previous versions.
  • Loading branch information
toubib committed Dec 10, 2015
1 parent 07e9b3e commit dd6b5a1
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
3 changes: 3 additions & 0 deletions Gemfile.lock
Expand Up @@ -10,3 +10,6 @@ PLATFORMS
DEPENDENCIES
hpricot
optiflag

BUNDLED WITH
1.10.3
17 changes: 14 additions & 3 deletions check_webpage.rb
Expand Up @@ -145,6 +145,11 @@ module Example extend OptiFlagSet
description "--graphite-prefix, prefix the graphite path (default to 'webpage')"
end

optional_flag "vhc" do
long_form "valid-http-codes"
description "--valid-http-codes XXX,XXX (ex 401,404)"
end

and_process!
end

Expand Down Expand Up @@ -195,6 +200,12 @@ module Example extend OptiFlagSet
httpHeaders['Authorization'] = 'Basic '+Base64.encode64(ARGV.flags.a)
end

if ARGV.flags.vhc?
validHttpCodes = ARGV.flags.vhc.split(',')
else
validHttpCodes = []
end

if ARGV.flags.p?
postData = ARGV.flags.p
else
Expand Down Expand Up @@ -526,11 +537,11 @@ def getInnerLinks (mainUrl, data, httpHeaders, reports, proxy)
## check main url return code
###############################################################
if res.code =~ /[^2]../
if res.code == "401" && ARGV.flags.a.nil? # server respond but authentication required
text = "OK: server respond but rcode is "
if validHttpCodes.include? res.code
text = "OK: server respond with http code "
result = 0
else
text = "Critical: main page rcode is "
text = "Critical: main page http code is "
result = 2
end

Expand Down
4 changes: 3 additions & 1 deletion test/test.rb
Expand Up @@ -58,7 +58,9 @@ def test_timeout
end

def test_auth_err
assert_equal(true, system( '../check_webpage.rb -u '+WEB_SERVER_URL+'/401' ) )
assert_equal(true, system( '../check_webpage.rb -u '+WEB_SERVER_URL+'/401 -vhc 401') )
assert_equal(true, system( '../check_webpage.rb -u '+WEB_SERVER_URL+'/401 -vhc 404,401') )
assert_equal(false, system( '../check_webpage.rb -u '+WEB_SERVER_URL+'/401' ) )
assert_equal(false, system( '../check_webpage.rb -a test -u '+WEB_SERVER_URL+'/401' ) )
end
end

0 comments on commit dd6b5a1

Please sign in to comment.