hq-sms-global-balance-check 0.1.0 → 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.
- checksums.yaml +4 -4
- data/features/basic.feature +22 -0
- data/features/cache.feature +28 -3
- data/features/support/steps.rb +10 -0
- data/features/support/web-server.rb +4 -0
- data/lib/hq/sms-global/balance-check/script.rb +37 -18
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ac2884b718655062111084b5f841ce23c62bbfc0
|
4
|
+
data.tar.gz: 67f8bb1a7a52b4ec07ba2faeca8d327249815f80
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4c560444e4484a7bb35974f706b9a2f9bb0d7d9e05b60d593e40ed8ba2727c5c588c1f0ae774f7eb347982f0b6c4f35abf9f53edca3e1adbddcd51deac3ee639
|
7
|
+
data.tar.gz: 4ab8340f21425d5cb7eca5c68bc7cda601e5a32c7c09c2cc493439818c9212a8eba3cc6d4d24d159151d892691a0c69c13e5630a509b7ec76e8823a25dfe2a9f
|
data/features/basic.feature
CHANGED
@@ -16,6 +16,16 @@ Feature: Basic functionality
|
|
16
16
|
--account account
|
17
17
|
--warning 500
|
18
18
|
--critical 100
|
19
|
+
--timeout 10
|
20
|
+
"""
|
21
|
+
|
22
|
+
Given a file "timeout.args":
|
23
|
+
"""
|
24
|
+
--config default.config
|
25
|
+
--account account
|
26
|
+
--warning 500
|
27
|
+
--critical 100
|
28
|
+
--timeout 0
|
19
29
|
"""
|
20
30
|
|
21
31
|
Scenario: Balance ok
|
@@ -53,3 +63,15 @@ Feature: Basic functionality
|
|
53
63
|
"""
|
54
64
|
SMS Global account CRITICAL: 50 credits (critical is 100)
|
55
65
|
"""
|
66
|
+
|
67
|
+
Scenario: Read timeout
|
68
|
+
|
69
|
+
Given the server is slow to respond
|
70
|
+
|
71
|
+
When I run the script with "timeout.args"
|
72
|
+
|
73
|
+
Then the status should be 3
|
74
|
+
And the output should be:
|
75
|
+
"""
|
76
|
+
SMS Global account UNKNOWN: server timed out
|
77
|
+
"""
|
data/features/cache.feature
CHANGED
@@ -21,6 +21,18 @@ Feature: Cached results
|
|
21
21
|
--account account
|
22
22
|
--warning 500
|
23
23
|
--critical 100
|
24
|
+
--timeout 10
|
25
|
+
--cache-warning 10
|
26
|
+
--cache-critical 20
|
27
|
+
"""
|
28
|
+
|
29
|
+
And a file "timeout.args":
|
30
|
+
"""
|
31
|
+
--config default.config
|
32
|
+
--account account
|
33
|
+
--warning 500
|
34
|
+
--critical 100
|
35
|
+
--timeout 0
|
24
36
|
--cache-warning 10
|
25
37
|
--cache-critical 20
|
26
38
|
"""
|
@@ -41,7 +53,7 @@ Feature: Cached results
|
|
41
53
|
Then the status should be 0
|
42
54
|
And the output should be:
|
43
55
|
"""
|
44
|
-
SMS Global account OK: 750 credits, last check 5 seconds ago
|
56
|
+
SMS Global account OK: server status 500, 750 credits, last check 5 seconds ago
|
45
57
|
"""
|
46
58
|
|
47
59
|
Scenario: Cache warning
|
@@ -54,7 +66,7 @@ Feature: Cached results
|
|
54
66
|
Then the status should be 1
|
55
67
|
And the output should be:
|
56
68
|
"""
|
57
|
-
SMS Global account WARNING: 750 credits, last check 15 seconds ago (warning is 10)
|
69
|
+
SMS Global account WARNING: server status 500, 750 credits, last check 15 seconds ago (warning is 10)
|
58
70
|
"""
|
59
71
|
|
60
72
|
Scenario: Cache critical
|
@@ -67,5 +79,18 @@ Feature: Cached results
|
|
67
79
|
Then the status should be 2
|
68
80
|
And the output should be:
|
69
81
|
"""
|
70
|
-
SMS Global account CRITICAL: 750 credits, last check 25 seconds ago (critical is 20)
|
82
|
+
SMS Global account CRITICAL: server status 500, 750 credits, last check 25 seconds ago (critical is 20)
|
83
|
+
"""
|
84
|
+
|
85
|
+
Scenario: Cache warning with timeout
|
86
|
+
|
87
|
+
Given the time is 115
|
88
|
+
And the server is slow to respond
|
89
|
+
|
90
|
+
When I run the script with "timeout.args"
|
91
|
+
|
92
|
+
Then the status should be 1
|
93
|
+
And the output should be:
|
94
|
+
"""
|
95
|
+
SMS Global account WARNING: server timed out, 750 credits, last check 15 seconds ago (warning is 10)
|
71
96
|
"""
|
data/features/support/steps.rb
CHANGED
@@ -15,6 +15,12 @@ Given /^the server is offline$/ do
|
|
15
15
|
|
16
16
|
end
|
17
17
|
|
18
|
+
Given /^the server is slow to respond$/ do
|
19
|
+
|
20
|
+
$status = :slow
|
21
|
+
|
22
|
+
end
|
23
|
+
|
18
24
|
When /^I run the script with "(.+)"$/ do
|
19
25
|
|args_file|
|
20
26
|
|
@@ -37,3 +43,7 @@ Then /^the output should be:$/ do
|
|
37
43
|
|expected_output|
|
38
44
|
@script.stdout.string.strip.should == expected_output
|
39
45
|
end
|
46
|
+
|
47
|
+
Then /^show stderr$/ do
|
48
|
+
puts @script.stderr.string
|
49
|
+
end
|
@@ -33,6 +33,10 @@ class Script < Tools::CheckScript
|
|
33
33
|
:convert => :to_f,
|
34
34
|
:required => true },
|
35
35
|
|
36
|
+
{ :name => :timeout,
|
37
|
+
:convert => :to_f,
|
38
|
+
:required => true },
|
39
|
+
|
36
40
|
{ :name => :cache_warning,
|
37
41
|
:convert => :to_i },
|
38
42
|
|
@@ -76,21 +80,16 @@ class Script < Tools::CheckScript
|
|
76
80
|
|
77
81
|
def perform_checks
|
78
82
|
|
79
|
-
|
80
|
-
|
81
|
-
begin
|
82
|
-
|
83
|
-
get_balance_from_server
|
84
|
-
|
85
|
-
rescue => exception
|
86
|
-
|
87
|
-
raise exception \
|
88
|
-
unless @cache_elem
|
83
|
+
get_balance_from_server
|
89
84
|
|
85
|
+
if @actual_balance
|
86
|
+
used_cache = false
|
87
|
+
elsif @cache_elem
|
90
88
|
read_cache
|
91
|
-
|
89
|
+
@unknown = false
|
92
90
|
used_cache = true
|
93
|
-
|
91
|
+
else
|
92
|
+
return
|
94
93
|
end
|
95
94
|
|
96
95
|
# report balance
|
@@ -160,22 +159,42 @@ class Script < Tools::CheckScript
|
|
160
159
|
"password" => @account_elem["password"],
|
161
160
|
})
|
162
161
|
|
163
|
-
|
164
|
-
|
162
|
+
http =
|
163
|
+
Net::HTTP.new url.host, url.port
|
164
|
+
|
165
|
+
http.open_timeout = @opts[:timeout]
|
166
|
+
http.read_timeout = @opts[:timeout]
|
167
|
+
|
168
|
+
http.start
|
169
|
+
|
170
|
+
begin
|
165
171
|
|
166
172
|
request = Net::HTTP::Get.new "#{url.path}?#{url.query}"
|
167
173
|
|
168
174
|
response = http.request request
|
169
175
|
|
170
|
-
|
171
|
-
|
176
|
+
unless response.code == "200"
|
177
|
+
unknown "server status #{response.code}"
|
178
|
+
return
|
179
|
+
end
|
172
180
|
|
173
|
-
|
174
|
-
|
181
|
+
unless response.body =~ /^BALANCE: ([^;]+); USER: (.+)$/
|
182
|
+
unknown "invalid server response"
|
183
|
+
return
|
184
|
+
end
|
175
185
|
|
176
186
|
@actual_balance =
|
177
187
|
$1.to_f
|
178
188
|
|
189
|
+
rescue Net::ReadTimeout
|
190
|
+
|
191
|
+
unknown "server timed out"
|
192
|
+
return
|
193
|
+
|
194
|
+
ensure
|
195
|
+
|
196
|
+
http.finish
|
197
|
+
|
179
198
|
end
|
180
199
|
|
181
200
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hq-sms-global-balance-check
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Pharaoh
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-05-
|
11
|
+
date: 2013-05-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: hq-tools
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - '>='
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.8.
|
19
|
+
version: 0.8.1
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - '>='
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 0.8.
|
26
|
+
version: 0.8.1
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: libxml-ruby
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -58,14 +58,14 @@ dependencies:
|
|
58
58
|
requirements:
|
59
59
|
- - '>='
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: 0.0.
|
61
|
+
version: 0.0.18
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - '>='
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: 0.0.
|
68
|
+
version: 0.0.18
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: json
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|