sensu-plugins-outlyer 0.4.0 → 0.5.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
- SHA1:
3
- metadata.gz: 06fefcec9b4ad9d5c308b13f85f547b0bd4b8b53
4
- data.tar.gz: e2b9db23d1252b2eeb1874eb3fd13a5c5290af91
2
+ SHA256:
3
+ metadata.gz: 46c1c2455d4122918ce986502ba90d6305f5d36edd67d4d98168183d596947f6
4
+ data.tar.gz: d7bdb065ab7a39cc84cc5b565450aa3df401bcce8cda35cf8a158b6c76a8de0c
5
5
  SHA512:
6
- metadata.gz: 2219ff7def5ba400bac2ed178d395ce94d786b95b3dc2102a5a86f5ae7c4c440fc0bfa7476ae663597425cea75f46ddd0d852b3c46804fa13555f8063be44da4
7
- data.tar.gz: 680a766582636eaf7b826bc8b7eccee35967b66c99ac98804cd9da1a5d039d6c247c740d67eb29e50cd7956a52419a4a75095fbefb9d31ac6f77bce001917113
6
+ metadata.gz: a61588c67195ff17deedc7a6d8c2c67696c76e68f867984fd4518bfbfe26729cc903b66883d198578b3dbc7012b060c0e56d532e7e3be19ee77b9cbba6f60a5a
7
+ data.tar.gz: b1b4f5348d643858473e4e9ad11fa21aa25aaf9d8b0a0706e34b316c403ebfe75b34976ab60b852707ba1fc32ff93abfc11a501534f8c12864cc2feb2b90333b
data/CHANGELOG.md CHANGED
@@ -3,6 +3,11 @@ 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.5.0] - 2018-07-16
7
+ - Made debug flag boolean
8
+ - Added additional debug logging for troubleshooting
9
+ - Added Unit Tests
10
+
6
11
  ## [0.4.0] - 2018-07-13
7
12
  - Added handling for client environments set as array of values
8
13
  - Added schemas so graphite metric names can be parsed into dimensional metrics
data/README.md CHANGED
@@ -27,21 +27,14 @@ handler configuration file with your API details as an environment variable:
27
27
  export SENSU_CONFIG_FILES='/Users/dgildeh/Development/Outlyer/sensu-config.json'
28
28
  ```
29
29
 
30
- Then you can use the following command to test the handler with example Nagios
31
- output data using the following command:
30
+ Ensure your handler has execution permissions set:
32
31
 
33
32
  ```bash
34
- cat ./test/test-nagios-data.json | ruby ./bin/outlyer-metrics.rb -f nagios
33
+ chmod +x ./bin/outlyer-metrics.rb
35
34
  ```
36
- For Graphite metric test:
35
+
36
+ The run the unit tests:
37
37
 
38
38
  ```bash
