ostrichpoll 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -47,6 +47,7 @@ Configuration is specified in the format:
47
47
  normal_range: [0, 5]
48
48
  missing: ignore
49
49
  exit_code: 2
50
+ exit_message: "Message drop rate is too high"
50
51
  metrics/KafkaEventSink_append_msec/p99:
51
52
  normal_range: [0, 10]
52
53
  missing: error
@@ -64,6 +65,7 @@ Configuration is specified in the format:
64
65
  * `normal_range` an array specifying the minimum and maximum (inclusive) values which are acceptable for this metric
65
66
  * `missing` behavior if the metric is not seen in the output at all. (error by default)
66
67
  * `exit_code` what value Ostrichpoll should exit with if this error is seen.
68
+ * `exit_message` what Ostrichpoll should output to STDOUT if this error is seen. "OK" is the default (if no errors are encountered).
67
69
 
68
70
  ### Notes
69
71
  Ostrichpoll is setup to execute all validations on each execution. Even if one of the early validations fails, the output from all validations is logged to stderr. However, the exit code is the exit code from the first erroring validation.
File without changes
@@ -6,7 +6,7 @@ require 'logger'
6
6
 
7
7
  require 'ostrichpoll/string'
8
8
  require 'ostrichpoll/version'
9
- require 'ostrichpoll/exit_codes'
9
+ require 'ostrichpoll/exit_status'
10
10
  require 'ostrichpoll/config_parser'
11
11
 
12
12
  module OstrichPoll
@@ -46,14 +46,14 @@ module OstrichPoll
46
46
  if @opts[:configfile]
47
47
  yaml = YAML.load_file @opts[:configfile]
48
48
  hosts = ConfigParser.parse(yaml)
49
+ retval = nil
49
50
 
50
- retval = false
51
51
  hosts.each do |h|
52
- retval = h.validate unless retval
52
+ retval = h.validate if retval.nil?
53
53
  end
54
54
 
55
55
  # use the exitcode, unless none is given
56
- exit retval if retval
56
+ retval.exit unless retval.nil?
57
57
 
58
58
  else
59
59
  # if we don't have a config file, simply check that the host and port respond to http
@@ -62,7 +62,7 @@ module OstrichPoll
62
62
  @response = Net::HTTP.get uri
63
63
  rescue Exception => e
64
64
  Log.warn e
65
- exit EXIT_NOHTTP
65
+ EXIT_NOHTTP.exit
66
66
  end
67
67
  end
68
68
 
@@ -71,7 +71,7 @@ rescue SystemExit => e
71
71
 
72
72
  rescue Exception => e
73
73
  Log.error e
74
- exit EXIT_ERROR # exit with error
74
+ ExitStatus.new(e.message, 1).exit # exit with error
75
75
  end
76
76
 
77
- exit OstrichPoll::EXIT_OK
77
+ OstrichPoll::EXIT_OK.exit
@@ -65,6 +65,9 @@ module OstrichPoll
65
65
  when 'exit_code'
66
66
  validator.exit_code = value
67
67
 
68
+ when 'exit_message'
69
+ validator.exit_message = value
70
+
68
71
  else
69
72
  Log.warn "Unknown key for validation: #{key}. Ignoring."
70
73
  end
@@ -0,0 +1,24 @@
1
+ module OstrichPoll
2
+
3
+ class ExitStatus
4
+ attr_accessor :message, :code
5
+
6
+ def initialize(message, code)
7
+ @message = message
8
+ @code = code
9
+ end
10
+
11
+ def exit
12
+ puts @message
13
+ Kernel.exit @code
14
+ end
15
+ end
16
+
17
+
18
+ # generics
19
+ EXIT_OK = ExitStatus.new("OK", 0)
20
+ EXIT_FAIL = ExitStatus.new("", 1)
21
+
22
+ # could not connect to http endpoint
23
+ EXIT_NOHTTP = ExitStatus.new("Ostrichpoll Could not connect to HTTP endpoint", 1)
24
+ end
@@ -23,14 +23,16 @@ module OstrichPoll
23
23
  def validate
24
24
  uri = URI.parse url
25
25
  response = Net::HTTP.get uri rescue (
26
- Log.error "Unable to connect to host #{uri}"
27
- return EXIT_ERROR
26
+ error_msg = "Unable to connect to host #{uri}"
27
+ Log.error error_msg
28
+ return ExitStatus.new(error_msg, 1)
28
29
  )
29
30
 
30
31
  # parse response
31
32
  json = JSON.parse(response) rescue (
32
- Log.error "Invalid JSON response: #{response}"
33
- return EXIT_ERROR
33
+ error_msg = "Invalid JSON response: #{response}"
34
+ Log.error error_msg
35
+ return ExitStatus.new(error_msg, 1)
34
36
  )
35
37
 
36
38
  @stored_values = {}
@@ -52,9 +54,10 @@ module OstrichPoll
52
54
  f.puts json.to_yaml
53
55
  end
54
56
  end
57
+
58
+ retval = nil
55
59
 
56
60
  # execute each validation:
57
- retval = false
58
61
  if validations
59
62
  matched_validations = []
60
63
  validations.each do |v|
