hq-check-site 0.1.1 → 0.2.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.
@@ -4,18 +4,18 @@ Feature: Function correctly in edge cases based on config file
4
4
 
5
5
  Given a config "no-path":
6
6
  """
7
- <check-site-script base-url="http://hostname:${port}/page">
8
- <timings warning="2" critical="4" timeout="10"/>
9
- <step name="page">
10
- <request/>
11
- <response/>
12
- </step>
13
- </check-site-script>
7
+ <check-site-script base-url="http://hostname:${port}/page">
8
+ <timings warning="2" critical="4" timeout="10"/>
9
+ <step name="page">
10
+ <request/>
11
+ <response/>
12
+ </step>
13
+ </check-site-script>
14
14
  """
15
15
 
16
16
  Scenario: No path specified
17
17
  Given one server which responds in 0 seconds
18
18
  When check-site is run with config "no-path"
19
19
  Then all servers should receive page requests
20
- And the message should be "Site OK: 1 hosts found, 0.0s time"
20
+ And the message should be "Site OK: 1 hosts found, 0.0s time | time=0s;2;4"
21
21
  And the status should be 0
@@ -4,24 +4,24 @@ Feature: Handle various types of connection error
4
4
 
5
5
  Given a config "default":
6
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>
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
14
  """
15
15
 
16
16
  Given a config "wrong-port":
17
17
  """
18
- <check-site-script base-url="http://hostname:65535">
19
- <timings warning="2" critical="4" timeout="10"/>
20
- <step name="page">
21
- <request path="/path"/>
22
- <response/>
23
- </step>
24
- </check-site-script>
18
+ <check-site-script base-url="http://hostname:65535">
19
+ <timings warning="2" critical="4" timeout="10"/>
20
+ <step name="page">
21
+ <request path="/path"/>
22
+ <response/>
23
+ </step>
24
+ </check-site-script>
25
25
  """
26
26
 
27
27
  Scenario: No servers
@@ -4,27 +4,27 @@ Feature: Authenticate via custom HTTP headers
4
4
 
5
5
  Given a config "default":
6
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
- """
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
15
 
16
16
  Given a config "headers-auth":
17
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
- <header name="username" value="USER"/>
23
- <header name="password" value="PASS"/>
24
- </request>
25
- <response/>
26
- </step>
27
- </check-site-script>
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
+ <header name="username" value="USER"/>
23
+ <header name="password" value="PASS"/>
24
+ </request>
25
+ <response/>
26
+ </step>
27
+ </check-site-script>
28
28
  """
29
29
 
30
30
  Scenario: Form based login success
@@ -4,13 +4,13 @@ Feature: Supply credentials via HTTP authentication
4
4
 
5
5
  Given a config "http-auth":
6
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" username="USER" password="PASS"/>
11
- <response/>
12
- </step>
13
- </check-site-script>
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" username="USER" password="PASS"/>
11
+ <response/>
12
+ </step>
13
+ </check-site-script>
14
14
  """
15
15
 
16
16
  Scenario: Username and password are correct
@@ -4,20 +4,20 @@ Feature: Log in via an HTML form
4
4
 
5
5
  Given a config "form-auth":
6
6
  """
7
- <check-site-script base-url="http://hostname:${port}">
8
- <timings warning="2" critical="4" timeout="10"/>
9
- <step name="login">
10
- <request path="/login" method="post">
11
- <param name="username" value="USER"/>
12
- <param name="password" value="PASS"/>
13
- </request>
14
- <response/>
15
- </step>
16
- <step name="page">
17
- <request path="/page" username="USER" password="PASS"/>
18
- <response/>
19
- </step>
20
- </check-site-script>
7
+ <check-site-script base-url="http://hostname:${port}">
8
+ <timings warning="2" critical="4" timeout="10"/>
9
+ <step name="login">
10
+ <request path="/login" method="post">
11
+ <param name="username" value="USER"/>
12
+ <param name="password" value="PASS"/>
13
+ </request>
14
+ <response/>
15
+ </step>
16
+ <step name="page">
17
+ <request path="/page" username="USER" password="PASS"/>
18
+ <response/>
19
+ </step>
20
+ </check-site-script>
21
21
  """
