sensu-plugins-outlyer 0.6.0 → 0.7.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a52cd273a16bb979d729d59b18b362fea57a28e2735b66b3a4b85cf210d8d4da
4
- data.tar.gz: 57bbeafe4ee42dd5cdd9eebb8ce32382e10270b10cb8d048f3d967159d3851dd
3
+ metadata.gz: 9a52863d6578923ee7abae3281e4bed498e6bae4c6ec66ebbffdfc8632f98bc4
4
+ data.tar.gz: 81c623f83b9e79fbf4af84dfdc8a13b33c27fd604a89b1643184bf0bed1bc05e
5
5
  SHA512:
6
- metadata.gz: 9bcb06a1122343f198587265b870a38c1518a1cb52590f59c8f577fd97bfdd65fed132616e5ea8535d9f9086e4ab10add59e90ac4972e77d38092f138ee851da
7
- data.tar.gz: d7ff052d31f96d246b5ba5d09f03df74797c30c76172176939a740abc5b4cf30f61eef459bff0e8ae32d479096fe600df6505fbf009ece055f7f829e6b8097de
6
+ metadata.gz: 18aa3e82c81931a8336a2b1f609770e9abbd166fa0f0a8434b063faafab5f6182e00a63718ebebf8b71f194596bca9fada9266302b2572a66899d9c0d4f84af3
7
+ data.tar.gz: b602dcb494dcae20291440d5bea058c298231b78d37e2bb95ebc03eba3fe04169cf6c905d15b555100c1f72786b5d0379da2aea2e99f505dffdbafcb33b5d0e7
data/CHANGELOG.md CHANGED
@@ -3,7 +3,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
3
3
 
