sensu-plugins-green-dragon 0.1.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 256f553f62100cd581bc0bf576aac8ad74297c64
4
+ data.tar.gz: 710b481798c0dd7cef2f851ca89e15c095fa4098
5
+ SHA512:
6
+ metadata.gz: e7c5e8ad0b1c3e337dca0793345755ab3530fa29b060496b89c2e3b2427d4a2d17ec05e0dc71c28265874593bef1ae0e4401862247404d78ac2b6527383434ff
7
+ data.tar.gz: 9046fab75141b60e61a87c58c530327eb89ec97685b17f1b4aae592b60d2c8ccbcca051598928c395c7e1e453bff2f83faaee3dd60a40a1928ef89df911b6bb3
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ /vendor/
11
+ /*.gem
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in sensu-plugins-green-dragon.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,35 @@
1
+ # Green::Dragon::Plugins
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/green/dragon/plugins`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'green-dragon-plugins'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install green-dragon-plugins
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/green-dragon-plugins.
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
data/bin/my-check.rb ADDED
@@ -0,0 +1,229 @@
1
+ #! /usr/bin/env ruby
2
+ #
3
+ # check-influxdb-query
4
+ #
5
+ # DESCRIPTION:
6
+ # Check InfluxDB queries
7
+ #
8
+ # OUTPUT:
9
+ # plain text
10
+ #
11
+ # PLATFORMS:
12
+ # Linux
13
+ #
14
+ # DEPENDENCIES:
15
+ # gem: sensu-plugin
16
+ # gem: jsonpath
17
+ # gem: json
18
+ # gem: dentaku
19
+ #
20
+ # USAGE:
21
+ # example commands
22
+ #
23
+ # NOTES:
24
+ # See the README here https://github.com/zeroXten/check_influxdb_query
25
+ #
26
+ # LICENSE:
27
+ # Copyright 2014, Fraser Scott <fraser.scott@gmail.com>
28
+ # Released under the same terms as Sensu (the MIT license); see LICENSE
29
+ # for details.
30
+ #
31
+
32
+ require 'influxdb'
33
+ require 'sensu-plugin/check/cli'
34
+ require 'json'
35
+ require 'jsonpath'
36
+ require 'dentaku'
37
+
38
+ # VERSION = '0.1.0'
39
+
40
+ #
41
+ # Check Influxdb Query
42
+ #
43
+ class CheckInfluxdbQuery < Sensu::Plugin::Check::CLI
44
+ check_name nil
45
+ option :host,
46
+ short: '-H HOST',
47
+ long: '--host HOST',
48
+ default: 'localhost',
49
+ description: 'InfluxDB host'
50
+
51
+ option :port,
52
+ short: '-P PORT',
53
+ long: '--port PORT',
54
+ default: '8086',
55
+ description: 'InfluxDB port'
56
+
57
+ option :use_ssl,
58
+ description: 'Turn on/off SSL (default: false)',
59
+ short: '-s',
60
+ long: '--use_ssl',
61
+ boolean: true,
62
+ default: false
63
+
64
+ option :verify_ssl,
65
+ description: 'Turn on/off using SSL certificate (default: false)',
66
+ short: '-v',
67
+ long: '--verify_ssl',
68
+ boolean: true,
69
+ default: false
70
+
71
+ option :ssl_ca_cert,
72
+ description: 'Path to the ssl ca certificate to connect to the InfluxDB server',
73
+ short: '-C CA_CERT',
74
+ long: '--ssl_ca_cert CA_CERT'
75
+
76
+ option :database,
77
+ short: '-d DATABASE',
78
+ long: '--database DATABASE',
79
+ default: 'influxdb',
80
+ description: 'InfluxDB database name'
81
+
82
+ option :retry,
83
+ short: '-r RETRY',
84
+ long: '--retry RETRY',
85
+ description: 'InfluxDB retry count with exponential back-off',
86
+ proc: proc(&:to_i),
87
+ default: 12
88
+
89
+ option :username,
90
+ short: '-u USERNAME',
91
+ long: '--username USERNAME',
92
+ default: 'root',
93
+ description: 'API username'
94
+
95
+ option :password,
96
+ short: '-p PASSWORD',
97
+ long: '--password PASSWORD',
98
+ default: 'root',
99
+ description: 'API password'
100
+
101
+ option :query,
102
+ short: '-q QUERY',
103
+ long: '--query QUERY',
104
+ required: true,
105
+ description: 'Query to run. See https://influxdb.com/docs/v0.9/query_language/query_syntax.html'
106
+
107
+ option :alias,
108
+ short: '-a ALIAS',
109
+ long: '--alias ALIAS',
110
+ default: nil,
111
+ description: 'Alias of query (e.g. if query and output gets too long)'
112
+
113
+ option :mode,
114
+ short: '-m MODE',
115
+ long: '--mode MODE',
116
+ default: 'first',
117
+ description: 'How the results are being checked (one of "first", "last", "max", "min", "avg") when the query returns more than one value'
118
+
119
+ option :jsonpath,
120
+ short: '-j JSONPATH',
121
+ long: '--jsonpath JSONPATH',
122
+ default: nil,
123
+ description: 'Json path to select value. Takes the first value, or 0 if none. See http://goessner.net/articles/JsonPath/'
124
+
125
+ option :noresult,
126
+ short: '-n',
127
+ long: '--noresult',
128
+ boolean: true,
129
+ description: 'Go critical for no result from query'
130
+
131
+ option :warning,
132
+ short: '-w WARNING',
133
+ long: '--warning WARNING',
134
+ default: nil,
135
+ description: "Warning threshold expression. E.g. 'value >= 10'. See https://github.com/rubysolo/dentaku"
136
+
137
+ option :critical,
138
+ short: '-c CRITICAL',
139
+ long: '--critical CRITICAL',
140
+ default: nil,
141
+ description: "Critical threshold expression. E.g. 'value >= 20'. See https://github.com/rubysolo/dentaku"
142
+
143
+ option :help,
144
+ short: '-h',
145
+ long: '--help',
146
+ description: 'Show this message',
147
+ on: :tail,
148
+ boolean: true,
149
+ show_options: true,
150
+ exit: 0
151
+
152
+ # option :version,
153
+ # short: '-v',
154
+ # long: '--version',
155
+ # description: 'Show version',
156
+ # on: :tail,
157
+ # boolean: true,
158
+ # proc: proc { puts "Version #{VERSION}" },
159
+ # exit: 0
160
+
161
+ def run
162
+ influxdb = InfluxDB::Client.new config[:database],
163
+ host: config[:host],
164
+ port: config[:port],
165
+ use_ssl: config[:use_ssl],
166
+ verify_ssl: config[:verify_ssl],
167
+ ssl_ca_cert: config[:ssl_ca_cert],
168
+ retry: config[:retry],
169
+ username: config[:username],
170
+ password: config[:password]
171
+
172
+ value = influxdb.query config[:query]
173
+
174
+ query_name = if config[:alias]
175
+ config[:alias]
176
+ else
177
+ config[:query]
178
+ end
179
+
180
+ if config[:noresult] && value.empty?
181
+ critical "No result for query '#{query_name}'"
182
+ elsif config[:noresult] && !config[:jsonpath] && !value.empty?
183
+ ok "Value returned for query '#{query_name}'"
184
+ end
185
+
186
+ if config[:jsonpath]
187
+ json_path = JsonPath.new(config[:jsonpath])
188
+ calc = Dentaku::Calculator.new
189
+ if config[:mode] == 'any' && json_path.on(value).length >= 1
190
+ json_path.on(value).each do |hashval|
191
+ if config[:critical] && calc.evaluate(config[:critical], value: hashval)
192
+ critical "Value '#{value}' matched '#{config[:critical]}' for query '#{query_name}'"
193
+ elsif config[:warning] && calc.evaluate(config[:warning], value: hashval)
194
+ warning "Value '#{value}' matched '#{config[:warning]}' for query '#{query_name}'"
195
+ end
196
+ end
197
+ ok 'All values OK!'
198
+ else
199
+ value = get_single_value(json_path, value)
200
+ if config[:critical] && calc.evaluate(config[:critical], value: value)
201
+ critical "Value '#{value}' matched '#{config[:critical]}' for query '#{query_name}'"
202
+ elsif config[:warning] && calc.evaluate(config[:warning], value: value)
203
+ warning "Value '#{value}' matched '#{config[:warning]}' for query '#{query_name}'"
204
+ else
205
+ ok "Value '#{value}' ok for query '#{query_name}'"
206
+ end
207
+ end
208
+ else
209
+ puts 'Debug output. Use -j to check value...'
210
+ puts JSON.pretty_generate(value)
211
+ end
212
+ end
213
+
214
+ def get_single_value(jpath, value)
215
+ return 0 if jpath.on(value).empty?
216
+ case config[:mode]
217
+ when 'last'
218
+ jpath.on(value).last
219
+ when 'min'
220
+ jpath.on(value).min
221
+ when 'max'
222
+ jpath.on(value).max
223
+ when 'avg', 'average'
224
+ jpath.on(value).inject(:+).to_f / jpath.on(value).length
225
+ else
226
+ jpath.on(value).first
227
+ end
228
+ end
229
+ end
@@ -0,0 +1,3 @@
1
+ module GreenDragonPlugins
2
+ VERSION = "0.1.1"
3
+ end
data/lib/plugins.rb ADDED
@@ -0,0 +1,4 @@
1
+ require "green-dragon-plugins/version"
2
+
3
+ module GreenDragonPlugins
4
+ end
@@ -0,0 +1,27 @@
1
+ lib = File.expand_path("../lib", __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+
4
+ require "green-dragon-plugins/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "sensu-plugins-green-dragon"
8
+ spec.version = GreenDragonPlugins::VERSION
9
+ spec.authors = ["Grzegorz Ziemonski"]
10
+ spec.email = ["grzegorz.ziemonski@zooplus.com"]
11
+
12
+ spec.summary = 'Custom Sensu plugins used by the Green Dragons'
13
+
14
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
15
+ f.match(%r{^(test|spec|features)/})
16
+ end
17
+ spec.executables = Dir.glob('bin/**/*').map {|file| File.basename(file)}
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_runtime_dependency "sensu-plugin", "~> 2.1"
21
+ spec.add_runtime_dependency 'dentaku', '2.0.9'
22
+ spec.add_runtime_dependency 'influxdb', '0.3.13'
23
+ spec.add_runtime_dependency 'jsonpath', '0.5.8'
24
+
25
+ spec.add_development_dependency "bundler", "~> 1.15"
26
+ spec.add_development_dependency "rake", "~> 10.0"
27
+ end
metadata ADDED
@@ -0,0 +1,136 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sensu-plugins-green-dragon
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Grzegorz Ziemonski
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-08-17 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: sensu-plugin
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: dentaku
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '='
32
+ - !ruby/object:Gem::Version
33
+ version: 2.0.9
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '='
39
+ - !ruby/object:Gem::Version
40
+ version: 2.0.9
41
+ - !ruby/object:Gem::Dependency
42
+ name: influxdb
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '='
46
+ - !ruby/object:Gem::Version
47
+ version: 0.3.13
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '='
53
+ - !ruby/object:Gem::Version
54
+ version: 0.3.13
55
+ - !ruby/object:Gem::Dependency
56
+ name: jsonpath
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '='
60
+ - !ruby/object:Gem::Version
61
+ version: 0.5.8
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '='
67
+ - !ruby/object:Gem::Version
68
+ version: 0.5.8
69
+ - !ruby/object:Gem::Dependency
70
+ name: bundler
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.15'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.15'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rake
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '10.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '10.0'
97
+ description:
98
+ email:
99
+ - grzegorz.ziemonski@zooplus.com
100
+ executables:
101
+ - my-check.rb
102
+ extensions: []
103
+ extra_rdoc_files: []
104
+ files:
105
+ - ".gitignore"
106
+ - Gemfile
107
+ - README.md
108
+ - Rakefile
109
+ - bin/my-check.rb
110
+ - lib/green-dragon-plugins/version.rb
111
+ - lib/plugins.rb
112
+ - sensu-plugins-green-dragon.gemspec
113
+ homepage:
114
+ licenses: []
115
+ metadata: {}
116
+ post_install_message:
117
+ rdoc_options: []
118
+ require_paths:
119
+ - lib
120
+ required_ruby_version: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ required_rubygems_version: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - ">="
128
+ - !ruby/object:Gem::Version
129
+ version: '0'
130
+ requirements: []
131
+ rubyforge_project:
132
+ rubygems_version: 2.6.12
133
+ signing_key:
134
+ specification_version: 4
135
+ summary: Custom Sensu plugins used by the Green Dragons
136
+ test_files: []