hq-check-site 0.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/bin/hq-check-site +15 -0
- data/features/check-site.feature +178 -0
- data/features/support/env.rb +105 -0
- data/features/support/steps.rb +121 -0
- data/lib/hq/check-site/script.rb +269 -0
- metadata +182 -0
data/bin/hq-check-site
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
script_path = $0
|
4
|
+
script_path = File.readlink(script_path) while File.symlink?(script_path)
|
5
|
+
CONFIG = File.expand_path("#{File.dirname(script_path)}/../..")
|
6
|
+
$LOAD_PATH.unshift "#{CONFIG}/alchemy-hq/ruby"
|
7
|
+
|
8
|
+
require "hq/systools/monitoring/check-site-script"
|
9
|
+
|
10
|
+
include HQ::SysTools::Monitoring
|
11
|
+
|
12
|
+
script = CheckSiteScript.new
|
13
|
+
script.args = ARGV
|
14
|
+
script.main
|
15
|
+
exit script.status
|
@@ -0,0 +1,178 @@
|
|
1
|
+
Feature: Check site script
|
2
|
+
|
3
|
+
Background:
|
4
|
+
|
5
|
+
Given a config "default":
|
6
|
+
"""
|
7
|
+
<check-site-script base-url="http://hostname:${port}">
|
8
|
+
<timings warning="2" critical="4" timeout="10"/>
|
9
|
+
<step name="page">
|
10
|
+
<request path="/page"/>
|
11
|
+
<response/>
|
12
|
+
</step>
|
13
|
+
</check-site-script>
|
14
|
+
"""
|
15
|
+
|
16
|
+
Given a config "regex":
|
17
|
+
"""
|
18
|
+
<check-site-script base-url="http://hostname:${port}">
|
19
|
+
<timings warning="2" critical="4" timeout="10"/>
|
20
|
+
<step name="page">
|
21
|
+
<request path="/page"/>
|
22
|
+
<response body-regex="y+e+s+"/>
|
23
|
+
</step>
|
24
|
+
</check-site-script>
|
25
|
+
"""
|
26
|
+
|
27
|
+
Given a config "timeout":
|
28
|
+
"""
|
29
|
+
<check-site-script base-url="http://hostname:${port}">
|
30
|
+
<timings warning="2" critical="4" timeout="0"/>
|
31
|
+
<step name="page">
|
32
|
+
<request path="/page"/>
|
33
|
+
<response/>
|
34
|
+
</step>
|
35
|
+
</check-site-script>
|
36
|
+
"""
|
37
|
+
|
38
|
+
Given a config "http-auth":
|
39
|
+
"""
|
40
|
+
<check-site-script base-url="http://hostname:${port}">
|
41
|
+
<timings warning="2" critical="4" timeout="10"/>
|
42
|
+
<step name="page">
|
43
|
+
<request path="/page" username="USER" password="PASS"/>
|
44
|
+
<response/>
|
45
|
+
</step>
|
46
|
+
</check-site-script>
|
47
|
+
"""
|
48
|
+
|
49
|
+
Given a config "form-auth":
|
50
|
+
"""
|
51
|
+
<check-site-script base-url="http://hostname:${port}">
|
52
|
+
<timings warning="2" critical="4" timeout="10"/>
|
53
|
+
<step name="login">
|
54
|
+
<request path="/login" method="post">
|
55
|
+
<param name="username" value="USER"/>
|
56
|
+
<param name="password" value="PASS"/>
|
57
|
+
</request>
|
58
|
+
<response/>
|
59
|
+
</step>
|
60
|
+
<step name="page">
|
61
|
+
<request path="/page" username="USER" password="PASS"/>
|
62
|
+
<response/>
|
63
|
+
</step>
|
64
|
+
</check-site-script>
|
65
|
+
"""
|
66
|
+
|
67
|
+
Given a config "no-path":
|
68
|
+
"""
|
69
|
+
<check-site-script base-url="http://hostname:${port}/page">
|
70
|
+
<timings warning="2" critical="4" timeout="10"/>
|
71
|
+
<step name="page">
|
72
|
+
<request/>
|
73
|
+
<response/>
|
74
|
+
</step>
|
75
|
+
</check-site-script>
|
76
|
+
"""
|
77
|
+
|
78
|
+
Given a config "wrong-port":
|
79
|
+
"""
|
80
|
+
<check-site-script base-url="http://hostname:65535">
|
81
|
+
<timings warning="2" critical="4" timeout="10"/>
|
82
|
+
<step name="page">
|
83
|
+
<request path="/path"/>
|
84
|
+
<response/>
|
85
|
+
</step>
|
86
|
+
</check-site-script>
|
87
|
+
"""
|
88
|
+
|
89
|
+
Scenario: Site responds in ok time
|
90
|
+
Given one server which responds in 1 second
|
91
|
+
When check-site is run with config "default"
|
92
|
+
Then all servers should receive page requests
|
93
|
+
And the message should be "Site OK: 1 hosts found, 1.0s time"
|
94
|
+
And the status should be 0
|
95
|
+
|
96
|
+
Scenario: Site responds in warning time
|
97
|
+
Given one server which responds in 1 second
|
98
|
+
And one server which responds in 3 seconds
|
99
|
+
When check-site is run with config "default"
|
100
|
+
Then all servers should receive page requests
|
101
|
+
And the message should be "Site WARNING: 2 hosts found, 3.0s time (warning is 2.0)"
|
102
|
+
And the status should be 1
|
103
|
+
|
104
|
+
Scenario: Site responds in critical time
|
105
|
+
Given one server which responds in 1 second
|
106
|
+
And one server which responds in 3 seconds
|
107
|
+
And one server which responds in 5 seconds
|
108
|
+
When check-site is run with config "default"
|
109
|
+
Then all servers should receive page requests
|
110
|
+
And the message should be "Site CRITICAL: 3 hosts found, 5.0s time (critical is 4.0)"
|
111
|
+
And the status should be 2
|
112
|
+
|
113
|
+
Scenario: Body contains regex
|
114
|
+
Given one server which responds with "-yes-"
|
115
|
+
When check-site is run with config "regex"
|
116
|
+
Then all servers should receive page requests
|
117
|
+
And the message should be "Site OK: 1 hosts found, 0.0s time"
|
118
|
+
And the status should be 0
|
119
|
+
|
120
|
+
Scenario: Body does not contain regex
|
121
|
+
Given one server which responds with "-yes-"
|
122
|
+
And one server which responds with "-no-"
|
123
|
+
When check-site is run with config "regex"
|
124
|
+
Then all servers should receive page requests
|
125
|
+
And the message should be "Site CRITICAL: 2 hosts found, 1 mismatches, 0.0s time"
|
126
|
+
And the status should be 2
|
127
|
+
|
128
|
+
Scenario: Timeout does not expire
|
129
|
+
Given one server which responds in 0 seconds
|
130
|
+
When check-site is run with config "default"
|
131
|
+
Then all servers should receive page requests
|
132
|
+
And the message should be "Site OK: 1 hosts found, 0.0s time"
|
133
|
+
And the status should be 0
|
134
|
+
|
135
|
+
Scenario: Timeout expires
|
136
|
+
Given one server which responds in 0 seconds
|
137
|
+
When check-site is run with config "timeout"
|
138
|
+
And the message should be "Site CRITICAL: 1 hosts found, 1 uncontactable"
|
139
|
+
And the status should be 2
|
140
|
+
|
141
|
+
Scenario: Username and password are correct
|
142
|
+
Given one server which requires username "USER" and password "PASS"
|
143
|
+
When check-site is run with config "http-auth"
|
144
|
+
Then all servers should receive page requests
|
145
|
+
And the message should be "Site OK: 1 hosts found, 0.0s time"
|
146
|
+
And the status should be 0
|
147
|
+
|
148
|
+
Scenario: Username and password are incorrect
|
149
|
+
Given one server which requires username "USER" and password "SECRET"
|
150
|
+
When check-site is run with config "http-auth"
|
151
|
+
Then all servers should receive page requests
|
152
|
+
And the message should be "Site CRITICAL: 1 hosts found, 1 errors (401), 0.0s time"
|
153
|
+
And the status should be 2
|
154
|
+
|
155
|
+
Scenario: No servers
|
156
|
+
When check-site is run with config "default"
|
157
|
+
And the message should be "Site CRITICAL: unable to resolve hostname"
|
158
|
+
And the status should be 2
|
159
|
+
|
160
|
+
Scenario: Form based login
|
161
|
+
Given one server which requires form based login with "USER" and "PASS"
|
162
|
+
When check-site is run with config "form-auth"
|
163
|
+
Then all servers should receive page requests
|
164
|
+
And the message should be "Site OK: 1 hosts found, 0.0s time"
|
165
|
+
And the status should be 0
|
166
|
+
|
167
|
+
Scenario: No path specified
|
168
|
+
Given one server which responds in 0 seconds
|
169
|
+
When check-site is run with config "no-path"
|
170
|
+
Then all servers should receive page requests
|
171
|
+
And the message should be "Site OK: 1 hosts found, 0.0s time"
|
172
|
+
And the status should be 0
|
173
|
+
|
174
|
+
Scenario: Connection refused
|
175
|
+
Given one server which responds in 0 seconds
|
176
|
+
When check-site is run with config "wrong-port"
|
177
|
+
Then the message should be "Site CRITICAL: 1 hosts found, 1 uncontactable"
|
178
|
+
And the status should be 2
|
@@ -0,0 +1,105 @@
|
|
1
|
+
require "cucumber/rspec/doubles"
|
2
|
+
require "webrick"
|
3
|
+
require "xml"
|
4
|
+
|
5
|
+
require "hq/check-site/script"
|
6
|
+
|
7
|
+
$web_config = {
|
8
|
+
:Port => 10000 + rand(55535),
|
9
|
+
:AccessLog => [],
|
10
|
+
:Logger => WEBrick::Log::new("/dev/null", 7),
|
11
|
+
:DoNotReverseLookup => true,
|
12
|
+
}
|
13
|
+
|
14
|
+
$web_server =
|
15
|
+
WEBrick::HTTPServer.new \
|
16
|
+
$web_config
|
17
|
+
|
18
|
+
Thread.new do
|
19
|
+
$web_server.start
|
20
|
+
end
|
21
|
+
|
22
|
+
at_exit do
|
23
|
+
$web_server.shutdown
|
24
|
+
end
|
25
|
+
|
26
|
+
$web_server.mount_proc "/login" do
|
27
|
+
|request, response|
|
28
|
+
|
29
|
+
server_address = request.addr[3]
|
30
|
+
server = $servers[server_address]
|
31
|
+
|
32
|
+
raise "auth method" unless server[:auth_method] == :form
|
33
|
+
raise "request method" unless request.request_method == "POST"
|
34
|
+
raise "username" unless request.query["username"] == server[:auth_username]
|
35
|
+
raise "password" unless request.query["password"] == server[:auth_password]
|
36
|
+
|
37
|
+
# set session id
|
38
|
+
|
39
|
+
server[:session_id] = (?a..?z).to_a.sample(10).join
|
40
|
+
|
41
|
+
# add session cookie and more to make it harder
|
42
|
+
|
43
|
+
misc_cookie_0 = WEBrick::Cookie.new "foo", "bar"
|
44
|
+
misc_cookie_0.path = "/"
|
45
|
+
response.cookies << misc_cookie_0
|
46
|
+
|
47
|
+
session_cookie = WEBrick::Cookie.new "session", server[:session_id]
|
48
|
+
session_cookie.expires = Time.now + 60
|
49
|
+
response.cookies << session_cookie
|
50
|
+
|
51
|
+
misc_cookie_1 = WEBrick::Cookie.new "blah", "meh"
|
52
|
+
misc_cookie_0.path = "/"
|
53
|
+
response.cookies << misc_cookie_1
|
54
|
+
|
55
|
+
end
|
56
|
+
|
57
|
+
$web_server.mount_proc "/page" do
|
58
|
+
|request, response|
|
59
|
+
|
60
|
+
server_address = request.addr[3]
|
61
|
+
server = $servers[server_address]
|
62
|
+
|
63
|
+
server[:request_count] += 1
|
64
|
+
|
65
|
+
if server[:auth_method] == :http
|
66
|
+
WEBrick::HTTPAuth.basic_auth request, response, "Realm" do
|
67
|
+
|user, pass|
|
68
|
+
user == server[:auth_username] &&
|
69
|
+
pass == server[:auth_password]
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
if server[:auth_method] == :form
|
74
|
+
|
75
|
+
session_cookie =
|
76
|
+
request.cookies.find {
|
77
|
+
|cookie|
|
78
|
+
cookie.name == "session"
|
79
|
+
}
|
80
|
+
|
81
|
+
session_id =
|
82
|
+
session_cookie.value
|
83
|
+
|
84
|
+
raise "not logged in" \
|
85
|
+
unless session_id = server[:session_id]
|
86
|
+
|
87
|
+
end
|
88
|
+
|
89
|
+
response.status = server[:response_code]
|
90
|
+
response.body = server[:response_body]
|
91
|
+
|
92
|
+
$time += server[:response_time]
|
93
|
+
|
94
|
+
end
|
95
|
+
|
96
|
+
Before do
|
97
|
+
|
98
|
+
$servers = {}
|
99
|
+
$time = Time.now
|
100
|
+
|
101
|
+
@configs = {}
|
102
|
+
|
103
|
+
Time.stub(:now) { $time }
|
104
|
+
|
105
|
+
end
|
@@ -0,0 +1,121 @@
|
|
1
|
+
Given /^a config "(.*?)":$/ do
|
2
|
+
|name, content|
|
3
|
+
@configs[name] = content
|
4
|
+
end
|
5
|
+
|
6
|
+
Given /^(?:one|another) server which responds in (\d+) seconds?$/ do
|
7
|
+
|time_str|
|
8
|
+
|
9
|
+
server = {
|
10
|
+
address: "127.0.1.#{$servers.size}",
|
11
|
+
request_count: 0,
|
12
|
+
response_code: "200",
|
13
|
+
response_time: time_str.to_i,
|
14
|
+
response_body: "",
|
15
|
+
}
|
16
|
+
|
17
|
+
$servers[server[:address]] = server
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
Given /^(?:one|another) server which responds with "(.*?)"$/ do
|
22
|
+
|response_str|
|
23
|
+
|
24
|
+
server = {
|
25
|
+
address: "127.0.1.#{$servers.size}",
|
26
|
+
request_count: 0,
|
27
|
+
response_code: "200",
|
28
|
+
response_time: 0,
|
29
|
+
response_body: response_str,
|
30
|
+
}
|
31
|
+
|
32
|
+
$servers[server[:address]] = server
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
Given /^(?:one|another) server which requires username "([^"]*)" and password "([^"]+)"$/ do
|
37
|
+
|username, password|
|
38
|
+
|
39
|
+
server = {
|
40
|
+
address: "127.0.1.#{$servers.size}",
|
41
|
+
request_count: 0,
|
42
|
+
response_code: "200",
|
43
|
+
response_time: 0,
|
44
|
+
response_body: "",
|
45
|
+
auth_method: :http,
|
46
|
+
auth_username: username,
|
47
|
+
auth_password: password,
|
48
|
+
}
|
49
|
+
|
50
|
+
$servers[server[:address]] = server
|
51
|
+
|
52
|
+
end
|
53
|
+
|
54
|
+
Given /^one server which requires form based login with "([^"]*)" and "([^"]*)"$/ do
|
55
|
+
|username, password|
|
56
|
+
|
57
|
+
server = {
|
58
|
+
address: "127.0.1.#{$servers.size}",
|
59
|
+
request_count: 0,
|
60
|
+
response_code: "200",
|
61
|
+
response_time: 0,
|
62
|
+
response_body: "",
|
63
|
+
auth_method: :form,
|
64
|
+
auth_username: username,
|
65
|
+
auth_password: password,
|
66
|
+
}
|
67
|
+
|
68
|
+
$servers[server[:address]] = server
|
69
|
+
|
70
|
+
end
|
71
|
+
|
72
|
+
When /^check\-site is run with config "([^"]*)"$/ do
|
73
|
+
|config_name|
|
74
|
+
|
75
|
+
Resolv.stub(:getaddresses).and_return(
|
76
|
+
$servers.values.map {
|
77
|
+
|server| server[:address]
|
78
|
+
}
|
79
|
+
)
|
80
|
+
|
81
|
+
@script =
|
82
|
+
HQ::CheckSite::Script.new
|
83
|
+
|
84
|
+
@script.stdout = StringIO.new
|
85
|
+
@script.stderr = StringIO.new
|
86
|
+
|
87
|
+
Tempfile.open "check-site-script-" do
|
88
|
+
|temp|
|
89
|
+
|
90
|
+
config_str = @configs[config_name]
|
91
|
+
config_str.gsub! "${port}", $web_config[:Port].to_s
|
92
|
+
config_doc = XML::Document.string config_str
|
93
|
+
temp.write config_doc
|
94
|
+
temp.flush
|
95
|
+
|
96
|
+
@script.args = [
|
97
|
+
"--config", temp.path,
|
98
|
+
]
|
99
|
+
|
100
|
+
@script.main
|
101
|
+
|
102
|
+
end
|
103
|
+
|
104
|
+
end
|
105
|
+
|
106
|
+
Then /^all servers should receive page requests$/ do
|
107
|
+
$servers.each do
|
108
|
+
|server_address, server|
|
109
|
+
server[:request_count].should >= 1
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
Then /^the status should be (\d+)$/ do
|
114
|
+
|status_str|
|
115
|
+
@script.status.should == status_str.to_i
|
116
|
+
end
|
117
|
+
|
118
|
+
Then /^the message should be "(.*?)"$/ do
|
119
|
+
|message|
|
120
|
+
@script.stdout.string.strip.should == message
|
121
|
+
end
|
@@ -0,0 +1,269 @@
|
|
1
|
+
require "net/http"
|
2
|
+
require "net/https"
|
3
|
+
require "resolv"
|
4
|
+
require "set"
|
5
|
+
require "webrick"
|
6
|
+
require "xml"
|
7
|
+
|
8
|
+
require "hq/tools/check-script"
|
9
|
+
require "hq/tools/getopt"
|
10
|
+
|
11
|
+
module HQ
|
12
|
+
module CheckSite
|
13
|
+
class Script < Tools::CheckScript
|
14
|
+
|
15
|
+
# custom http class allows us to connect to a different address
|
16
|
+
|
17
|
+
class CustomHTTP < Net::HTTP
|
18
|
+
attr_accessor :conn_address
|
19
|
+
end
|
20
|
+
|
21
|
+
def initialize
|
22
|
+
super
|
23
|
+
@name = "Site"
|
24
|
+
end
|
25
|
+
|
26
|
+
def process_args
|
27
|
+
|
28
|
+
@opts, @args =
|
29
|
+
Tools::Getopt.process @args, [
|
30
|
+
|
31
|
+
{ :name => :config,
|
32
|
+
:required => true },
|
33
|
+
|
34
|
+
{ :name => :debug,
|
35
|
+
:boolean => true },
|
36
|
+
|
37
|
+
]
|
38
|
+
|
39
|
+
@args.empty? or raise "Extra args on command line"
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
def prepare
|
44
|
+
|
45
|
+
config_doc =
|
46
|
+
XML::Document.file @opts[:config]
|
47
|
+
|
48
|
+
@config_elem =
|
49
|
+
config_doc.root
|
50
|
+
|
51
|
+
@timings_elem =
|
52
|
+
@config_elem.find_first "timings"
|
53
|
+
|
54
|
+
@critical_time =
|
55
|
+
@timings_elem["critical"].to_f
|
56
|
+
|
57
|
+
@warning_time =
|
58
|
+
@timings_elem["warning"].to_f
|
59
|
+
|
60
|
+
@timeout_time =
|
61
|
+
@timings_elem["timeout"].to_f
|
62
|
+
|
63
|
+
@base_url = URI.parse @config_elem["base-url"]
|
64
|
+
|
65
|
+
end
|
66
|
+
|
67
|
+
def perform_checks
|
68
|
+
|
69
|
+
addresses = Resolv.getaddresses @base_url.host
|
70
|
+
|
71
|
+
@worst = nil
|
72
|
+
@successes = 0
|
73
|
+
@failures = 0
|
74
|
+
@mismatches = 0
|
75
|
+
@error_codes = Set.new
|
76
|
+
|
77
|
+
addresses.each do
|
78
|
+
|address|
|
79
|
+
|
80
|
+
check_address address
|
81
|
+
|
82
|
+
end
|
83
|
+
|
84
|
+
errors = @error_codes.size
|
85
|
+
total = @successes + errors + @failures + @mismatches
|
86
|
+
|
87
|
+
if total == 0
|
88
|
+
critical "unable to resolve #{@base_url.host}"
|
89
|
+
else
|
90
|
+
message "#{total} hosts found"
|
91
|
+
|
92
|
+
critical "#{@failures} uncontactable" \
|
93
|
+
if @failures > 0
|
94
|
+
|
95
|
+
critical "#{errors} errors (#{@error_codes.to_a.join(",")})" \
|
96
|
+
if errors > 0
|
97
|
+
|
98
|
+
critical "#{@mismatches} mismatches" \
|
99
|
+
if @mismatches > 0
|
100
|
+
|
101
|
+
if @worst != nil
|
102
|
+
|
103
|
+
if @worst >= @critical_time
|
104
|
+
critical "#{@worst}s time (critical is #{@critical_time})"
|
105
|
+
elsif @worst >= @warning_time
|
106
|
+
warning "#{@worst}s time (warning is #{@warning_time})"
|
107
|
+
else
|
108
|
+
message "#{@worst}s time"
|
109
|
+
end
|
110
|
+
|
111
|
+
end
|
112
|
+
|
113
|
+
end
|
114
|
+
|
115
|
+
end
|
116
|
+
|
117
|
+
def check_address address
|
118
|
+
|
119
|
+
cookies = {}
|
120
|
+
|
121
|
+
begin
|
122
|
+
|
123
|
+
# open http connection
|
124
|
+
|
125
|
+
http = CustomHTTP.new @base_url.host, @base_url.port
|
126
|
+
http.conn_address = address
|
127
|
+
http.open_timeout = @timeout_time
|
128
|
+
http.read_timeout = @timeout_time
|
129
|
+
http.use_ssl = @base_url.scheme == "https"
|
130
|
+
http.start
|
131
|
+
|
132
|
+
success = true
|
133
|
+
|
134
|
+
@config_elem.find("step").each do
|
135
|
+
|step_elem|
|
136
|
+
|
137
|
+
success =
|
138
|
+
check_step http, cookies, step_elem
|
139
|
+
|
140
|
+
break unless success
|
141
|
+
|
142
|
+
end
|
143
|
+
|
144
|
+
@successes += 1 if success
|
145
|
+
|
146
|
+
rescue Errno::ECONNREFUSED
|
147
|
+
|
148
|
+
@failures += 1
|
149
|
+
|
150
|
+
rescue Timeout::Error
|
151
|
+
|
152
|
+
@failures += 1
|
153
|
+
|
154
|
+
end
|
155
|
+
|
156
|
+
end
|
157
|
+
|
158
|
+
def check_step http, cookies, step_elem
|
159
|
+
|
160
|
+
@postscript << "performing step #{step_elem["name"]}"
|
161
|
+
|
162
|
+
request_elem = step_elem.find_first "request"
|
163
|
+
response_elem = step_elem.find_first "response"
|
164
|
+
|
165
|
+
# create request
|
166
|
+
|
167
|
+
path = @base_url.path + (request_elem["path"] || "")
|
168
|
+
|
169
|
+
req =
|
170
|
+
case request_elem["method"] || "get"
|
171
|
+
when "get"
|
172
|
+
Net::HTTP::Get.new path
|
173
|
+
when "post"
|
174
|
+
Net::HTTP::Post.new path
|
175
|
+
else
|
176
|
+
raise "error"
|
177
|
+
end
|
178
|
+
|
179
|
+
# set headers
|
180
|
+
|
181
|
+
req["host"] = @base_url.host
|
182
|
+
req["user-agent"] = "hq check-site"
|
183
|
+
|
184
|
+
unless cookies.empty?
|
185
|
+
req["cookie"] =
|
186
|
+
cookies.map {
|
187
|
+
|name, value|
|
188
|
+
"#{name}=#{value}"
|
189
|
+
}.join ", "
|
190
|
+
end
|
191
|
+
|
192
|
+
# set http auth
|
193
|
+
|
194
|
+
if request_elem["username"]
|
195
|
+
req.basic_auth \
|
196
|
+
request_elem["username"],
|
197
|
+
request_elem["password"]
|
198
|
+
end
|
199
|
+
|
200
|
+
# set form data
|
201
|
+
|
202
|
+
form_data = {}
|
203
|
+
|
204
|
+
request_elem.find("param").each do |param_elem|
|
205
|
+
form_data[param_elem["name"]] = param_elem["value"]
|
206
|
+
end
|
207
|
+
|
208
|
+
req.set_form_data form_data
|
209
|
+
|
210
|
+
# make request
|
211
|
+
|
212
|
+
start_time = Time.now
|
213
|
+
|
214
|
+
res = http.request req
|
215
|
+
|
216
|
+
end_time = Time.now
|
217
|
+
duration = end_time - start_time
|
218
|
+
|
219
|
+
# save cookies
|
220
|
+
|
221
|
+
if res["set-cookie"]
|
222
|
+
WEBrick::Cookie.parse_set_cookies(res["set-cookie"]).each do
|
223
|
+
|cookie|
|
224
|
+
cookies[cookie.name] = cookie.value
|
225
|
+
end
|
226
|
+
end
|
227
|
+
|
228
|
+
# process results
|
229
|
+
|
230
|
+
@worst = duration if @worst == nil
|
231
|
+
@worst = duration if duration > @worst
|
232
|
+
|
233
|
+
debug "REQUEST #{req.path}"
|
234
|
+
req.each { |k,v| debug " #{k}: #{v}" }
|
235
|
+
debug "RESPONSE #{res.code} #{res.message}"
|
236
|
+
res.each { |k,v| debug " #{k}: #{v}" }
|
237
|
+
|
238
|
+
if res.code != "200"
|
239
|
+
|
240
|
+
debug "EXPECTED response code 200"
|
241
|
+
@error_codes << res.code
|
242
|
+
return false
|
243
|
+
|
244
|
+
elsif response_elem["body-regex"] &&
|
245
|
+
res.body !~ /#{response_elem["body-regex"]}/
|
246
|
+
|
247
|
+
debug "EXPECTED body to match #{response_elem["body-regex"]}"
|
248
|
+
|
249
|
+
if @opts[:debug]
|
250
|
+
debug "BODY"
|
251
|
+
debug res.body.gsub(/^/, " ")
|
252
|
+
end
|
253
|
+
|
254
|
+
@mismatches += 1
|
255
|
+
return false
|
256
|
+
|
257
|
+
end
|
258
|
+
|
259
|
+
return true
|
260
|
+
|
261
|
+
end
|
262
|
+
|
263
|
+
def debug message
|
264
|
+
@postscript << message
|
265
|
+
end
|
266
|
+
|
267
|
+
end
|
268
|
+
end
|
269
|
+
end
|
metadata
ADDED
@@ -0,0 +1,182 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: hq-check-site
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- James Pharaoh
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-04-05 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: hq-tools
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 0.3.1
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 0.3.1
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: libxml-ruby
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 2.6.0
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 2.6.0
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: capybara
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 2.0.2
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 2.0.2
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: cucumber
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 1.2.1
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: 1.2.1
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: rake
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: 10.0.3
|
86
|
+
type: :development
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: 10.0.3
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
name: rspec
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ! '>='
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: 2.12.0
|
102
|
+
type: :development
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: 2.12.0
|
110
|
+
- !ruby/object:Gem::Dependency
|
111
|
+
name: rspec_junit_formatter
|
112
|
+
requirement: !ruby/object:Gem::Requirement
|
113
|
+
none: false
|
114
|
+
requirements:
|
115
|
+
- - ! '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
none: false
|
122
|
+
requirements:
|
123
|
+
- - ! '>='
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
126
|
+
- !ruby/object:Gem::Dependency
|
127
|
+
name: simplecov
|
128
|
+
requirement: !ruby/object:Gem::Requirement
|
129
|
+
none: false
|
130
|
+
requirements:
|
131
|
+
- - ! '>='
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: '0'
|
134
|
+
type: :development
|
135
|
+
prerelease: false
|
136
|
+
version_requirements: !ruby/object:Gem::Requirement
|
137
|
+
none: false
|
138
|
+
requirements:
|
139
|
+
- - ! '>='
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
version: '0'
|
142
|
+
description: HQ nagios plugin to check a web site
|
143
|
+
email:
|
144
|
+
- james@phsys.co.uk
|
145
|
+
executables:
|
146
|
+
- hq-check-site
|
147
|
+
extensions: []
|
148
|
+
extra_rdoc_files: []
|
149
|
+
files:
|
150
|
+
- lib/hq/check-site/script.rb
|
151
|
+
- features/check-site.feature
|
152
|
+
- features/support/steps.rb
|
153
|
+
- features/support/env.rb
|
154
|
+
- bin/hq-check-site
|
155
|
+
homepage: https://github.com/jamespharaoh/hq-check-site
|
156
|
+
licenses: []
|
157
|
+
post_install_message:
|
158
|
+
rdoc_options: []
|
159
|
+
require_paths:
|
160
|
+
- lib
|
161
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
162
|
+
none: false
|
163
|
+
requirements:
|
164
|
+
- - ! '>='
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '0'
|
167
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
168
|
+
none: false
|
169
|
+
requirements:
|
170
|
+
- - ! '>='
|
171
|
+
- !ruby/object:Gem::Version
|
172
|
+
version: 1.3.6
|
173
|
+
requirements: []
|
174
|
+
rubyforge_project: hq-check-site
|
175
|
+
rubygems_version: 1.8.23
|
176
|
+
signing_key:
|
177
|
+
specification_version: 3
|
178
|
+
summary: HQ check site script
|
179
|
+
test_files:
|
180
|
+
- features/check-site.feature
|
181
|
+
- features/support/steps.rb
|
182
|
+
- features/support/env.rb
|