4
4
  This CHANGELOG follows the format listed at [Keep A Changelog](http://keepachangelog.com/)
5
5
 
6
- ## [0.6.0] - 2018-07-16
6
+ ## [0.7.0] - 2018-07-16
7
7
  - Made debug flag boolean
8
8
  - Added additional debug logging for troubleshooting
9
9
  - Added Unit Tests
@@ -71,11 +71,9 @@ class OutlyerMetrics < Sensu::Handler
71
71
  def handle
72
72
 
73
73
  output = @event['check']['output']
74
- check_status = @event['check']['status'].to_f
75
74
  @check_name = @event['check']['name']
76
75
  @host = @event['client']['name'].strip.to_s
77
76
  @environment = @event['client']['environment']
78
- timestamp = @event['check']['executed'].to_i * 1000
79
77
 
80
78
  if config[:debug]
81
79
  puts "Handling check #{@check_name} for host #{@host} in environment #{@environment}"
@@ -88,31 +86,9 @@ class OutlyerMetrics < Sensu::Handler
88
86
  parse_graphite_output(output)
89
87
  end
90
88
 
91
- # Add a service status metric
92
- metrics.push(create_datapoint('service.status', check_status, timestamp, {service: "sensu.#{sanitize_value(@check_name)}"}))
93
89
  # Post metrics to Outlyer
94
90
  push_metrics(metrics)
95
91
  end
96
-
97
- # Create a single data point
98
- #
99
- # @param name [String] metric name
100
- # @param value [Float] metric value
101
- # @param time [Integer] epoch timestamp of metric in milliseconds
102
- # @param labels [HashMap] (Optional) Additional labels to append to data point
103
- # @param metric_host [String] (Optional) Set a host for the metric
104
- #
105
- def create_datapoint(name, value, time, labels = {}, metric_host=@host)
106
- datapoint = {
107
- host: metric_host,
108
- labels: labels,
109
- name: name,
110
- timestamp: time,
111
- type: 'gauge',
112
- value: value
113
- }
114
- datapoint
115
- end
116
92
 
117
93
  # Parse the Nagios output format:
118
94
  # <message> | <metric path 1>=<metric value 1>, <metric path 2>=<metric value 2>...
@@ -141,6 +117,7 @@ class OutlyerMetrics < Sensu::Handler
141
117
  puts "The Nagios metric '#{metric}' could not be parsed: #{error.message}"
142
118
  end
143
119
  end
120
+ data.push(create_status_metric(@event['check']['status'].to_f))
144
121
  data
145
122
  end
146
123
 
@@ -161,15 +138,15 @@ class OutlyerMetrics < Sensu::Handler
161
138
  end
162
139
 
163
140
  # Parse the metric on each line in graphite format
141
+ metric_host = @host
164
142
  output.split("\n").each do |metric|
165
143
  m = metric.split
166
144
  next unless m.count == 3
167
145
  labels = {service: "sensu.#{sanitize_value(@check_name)}"}
168
- metric_host = @host
169
146
 
170
147
  # Check to see if we have a scheme filter that matches the metric name
171
- template = nil
172
148
  if schemes
149
+ template = nil
173
150
  schemes.each do |scheme|
174
151
  filter = Regexp.new("^#{Regexp.escape(scheme['filter']).gsub('\*','[^\.]*?')}$")
175
152
  if m[0] =~ filter
@@ -215,8 +192,8 @@ class OutlyerMetrics < Sensu::Handler
215
192
  puts "No scheme was found that matches the metric '#{m[0]}.'"
216
193
  puts "Please configure a scheme for the check '#{@check_name}' "\
217
194
  "on the Sensu client '#{@host}'."
218
- exit(2)
219
- metric_name = sanitize_value(m[0])
195
+ data.push(create_status_metric(3))
196
+ return data
220
197
  end
221
198
  else
222
199
  metric_name = sanitize_value(m[0])
@@ -227,9 +204,30 @@ class OutlyerMetrics < Sensu::Handler
227
204
  point = create_datapoint(metric_name, value, time, labels, metric_host)
228
205
  data.push(point)
229
206
  end
207
+ if config[:debug]
208
+ puts "Parsed #{data.length} of #{output.split("\n").length} metrics"
209
+ end
210
+ data.push(create_status_metric(@event['check']['status'].to_f, metric_host))
230
211
  data
231
212
  end
232
213
 
214
+ # Create the status metric for the check with status:
215
+ #
216
+ # 0 - OK
217
+ # 1 - WARN
218
+ # 2 - CRITICAL
219
+ # 3 - UNKNOWN
220
+ #
221
+ # Unknown is used to tell Outlyer there was a parsing error for the check
222
+ #
223
+ # @param check_status [Integer] Check status code
224
+ # @param host [String] (Optional) hostname of host that ran the check
225
+ # @param timestamp [Integer] (Optional) timestamp of when host ran the check
226
+ #
227
+ def create_status_metric(check_status, host=@host, timestamp=@event['check']['executed'].to_i * 1000)
228
+ return create_datapoint('service.status', check_status, timestamp, {service: "sensu.#{sanitize_value(@check_name)}"}, host)
229
+ end
230
+
233
231
  # Ensures all label values conform to Outlyer's data format requirements:
234
232
  #
235
233
  # * values can only contain the characters `-._A-Za-z0-9`, other characters
@@ -250,6 +248,26 @@ class OutlyerMetrics < Sensu::Handler
250
248
  end
251
249
  value
252
250
  end
251
+
252
+ # Create a single data point
253
+ #
254
+ # @param name [String] metric name
255
+ # @param value [Float] metric value
256
+ # @param time [Integer] epoch timestamp of metric in milliseconds
257
+ # @param labels [HashMap] (Optional) Additional labels to append to data point
258
+ # @param metric_host [String] (Optional) Set a host for the metric
259
+ #
260
+ def create_datapoint(name, value, time, labels = {}, metric_host=@host)
261
+ datapoint = {
262
+ host: metric_host,
263
+ labels: labels,
264
+ name: name,
265
+ timestamp: time,
266
+ type: 'gauge',
267
+ value: value
268
+ }
269
+ datapoint
270
+ end
253
271
 
254
272
  # Post check metrics to Outlyer's Series API:
255
273
  #
@@ -1,7 +1,7 @@
1
1
  module SensuPluginsOutlyer
2
2
  module Version
3
3
  MAJOR = 0
4
- MINOR = 6
4
+ MINOR = 7
5
5
  PATCH = 0
6
6
 
7
7
  VER_STRING = [MAJOR, MINOR, PATCH].compact.join('.')
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sensu-plugins-outlyer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dataloop Software, INC. Trading as Outlyer
@@ -175,7 +175,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
175
175
  version: '0'
176
176
  requirements: []
177
177
  rubyforge_project:
178
- rubygems_version: 2.7.4
178
+ rubygems_version: 2.7.6
179
179
  signing_key:
180
180
  specification_version: 4
181
181
  summary: Sensu plugins for Outlyer