39
- cat ./test/test-graphite-data.json | ruby ./bin/outlyer-metrics.rb
39
+ ruby test/test_outlyer_handler.rb
40
40
  ```
41
-
42
- Note you will have to override the check timestamp to the current time so your
43
- metrics will appear in Outlyer using the test above:
44
-
45
- ```ruby
46
- timestamp = Time.now.to_i * 1000
47
- ```
@@ -22,6 +22,7 @@
22
22
  #
23
23
  # -f: set the Handler's check output format to parse. Can either be `graphite` (default) or `nagios`.
24
24
  # -t: Set the timeout in seconds for the Outlyer API requests
25
+ # -d: Enable debugging to see additional logging in Output
25
26
  #
26
27
  # NOTES:
27
28
  #
@@ -53,10 +54,11 @@ class OutlyerMetrics < Sensu::Handler
53
54
  default: '5'
54
55
 
55
56
  option :debug,
56
- description: 'Enable debug for more verbose output',
57
- short: '-d DEBUG',
58
- long: '--debug DEBUG',
59
- default: 'false'
57
+ description: 'Enable debug for more verbose output',
58
+ boolean: true,
59
+ short: '-d',
60
+ long: '--debug',
61
+ default: false
60
62
 
61
63
  # Override filters from Sensu::Handler.
62
64
  # They are not appropriate for metric handlers
@@ -67,12 +69,7 @@ class OutlyerMetrics < Sensu::Handler
67
69
  # Create a handle and event set
68
70
  #
69
71
  def handle
70
-
71
- @debug = false
72
- if config[:debug] == 'true'
73
- @debug = true
74
- end
75
-
72
+
76
73
  output = @event['check']['output']
77
74
  check_status = @event['check']['status'].to_f
78
75
  @check_name = @event['check']['name']
@@ -84,6 +81,10 @@ class OutlyerMetrics < Sensu::Handler
84
81
  end
85
82
  timestamp = @event['check']['executed'].to_i * 1000
86
83
 
84
+ if config[:debug]
85
+ puts "Handling check #{@check_name} for host #{@host} in environment #{@environment}"
86
+ end
87
+
87
88
  # Parse output for metric data
88
89
  metrics = if config[:output_format] == 'nagios' then
89
90
  parse_nagios_output(output, timestamp)
@@ -183,8 +184,12 @@ class OutlyerMetrics < Sensu::Handler
183
184
  # Get dimensions from metric name
184
185
  schema_parts = scheme['scheme'].split('.')
185
186
  if (metric_parts.length - scheme['metric_name_length'].to_i) != schema_parts.length
186
- puts "Schema Parsing Error: metric parts (#{metric_parts.length - scheme['metric_name_length'].to_i}) is not same length as schema (#{schema_parts.length})"
187
- puts "Example metric: m[0]"
187
+ puts "Scheme Parsing Error: metric parts (#{metric_parts.length - scheme['metric_name_length'].to_i}) is not same length as schema (#{schema_parts.length})"
188
+ puts "Scheme: #{scheme['scheme']}"
189
+ puts "Example metric: #{m[0]}"
190
+ if config[:debug]
191
+ puts "Event Data: \n#{JSON.pretty_generate(@event)}"
192
+ end
188
193
  return []
189
194
  end
190
195
  schema_parts.each_with_index do |val,index|
@@ -196,7 +201,7 @@ class OutlyerMetrics < Sensu::Handler
196
201
  metric_name = sanitize_value(metric_parts.join('.'))
197
202
  end
198
203
  value = m[1].to_f
199
- time = Time.now.to_i * 1000
204
+ time = m[2].to_i * 1000
200
205
  point = create_datapoint(metric_name, value, time, labels)
201
206
  data.push(point)
202
207
  end
@@ -242,9 +247,9 @@ class OutlyerMetrics < Sensu::Handler
242
247
  request.add_field("Authorization", "Bearer #{settings['outlyer']['api_key']}")
243
248
  request.add_field("accept", "application/json")
244
249
  request.add_field("Content-Type", "application/json")
245
- request.body = {samples: datapoints}.to_json
250
+ request.body = JSON.pretty_generate({samples: datapoints})
246
251
 
247
- if @debug
252
+ if config[:debug]
248
253
  puts "DEBUG: Outlyer API Payload: #{request.body}"
249
254
  end
250
255
 
@@ -262,8 +267,13 @@ class OutlyerMetrics < Sensu::Handler
262
267
  #
263
268
  rescue Timeout::Error
264
269
  puts 'Outlyer API Error -- timed out while sending metrics'
270
+ exit(2)
265
271
  rescue => error
266
272
  puts "Outlyer API Error -- failed to send metrics: #{error.message}"
267
273
  puts " #{error.backtrace.join("\n\t")}"
274
+ if config[:debug]
275
+ puts "Event Data: \n#{JSON.pretty_generate(@event)}"
276
+ end
277
+ exit(2)
268
278
  end
269
279
  end
@@ -1,7 +1,7 @@
1
1
  module SensuPluginsOutlyer
2
2
  module Version
3
3
  MAJOR = 0
4
- MINOR = 4
4
+ MINOR = 5
5
5
  PATCH = 0
6
6
 
7
7
  VER_STRING = [MAJOR, MINOR, PATCH].compact.join('.')
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sensu-plugins-outlyer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dataloop Software, INC. Trading as Outlyer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-07-15 00:00:00.000000000 Z
11
+ date: 2018-07-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sensu-plugin
@@ -38,20 +38,6 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '1.7'
41
- - !ruby/object:Gem::Dependency
42
- name: codeclimate-test-reporter
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - "~>"
46
- - !ruby/object:Gem::Version
47
- version: '0.4'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - "~>"
53
- - !ruby/object:Gem::Version
54
- version: '0.4'
55
41
  - !ruby/object:Gem::Dependency
56
42
  name: github-markup
57
43
  requirement: !ruby/object:Gem::Requirement
@@ -189,7 +175,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
189
175
  version: '0'
190
176
  requirements: []
191
177
  rubyforge_project:
192
- rubygems_version: 2.5.2
178
+ rubygems_version: 2.7.4
193
179
  signing_key:
194
180
  specification_version: 4
195
181
  summary: Sensu plugins for Outlyer