sensu-plugins-http-boutetnico 1.1.0 → 1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5f6360dc0aca83dde1940b01531dd6c5f03a35b3
4
- data.tar.gz: d510ec56b7512341206e734ab97a01d079ebaa32
3
+ metadata.gz: 614d08b1f3e1c9b2d460ea354358ef70e2f64ae8
4
+ data.tar.gz: 2f362017637e487505175c01b059b8762c09e13e
5
5
  SHA512:
6
- metadata.gz: 68623e4e6a7a6528cd21b7650d1a69cc81331325d5f8a8afb88fd5a9e6f7f112f1a17abe8bf3be0fa55f27327844510fc84052c1930b16c83e4325c662c147ae
7
- data.tar.gz: 76fe6e697ff95b89c2187d5f81a5c7186e9846145a26c36bb6466b9b277afee11af4bbc6a86fc34310e21b9c371142374ba9ee42e29b24f5916ed61c068de656
6
+ metadata.gz: 0ebcb58029ff428cd41bc33047f967682a8f4589ad01862e9b0a187187aa821f649a253c127f296bd988b45c0f1885674a19c8da84206edc028b22247b91de89
7
+ data.tar.gz: 46138a93ec92ded1c134e48519ebcd3cc3879e4e1bd9b4b066d9e251da58fcd16cf5a4c7c4b9b680aca3982993c3fc53b8ed25d6d9b3a9c597b12e03db8a752b
@@ -1,6 +1,5 @@
1
1
  #! /usr/bin/env ruby
2
- # frozen_string_literal: false
3
-
2
+ #
4
3
  # metrics-http-json.rb
5
4
  #
6
5
  # DESCRIPTION:
@@ -17,7 +16,9 @@
17
16
  # gem: rest-client
18
17
  #
19
18
  # USAGE:
20
- # EX: ./metrics-http-json.rb -u 'http://127.0.0.1:8080/jolokia/read/com\
19
+ # ./metrics-http-json.rb -u 'https://user:password@127.0.0.1:443
20
+ #
21
+ # ./metrics-http-json.rb -u 'http://127.0.0.1:8080/jolokia/read/com\
21
22
  # .mchange.v2.c3p0:name=datasource,type=PooledDataSource' -s hostname.c3p0\
22
23
  # -m 'Connections::numConnections,BusyConnections::numBusyConnections'\
23
24
  # -o 'value'
@@ -56,9 +57,10 @@ class HttpJsonGraphite < Sensu::Plugin::Metric::CLI::Graphite
56
57
  default: Socket.gethostname.to_s
57
58
 
58
59
  option :metric,
59
- description: 'Metric/JSON key pair ex:Connections::numConnections',
60
+ description: 'Optional Metric/JSON key pair ex:Connections::numConnections',
60
61
  short: '-m METRIC::JSONKEY',
61
- long: '--metric METRIC::JSONKEY'
62
+ long: '--metric METRIC::JSONKEY',
63
+ default: nil
62
64
 
63
65
  option :headers,
64
66
  description: 'Additional HTTP request headers to send. Example: Authorization:XYZ,User-Agent:ABC',
@@ -82,6 +84,16 @@ class HttpJsonGraphite < Sensu::Plugin::Metric::CLI::Graphite
82
84
  long: '--debug',
83
85
  default: false
84
86
 
87
+ def deep_value(hash, scheme = '')
88
+ hash.each do |key, value|
89
+ if value.is_a?(Hash)
90
+ deep_value(value, "#{scheme}.#{key}")
91
+ else
92
+ output "#{scheme}.#{key}", value
93
+ end
94
+ end
95
+ end
96
+
85
97
  def run
86
98
  puts "args config: #{config}" if config[:debug]
87
99
 
@@ -110,22 +122,27 @@ class HttpJsonGraphite < Sensu::Plugin::Metric::CLI::Graphite
110
122
  )
111
123
 
112
124
  puts "Http response: #{r}" if config[:debug]
113
- metric_pair_array = metric_pair_input.split(/,/)
114
- metric_pair_array.each do |m|
115
- metric, attribute = m.to_s.split(/::/)
116
- puts "metric: #{metric}, attribute: #{attribute}" if config[:debug]
117
- unless object.nil?
118
- ::JSON.parse(r)[object].each do |k, v|
125
+
126
+ if config[:metric].nil?
127
+ deep_value(::JSON.parse(r), scheme)
128
+ else
129
+ metric_pair_array = metric_pair_input.split(/,/)
130
+ metric_pair_array.each do |m|
131
+ metric, attribute = m.to_s.split(/::/)
132
+ puts "metric: #{metric}, attribute: #{attribute}" if config[:debug]
133
+ unless object.nil?
134
+ ::JSON.parse(r)[object].each do |k, v|
135
+ if k == attribute
136
+ output([scheme, metric].join('.'), v)
137
+ end
138
+ end
139
+ end
140
+ ::JSON.parse(r).each do |k, v|
119
141
  if k == attribute
120
142
  output([scheme, metric].join('.'), v)
121
143
  end
122
144
  end
123
145
  end
124
- ::JSON.parse(r).each do |k, v|
125
- if k == attribute
126
- output([scheme, metric].join('.'), v)
127
- end
128
- end
129
146
  end
130
147
  rescue Errno::ECONNREFUSED
131
148
  critical "#{config[:url]} is not responding"
@@ -3,7 +3,7 @@
3
3
  module SensuPluginsHttp
4
4
  module Version
5
5
  MAJOR = 1
6
- MINOR = 1
6
+ MINOR = 2
7
7
  PATCH = 0
8
8
 
9
9
  VER_STRING = [MAJOR, MINOR, PATCH].compact.join('.')
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sensu-plugins-http-boutetnico
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sensu-Plugins and contributors