22
22
 
23
23
  Scenario: Form based login
@@ -4,13 +4,13 @@ Feature: Check for regex in HTTP response
4
4
 
5
5
  Given a config "regex":
6
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 body-regex="y+e+s+"/>
12
- </step>
13
- </check-site-script>
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 body-regex="y+e+s+"/>
12
+ </step>
13
+ </check-site-script>
14
14
  """
15
15
 
16
16
  Scenario: Body contains regex
@@ -0,0 +1,38 @@
1
+ Feature: Check for regex in HTTP response
2
+
3
+ Background:
4
+
5
+ Given a config "report":
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 report-error="\[(.+)\]"/>
12
+ </step>
13
+ </check-site-script>
14
+ """
15
+
16
+ Scenario: No servers to report
17
+
18
+ Given one server which responds with 200 "abc[def]ghi"
19
+ And another server which responds with 500 "abc[]ghi"
20
+
21
+ When check-site is run with config "report"
22
+
23
+ Then all servers should receive page requests
24
+ And the message should be "Site CRITICAL: 2 hosts found, 1 errors (500), 0.0s time"
25
+ And the status should be 2
26
+
27
+ Scenario: One server to report
28
+
29
+ Given one server which responds with 200 "abc[def]ghi"
30
+ And another server which responds with 500 "jkl[]mno"
31
+ And another server which responds with 500 "abc[def]ghi"
32
+ And another server which responds with 500 "jkl[mno]pqr"
33
+
34
+ When check-site is run with config "report"
35
+
36
+ Then all servers should receive page requests
37
+ And the message should be "Site CRITICAL: 4 hosts found, 3 errors (500), 0.0s time, response 'def'"
38
+ And the status should be 2
@@ -4,6 +4,8 @@ require "xml"
4
4
 
5
5
  require "hq/check-site/script"
6
6
 