@@ -71,7 +74,7 @@ module OstrichPoll
71
74
 
72
75
  matched_validations.each do |v|
73
76
  value = v.check(find_value(json, v.metric))
74
- retval = value unless retval
77
+ retval = value if retval.nil?
75
78
  end
76
79
  end
77
80
 
@@ -133,11 +136,13 @@ module OstrichPoll
133
136
  attr_accessor :normal_range
134
137
  attr_accessor :missing
135
138
  attr_accessor :exit_code
139
+ attr_accessor :exit_message
136
140
 
137
141
  def init
138
142
  @rate = false
139
143
  @regex = false
140
144
  @exit_code = 1
145
+ @exit_message = ""
141
146
  @missing = :ignore
142
147
  end
143
148
 
@@ -145,6 +150,10 @@ module OstrichPoll
145
150
  Log.warn "Invalid metric #{metric.inspect}" unless metric.is_a? String
146
151
  Log.warn "Invalid exit code: #{exit_code.inspect}" unless exit_code.is_a? Integer
147
152
 
153
+ if exit_message
154
+ Log.warn "Invalid exit message: #{exit_message.inspect}" unless exit_message.is_a? String
155
+ end
156
+
148
157
  if normal_range
149
158
  Log.warn "Invalid normal range: #{normal_range.inspect}" unless normal_range.is_a? Array
150
159
  end
@@ -160,12 +169,13 @@ module OstrichPoll
160
169
  # error on missing value unless we ignore missing
161
170
  unless value
162
171
  unless missing == :ignore
163
- Log.warn "#{metric}: value missing, treating as error; exit code #{exit_code}"
164
- return exit_code
172
+ error_msg = "#{metric}: value missing"
173
+ Log.warn "#{error_msg}, treating as error; exit code #{exit_code}"
174
+ return ExitStatus.new(error_msg, exit_code)
165
175
  else
166
176
  Log.debug "#{host_instance.url} | missing value, but set to ignore"
167
177
  # not an error, but you can't check anything else
168
- return false
178
+ return nil
169
179
  end
170
180
  end
171
181
 
@@ -187,7 +197,7 @@ module OstrichPoll
187
197
  else
188
198
  # let it pass
189
199
  Log.info "#{metric}: no previous reading for rate"
190
- return false
200
+ return nil
191
201
  end
192
202
  end
193
203
 
@@ -208,19 +218,19 @@ module OstrichPoll
208
218
  end
209
219
 
210
220
  if lo && value < lo
211
- Log.warn "#{metric}: read value #{value} is below normal range minimum #{lo}; exit code #{exit_code}"
212
- return exit_code
221
+ Log.warn "#{metric}: read value #{value} is below normal range minimum #{lo}; exit code #{exit_code}; exit message '#{exit_message}'"
222
+ return ExitStatus.new(exit_message, exit_code)
213
223
  end
214
224
 
215
225
  if hi && value > hi
216
- Log.warn "#{metric}: read value #{value} is above normal range maximum #{hi}; exit code #{exit_code}"
217
- return exit_code
226
+ Log.warn "#{metric}: read value #{value} is above normal range maximum #{hi}; exit code #{exit_code}; exit message '#{exit_message}'"
227
+ return ExitStatus.new(exit_message, exit_code)
218
228
  end
219
229
 
220
230
  Log.debug "#{host_instance.url} | within normal range"
221
231
  end
222
232
 
223
- false
233
+ nil
224
234
  end
225
235
  end
226
236
  end
@@ -1,3 +1,3 @@
1
1
  module OstrichPoll
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ostrichpoll
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-08-12 00:00:00.000000000Z
12
+ date: 2012-09-11 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: json
16
- requirement: &70343268535920 !ruby/object:Gem::Requirement
16
+ requirement: &70231070956020 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70343268535920
24
+ version_requirements: *70231070956020
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: trollop
27
- requirement: &70343268534280 !ruby/object:Gem::Requirement
27
+ requirement: &70231070955200 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70343268534280
35
+ version_requirements: *70231070955200
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rspec
38
- requirement: &70343268530060 !ruby/object:Gem::Requirement
38
+ requirement: &70231070948140 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,7 +43,7 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70343268530060
46
+ version_requirements: *70231070948140
47
47
  description: Ostrichpoll is a tiny utility for monitoring Twitter Ostrich services.
48
48
  Effectively it can monitor any service which exposes internal metrics in JSON over
49
49
  HTTP.
@@ -63,7 +63,7 @@ files:
63
63
  - bin/ostrichpoll
64
64
  - lib/ostrichpoll.rb
65
65
  - lib/ostrichpoll/config_parser.rb
66
- - lib/ostrichpoll/exit_codes.rb
66
+ - lib/ostrichpoll/exit_status.rb
67
67
  - lib/ostrichpoll/ostrich_validator.rb
68
68
  - lib/ostrichpoll/string.rb
69
69
  - lib/ostrichpoll/version.rb
@@ -1,8 +0,0 @@
1
- module OstrichPoll
2
- # generics
3
- EXIT_OK = 0
4
- EXIT_ERROR = -1
5
-
6
- # could not connect to http endpoint
7
- EXIT_NOHTTP = 1
8
- end