7
+ $mutex = Mutex.new
8
+
7
9
  $web_config = {
8
10
  :Port => 10000 + rand(55535),
9
11
  :AccessLog => [],
@@ -13,6 +15,24 @@ $web_config = {
13
15
 
14
16
  $servers = {}
15
17
 
18
+ # assign a unique ip address to each server
19
+
20
+ $next_server_num = 256
21
+
22
+ def next_server_num
23
+ ret = $next_server_num
24
+ $next_server_num += 1
25
+ return ret
26
+ end
27
+
28
+ def next_server_ip
29
+ num = next_server_num
30
+ high_byte = num / 256
31
+ low_byte = num % 256
32
+ ip_address = "127.0.#{high_byte}.#{low_byte}"
33
+ return ip_address
34
+ end
35
+
16
36
  $web_server =
17
37
  WEBrick::HTTPServer.new \
18
38
  $web_config
@@ -97,11 +117,11 @@ $web_server.mount_proc "/page" do
97
117
 
98
118
  end
99
119
 
120
+ $time += server[:response_time]
121
+
100
122
  response.status = server[:response_code]
101
123
  response.body = server[:response_body]
102
124
 
103
- $time += server[:response_time]
104
-
105
125
  end
106
126
 
107
127
  Before do
@@ -7,7 +7,7 @@ Given /^(?:one|another) server which responds in (\d+) seconds?$/ do
7
7
  |time_str|
8
8
 
9
9
  server = {
10
- address: "127.0.1.#{$servers.size}",
10
+ address: next_server_ip,
11
11
  request_count: 0,
12
12
  response_code: "200",
13
13
  response_time: time_str.to_i,
@@ -22,7 +22,7 @@ Given /^(?:one|another) server which responds with "(.*?)"$/ do
22
22
  |response_str|
23
23
 
24
24
  server = {
25
- address: "127.0.1.#{$servers.size}",
25
+ address: next_server_ip,
26
26
  request_count: 0,
27
27
  response_code: "200",
28
28
  response_time: 0,
@@ -33,11 +33,26 @@ Given /^(?:one|another) server which responds with "(.*?)"$/ do
33
33
 
34
34
  end
35
35
 
36
+ Given /^(?:one|another) server which responds with (\d+) "(.*?)"$/ do
37
+ |status_str, response_str|
38
+
39
+ server = {
40
+ address: next_server_ip,
41
+ request_count: 0,
42
+ response_code: status_str,
43
+ response_time: 0,
44
+ response_body: response_str,
45
+ }
46
+
47
+ $servers[server[:address]] = server
48
+
49
+ end
50
+
36
51
  Given /^(?:one|another) server which requires username "([^"]*)" and password "([^"]+)"$/ do
37
52
  |username, password|
38
53
 
39
54
  server = {
40
- address: "127.0.1.#{$servers.size}",
55
+ address: next_server_ip,
41
56
  request_count: 0,
42
57
  response_code: "200",
43
58
  response_time: 0,
@@ -55,7 +70,7 @@ Given /^one server which requires form based login with "([^"]*)" and "([^"]*)"$
55
70
  |username, password|
56
71
 
57
72
  server = {
58
- address: "127.0.1.#{$servers.size}",
73
+ address: next_server_ip,
59
74
  request_count: 0,
60
75
  response_code: "200",
61
76
  response_time: 0,
@@ -72,7 +87,7 @@ end
72
87
  Given /^one server which requires header based login$/ do
73
88
 
74
89
  server = {
75
- address: "127.0.1.#{$servers.size}",
90
+ address: next_server_ip,
76
91
  request_count: 0,
77
92
  response_code: "200",
78
93
  response_time: 0,
@@ -4,24 +4,24 @@ Feature: Handle timeout correctly
4
4
 
5
5
  Given a config "default":
6
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>
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
14
  """
15
15
 
16
16
  Given a config "timeout":
17
17
  """
18
- <check-site-script base-url="http://hostname:${port}">
19
- <timings warning="2" critical="4" timeout="0"/>
20
- <step name="page">
21
- <request path="/page"/>
22
- <response/>
23
- </step>
24
- </check-site-script>
18
+ <check-site-script base-url="http://hostname:${port}">
19
+ <timings warning="2" critical="4" timeout="0"/>
20
+ <step name="page">
21
+ <request path="/page"/>
22
+ <response/>
23
+ </step>
24
+ </check-site-script>
25
25
  """
26
26
 
27
27
  Scenario: Timeout does not expire
@@ -0,0 +1,38 @@
1
+ Feature: Return ok/warning/critical based on response time
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
+ Scenario: Site responds in ok time
17
+ Given one server which responds in 1 second
18
+ When check-site is run with config "default"
19
+ Then all servers should receive page requests
20
+ And the message should be "Site OK: 1 hosts found, 1.0s time"
21
+ And the status should be 0
22
+
23
+ Scenario: Site responds in warning time
24
+ Given one server which responds in 1 second
25
+ And one server which responds in 3 seconds
26
+ When check-site is run with config "default"
27
+ Then all servers should receive page requests
28
+ And the message should be "Site WARNING: 2 hosts found, 3.0s time (warning is 2.0)"
29
+ And the status should be 1
30
+
31
+ Scenario: Site responds in critical time
32
+ Given one server which responds in 1 second
33
+ And one server which responds in 3 seconds
34
+ And one server which responds in 5 seconds
35
+ When check-site is run with config "default"
36
+ Then all servers should receive page requests
37
+ And the message should be "Site CRITICAL: 3 hosts found, 5.0s time (critical is 4.0)"
38
+ And the status should be 2
@@ -95,7 +95,8 @@ class Script < Tools::CheckScript
95
95
  @successes = 0
96
96
  @failures = 0
97
97
  @mismatches = 0
98
- @error_codes = Set.new
98
+ @error_codes = []
99
+ @report_error = nil
99
100
 
100
101
  addresses.each do
101
102
  |address|
@@ -115,7 +116,7 @@ class Script < Tools::CheckScript
115
116
  critical "#{@failures} uncontactable" \
116
117
  if @failures > 0
117
118
 
118
- critical "#{errors} errors (#{@error_codes.to_a.join(",")})" \
119
+ critical "#{errors} errors (#{@error_codes.uniq.sort.join ","})" \
119
120
  if errors > 0
120
121
 
121
122
  critical "#{@mismatches} mismatches" \
@@ -133,6 +134,10 @@ class Script < Tools::CheckScript
133
134
 
134
135
  end
135
136
 
137
+ if @report_error != nil
138
+ message "response '#{@report_error}'"
139
+ end
140
+
136
141
  end
137
142
 
138
143
  end
@@ -273,6 +278,14 @@ class Script < Tools::CheckScript
273
278
  if res.code != "200"
274
279
 
275
280
  debug "EXPECTED response code 200"
281
+
282
+ if @report_error == nil &&
283
+ res.body =~ /#{response_elem["report-error"]}/
284
+
285
+ @report_error = $1
286
+
287
+ end
288
+
276
289
  @error_codes << res.code
277
290
  return false
278
291
 
metadata CHANGED
@@ -1,111 +1,126 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hq-check-site
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
+ prerelease:
5
6
  platform: ruby
6
7
  authors:
7
8
  - James Pharaoh
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2013-04-05 00:00:00.000000000 Z
12
+ date: 2013-04-08 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: hq-tools
15
16
  requirement: !ruby/object:Gem::Requirement
17
+ none: false
16
18
  requirements:
17
- - - '>='
19
+ - - ! '>='
18
20
  - !ruby/object:Gem::Version
19
21
  version: 0.3.1
20
22
  type: :runtime
21
23
  prerelease: false
22
24
  version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
23
26
  requirements:
24
- - - '>='
27
+ - - ! '>='
25
28
  - !ruby/object:Gem::Version
26
29
  version: 0.3.1
27
30
  - !ruby/object:Gem::Dependency
28
31
  name: libxml-ruby
29
32
  requirement: !ruby/object:Gem::Requirement
33
+ none: false
30
34
  requirements:
31
- - - '>='
35
+ - - ! '>='
32
36
  - !ruby/object:Gem::Version
33
37
  version: 2.6.0
34
38
  type: :runtime
35
39
  prerelease: false
36
40
  version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
37
42
  requirements:
38
- - - '>='
43
+ - - ! '>='
39
44
  - !ruby/object:Gem::Version
40
45
  version: 2.6.0
41
46
  - !ruby/object:Gem::Dependency
42
47
  name: cucumber
43
48
  requirement: !ruby/object:Gem::Requirement
49
+ none: false
44
50
  requirements:
45
- - - '>='
51
+ - - ! '>='
46
52
  - !ruby/object:Gem::Version
47
53
  version: 1.2.1
48
54
  type: :development
49
55
  prerelease: false
50
56
  version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
51
58
  requirements:
52
- - - '>='
59
+ - - ! '>='
53
60
  - !ruby/object:Gem::Version
54
61
  version: 1.2.1
55
62
  - !ruby/object:Gem::Dependency
56
63
  name: rake
57
64
  requirement: !ruby/object:Gem::Requirement
65
+ none: false
58
66
  requirements:
59
- - - '>='
67
+ - - ! '>='
60
68
  - !ruby/object:Gem::Version
61
69
  version: 10.0.3
62
70
  type: :development
63
71
  prerelease: false
64
72
  version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
65
74
  requirements:
66
- - - '>='
75
+ - - ! '>='
67
76
  - !ruby/object:Gem::Version
68
77
  version: 10.0.3
69
78
  - !ruby/object:Gem::Dependency
70
79
  name: rspec
71
80
  requirement: !ruby/object:Gem::Requirement
81
+ none: false
72
82
  requirements:
73
- - - '>='
83
+ - - ! '>='
74
84
  - !ruby/object:Gem::Version
75
85
  version: 2.12.0
76
86
  type: :development
77
87
  prerelease: false
78
88
  version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
79
90
  requirements:
80
- - - '>='
91
+ - - ! '>='
81
92
  - !ruby/object:Gem::Version
82
93
  version: 2.12.0
83
94
  - !ruby/object:Gem::Dependency
84
95
  name: rspec_junit_formatter
85
96
  requirement: !ruby/object:Gem::Requirement
97
+ none: false
86
98
  requirements:
87
- - - '>='
99
+ - - ! '>='
88
100
  - !ruby/object:Gem::Version
89
101
  version: '0'
90
102
  type: :development
91
103
  prerelease: false
92
104
  version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
93
106
  requirements:
94
- - - '>='
107
+ - - ! '>='
95
108
  - !ruby/object:Gem::Version
96
109
  version: '0'
97
110
  - !ruby/object:Gem::Dependency
98
111
  name: simplecov
99
112
  requirement: !ruby/object:Gem::Requirement
113
+ none: false
100
114
  requirements:
101
- - - '>='
115
+ - - ! '>='
102
116
  - !ruby/object:Gem::Version
103
117
  version: '0'
104
118
  type: :development
105
119
  prerelease: false
106
120
  version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
107
122
  requirements:
108
- - - '>='
123
+ - - ! '>='
109
124
  - !ruby/object:Gem::Version
110
125
  version: '0'
111
126
  description: HQ nagios plugin to check a web site
@@ -120,43 +135,48 @@ files:
120
135
  - features/headers-auth.feature
121
136
  - features/config-edge-cases.feature
122
137
  - features/http-auth.feature
138
+ - features/response-report.feature
123
139
  - features/timeout.feature
124
- - features/body-regex.feature
140
+ - features/timings.feature
125
141
  - features/errors.feature
142
+ - features/response-match.feature
126
143
  - features/login-form.feature
127
144
  - features/support/steps.rb
128
145
  - features/support/env.rb
129
146
  - bin/hq-check-site
130
147
  homepage: https://github.com/jamespharaoh/hq-check-site
131
148
  licenses: []
132
- metadata: {}
133
149
  post_install_message:
134
150
  rdoc_options: []
135
151
  require_paths:
136
152
  - lib
137
153
  required_ruby_version: !ruby/object:Gem::Requirement
154
+ none: false
138
155
  requirements:
139
- - - '>='
156
+ - - ! '>='
140
157
  - !ruby/object:Gem::Version
141
158
  version: '0'
142
159
  required_rubygems_version: !ruby/object:Gem::Requirement
160
+ none: false
143
161
  requirements:
144
- - - '>='
162
+ - - ! '>='
145
163
  - !ruby/object:Gem::Version
146
164
  version: 1.3.6
147
165
  requirements: []
148
166
  rubyforge_project: hq-check-site
149
- rubygems_version: 2.0.0
167
+ rubygems_version: 1.8.23
150
168
  signing_key:
151
- specification_version: 4
169
+ specification_version: 3
152
170
  summary: HQ check site script
153
171
  test_files:
154
172
  - features/headers-auth.feature
155
173
  - features/config-edge-cases.feature
156
174
  - features/http-auth.feature
175
+ - features/response-report.feature
157
176
  - features/timeout.feature
158
- - features/body-regex.feature
177
+ - features/timings.feature
159
178
  - features/errors.feature
179
+ - features/response-match.feature
160
180
  - features/login-form.feature
161
181
  - features/support/steps.rb
162
182
  - features/support/env.rb
checksums.yaml DELETED
@@ -1,7 +0,0 @@
1
- ---
2
- SHA1:
3
- metadata.gz: 7659348d9eaac3642458ab753f08cb2fd6e75af6
4
- data.tar.gz: 95bf5186c43629c2f072524d563d7283016e6f2c
5
- SHA512:
6
- metadata.gz: 244cc2d0c69efe57be259e17575815e796093cc2a834f19c98b94fd49bf444f5dbb3061c523603ab53e1c7962194f9fdc8a9e2b73710dcb4b9c451e2d58da2a4
7
- data.tar.gz: 1195338e453785cc6886023556f144823bea08e8e7f0985db64fbc7b2638b444512f25f74c2e83d83405ec5f1f2037584f69a56cd6e979dfd119e8f11fa6c940