portertech-sensu-extensions 1.12.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: '097e4f73c1cc85a6de27331b0331c0ad2f826d42a51bd2c1d1f10850ed48361a'
4
+ data.tar.gz: c6015b1aa38fb3252e6b9adf1fff31b5ff31a07c5aac79a29458aa8a1a60a5c6
5
+ SHA512:
6
+ metadata.gz: a8901e92240c60e1a1f590ad774246653a5d9001bd1ab1f493246fe21fddc76803f5831a7a280f45caca7d9716effc66dbe405a15298a5660dc12f4fea121857
7
+ data.tar.gz: 1c314c095c97380a464032d264931cac8d85d5ce72e824ad07ea0f79d982ce3fd06c686180d5dcc1c39d4aaf1e4779961c120eddf5977d0aec4817ad63dd5769
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2014 Heavy Water Operations, LLC.
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,28 @@
1
+ # Sensu::Extensions
2
+
3
+ [![Build Status](https://travis-ci.org/sensu/sensu-extensions.svg?branch=master)](https://travis-ci.org/sensu/sensu-extensions)
4
+ ![Gem Version](https://img.shields.io/gem/v/sensu-extensions.svg)
5
+ ![MIT Licensed](https://img.shields.io/github/license/sensu/sensu.svg)
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'sensu-extensions'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ ## Usage
18
+
19
+ Documentation can be found [here](http://rubydoc.info/github/sensu/sensu-extensions/Sensu/Extensions).
20
+
21
+ ## Contributing
22
+
23
+ 0. By contributing to this project you agree to abide by the [code of conduct](https://sensuapp.org/conduct).
24
+ 1. [Fork it](https://github.com/sensu/sensu-extensions/fork)
25
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
26
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
27
+ 4. Push to the branch (`git push origin my-new-feature`)
28
+ 5. Create a new Pull Request
@@ -0,0 +1,8 @@
1
+ module Sensu
2
+ module Extensions
3
+ unless defined?(Sensu::Extensions::GEM_PREFIX)
4
+ # Sensu Extension Rubygem prefix.
5
+ GEM_PREFIX = "sensu-extensions-".freeze
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,209 @@
1
+ gem "sensu-extensions-occurrences", "1.2.0"
2
+ gem "sensu-extensions-check-dependencies", "1.1.0"
3
+ gem "sensu-extensions-json", "1.0.0"
4
+ gem "sensu-extensions-ruby-hash", "1.0.0"
5
+ gem "sensu-extensions-only-check-output", "1.0.0"
6
+ gem "sensu-extensions-debug", "1.0.0"
7
+ gem "sensu-extensions-deregistration", "1.0.0"
8
+
9
+ require "sensu/extension"
10
+ require "sensu/extensions/constants"
11
+ require "sensu/extensions/occurrences"
12
+ require "sensu/extensions/check-dependencies"
13
+ require "sensu/extensions/json"
14
+ require "sensu/extensions/ruby-hash"
15
+ require "sensu/extensions/only-check-output"
16
+ require "sensu/extensions/debug"
17
+ require "sensu/extensions/deregistration"
18
+
19
+ module Sensu
20
+ module Extensions
21
+ class Loader
22
+ # @!attribute [r] warnings
23
+ # @return [Array] loader warnings.
24
+ attr_reader :warnings
25
+
26
+ # @!attribute [r] loaded_files
27
+ # @return [Array] loaded extension files.
28
+ attr_reader :loaded_files
29
+
30
+ # @!attribute [r] loaded_gems
31
+ # @return [Array] loaded extension gems.
32
+ attr_reader :loaded_gems
33
+
34
+ def initialize
35
+ @warnings = []
36
+ @loaded_files = []
37
+ @loaded_gems = []
38
+ @extensions = {}
39
+ Extension::CATEGORIES.each do |category|
40
+ @extensions[category] = {}
41
+ end
42
+ self.class.create_category_methods
43
+ end
44
+
45
+ # Create extension category accessors and methods to test the
46
+ # existence of extensions. Called in initialize().
47
+ def self.create_category_methods
48
+ Extension::CATEGORIES.each do |category|
49
+ define_method(category) do
50
+ extension_category(category)
51
+ end
52
+ method_name = category.to_s.chop + "_exists?"
53
+ define_method(method_name.to_sym) do |name|
54
+ extension_exists?(category, name)
55
+ end
56
+ end
57
+ end
58
+
59
+ # Retrieve the extension object corresponding to a key, acting
60
+ # like a Hash object.
61
+ #
62
+ # @param key [Symbol]
63
+ # @return [Object] value for key.
64
+ def [](key)
65
+ @extensions[key]
66
+ end
67
+
68
+ # Retrieve all extension instances.
69
+ #
70
+ # @return [Array<object>] extensions.
71
+ def all
72
+ @extensions.map { |category, extensions|
73
+ extensions.map { |name, extension|
74
+ extension
75
+ }.uniq
76
+ }.flatten
77
+ end
78
+
79
+ # Load an extension from a file.
80
+ #
81
+ # @param [String] file path.
82
+ def load_file(file)
83
+ warning("loading extension file", :file => file)
84
+ begin
85
+ require File.expand_path(file)
86
+ @loaded_files << file
87
+ rescue ScriptError, StandardError => error
88
+ warning("failed to require extension", :file => file, :error => error)
89
+ warning("ignoring extension", :file => file)
90
+ end
91
+ end
92
+
93
+ # Load extensions from files in a directory. Files may be in
94
+ # nested directories.
95
+ #
96
+ # @param [String] directory path.
97
+ def load_directory(directory)
98
+ warning("loading extension files from directory", :directory => directory)
99
+ path = directory.gsub(/\\(?=\S)/, "/")
100
+ Dir.glob(File.join(path, "**{,/*/**}/*.rb")).each do |file|
101
+ load_file(file)
102
+ end
103
+ end
104
+
105
+ # Load an extension from a Rubygem.
106
+ #
107
+ # @param [String] gem name.
108
+ def load_gem(raw_gem, version=nil)
109
+ warning("loading extension gem", :gem => raw_gem, :version => version)
110
+ begin
111
+ gem(raw_gem, version) if version
112
+ if raw_gem.start_with?(GEM_PREFIX)
113
+ lib = raw_gem.sub(/^#{GEM_PREFIX}/, "")
114
+ require_path = "sensu/extensions/#{lib}"
115
+ else
116
+ require_path = raw_gem
117
+ end
118
+ warning("requiring extension gem", :require => require_path)
119
+ require require_path
120
+ @loaded_gems << raw_gem
121
+ rescue ScriptError, StandardError => error
122
+ warning("failed to require extension", {
123
+ :gem => raw_gem,
124
+ :version => version,
125
+ :error => error
126
+ })
127
+ warning("ignoring extension", :gem => raw_gem)
128
+ end
129
+ end
130
+
131
+ # Load instances of the loaded extensions.
132
+ #
133
+ # @param [String] sensu service to load extensions for.
134
+ def load_instances(service=nil)
135
+ service ||= sensu_service_name
136
+ categories_to_load(service).each do |category|
137
+ extension_type = category.to_s.chop
138
+ Extension.const_get(extension_type.capitalize).descendants.each do |klass|
139
+ extension = klass.new
140
+ @extensions[category][extension.name] = extension
141
+ if extension.name_alias
142
+ @extensions[category][extension.name_alias] = extension
143
+ end
144
+ warning("loaded extension", {
145
+ :type => extension_type,
146
+ :name => extension.name,
147
+ :description => extension.description
148
+ })
149
+ end
150
+ end
151
+ end
152
+
153
+ private
154
+
155
+ # Retrieve extension category definitions.
156
+ #
157
+ # @param [Symbol] category to retrive.
158
+ # @return [Array<Hash>] category definitions.
159
+ def extension_category(category)
160
+ @extensions[category].map { |name, extension|
161
+ extension.definition
162
+ }.uniq
163
+ end
164
+
165
+ # Check to see if an extension exists in a category.
166
+ #
167
+ # @param [Symbol] category to inspect for the extension.
168
+ # @param [String] name of extension.
169
+ # @return [TrueClass, FalseClass]
170
+ def extension_exists?(category, name)
171
+ @extensions[category].has_key?(name)
172
+ end
173
+
174
+ # Retrieve Sensu service name.
175
+ #
176
+ # @return [String] service name.
177
+ def sensu_service_name
178
+ File.basename($0).split("-").last
179
+ end
180
+
181
+ # Determine which extension categories to load for the given
182
+ # sensu service.
183
+ #
184
+ # @param [String] sensu service to load extensions for.
185
+ # @return [Array] extension categories.
186
+ def categories_to_load(service)
187
+ case service
188
+ when "client"
189
+ [:checks]
190
+ when "server"
191
+ Extension::CATEGORIES.reject { |category| category == :checks }
192
+ else
193
+ Extension::CATEGORIES
194
+ end
195
+ end
196
+
197
+ # Record a warning.
198
+ #
199
+ # @param message [String] warning message.
200
+ # @param data [Hash] warning context.
201
+ # @return [Array] current warnings.
202
+ def warning(message, data={})
203
+ @warnings << {
204
+ :message => message
205
+ }.merge(data)
206
+ end
207
+ end
208
+ end
209
+ end
@@ -0,0 +1,48 @@
1
+ require "sensu/extensions/loader"
2
+
3
+ module Sensu
4
+ module Extensions
5
+ class << self
6
+ # Load Sensu extensions.
7
+ #
8
+ # @param [Hash] options
9
+ # @option options [String] :extension_file to load.
10
+ # @option options [String] :extension_dir to load.
11
+ # @option options [Array] :extension_dirs to load.
12
+ # @option options [Hash] :extensions to load (gems).
13
+ # @return [Loader] a loaded instance of Loader.
14
+ def load(options={})
15
+ @loader = Loader.new
16
+ if options[:extension_file]
17
+ @loader.load_file(options[:extension_file])
18
+ end
19
+ if options[:extension_dir]
20
+ @loader.load_directory(options[:extension_dir])
21
+ end
22
+ if options[:extension_dirs]
23
+ options[:extension_dirs].each do |directory|
24
+ @loader.load_directory(directory)
25
+ end
26
+ end
27
+ if options[:extensions]
28
+ options[:extensions].each do |name, details|
29
+ gem_name = details[:gem] || "#{GEM_PREFIX}#{name}"
30
+ @loader.load_gem(gem_name, details[:version])
31
+ end
32
+ end
33
+ @loader.load_instances
34
+ @loader
35
+ end
36
+
37
+ # Retrieve the current loaded extensions loader or load one up
38
+ # if there isn't one. Note: We may need to add a mutex for
39
+ # thread safety.
40
+ #
41
+ # @param [Hash] options to pass to load().
42
+ # @return [Loader] instance of a loaded loader.
43
+ def get(options={})
44
+ @loader || load(options)
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,35 @@
1
+ # coding: utf-8
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "portertech-sensu-extensions"
5
+ spec.version = "1.12.0"
6
+ spec.authors = ["Sean Porter"]
7
+ spec.email = ["portertech@gmail.com"]
8
+ spec.summary = "The Sensu extension loader library"
9
+ spec.description = "The Sensu extension loader library"
10
+ spec.homepage = "https://github.com/sensu/sensu-extensions"
11
+ spec.license = "MIT"
12
+
13
+ spec.files = Dir.glob("lib/**/*") + %w[sensu-extensions.gemspec README.md LICENSE.txt]
14
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
15
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
16
+ spec.require_paths = ["lib"]
17
+
18
+ spec.add_dependency "portertech-sensu-json", ">= 2.2.1"
19
+ spec.add_dependency "sensu-logger"
20
+ spec.add_dependency "sensu-settings"
21
+ spec.add_dependency "sensu-extension"
22
+ spec.add_dependency "sensu-extensions-occurrences", "1.2.0"
23
+ spec.add_dependency "sensu-extensions-check-dependencies", "1.1.0"
24
+ spec.add_dependency "sensu-extensions-json", "1.0.0"
25
+ spec.add_dependency "sensu-extensions-ruby-hash", "1.0.0"
26
+ spec.add_dependency "sensu-extensions-only-check-output", "1.0.0"
27
+ spec.add_dependency "sensu-extensions-debug", "1.0.0"
28
+ spec.add_dependency "sensu-extensions-deregistration", "1.0.0"
29
+
30
+ spec.add_development_dependency "bundler", "~> 2.4"
31
+ spec.add_development_dependency "rake"
32
+ spec.add_development_dependency "rspec"
33
+ spec.add_development_dependency "sensu-extensions-system-profile", "1.0.0"
34
+ spec.add_development_dependency "bouncy-castle-java" if RUBY_PLATFORM =~ /java/
35
+ end
metadata ADDED
@@ -0,0 +1,259 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: portertech-sensu-extensions
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.12.0
5
+ platform: ruby
6
+ authors:
7
+ - Sean Porter
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2023-10-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: portertech-sensu-json
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 2.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.2.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: sensu-logger
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: sensu-settings
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: sensu-extension
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: sensu-extensions-occurrences
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '='
74
+ - !ruby/object:Gem::Version
75
+ version: 1.2.0
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '='
81
+ - !ruby/object:Gem::Version
82
+ version: 1.2.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: sensu-extensions-check-dependencies
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '='
88
+ - !ruby/object:Gem::Version
89
+ version: 1.1.0
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '='
95
+ - !ruby/object:Gem::Version
96
+ version: 1.1.0
97
+ - !ruby/object:Gem::Dependency
98
+ name: sensu-extensions-json
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '='
102
+ - !ruby/object:Gem::Version
103
+ version: 1.0.0
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '='
109
+ - !ruby/object:Gem::Version
110
+ version: 1.0.0
111
+ - !ruby/object:Gem::Dependency
112
+ name: sensu-extensions-ruby-hash
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - '='
116
+ - !ruby/object:Gem::Version
117
+ version: 1.0.0
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - '='
123
+ - !ruby/object:Gem::Version
124
+ version: 1.0.0
125
+ - !ruby/object:Gem::Dependency
126
+ name: sensu-extensions-only-check-output
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - '='
130
+ - !ruby/object:Gem::Version
131
+ version: 1.0.0
132
+ type: :runtime
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - '='
137
+ - !ruby/object:Gem::Version
138
+ version: 1.0.0
139
+ - !ruby/object:Gem::Dependency
140
+ name: sensu-extensions-debug
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - '='
144
+ - !ruby/object:Gem::Version
145
+ version: 1.0.0
146
+ type: :runtime
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - '='
151
+ - !ruby/object:Gem::Version
152
+ version: 1.0.0
153
+ - !ruby/object:Gem::Dependency
154
+ name: sensu-extensions-deregistration
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - '='
158
+ - !ruby/object:Gem::Version
159
+ version: 1.0.0
160
+ type: :runtime
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - '='
165
+ - !ruby/object:Gem::Version
166
+ version: 1.0.0
167
+ - !ruby/object:Gem::Dependency
168
+ name: bundler
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - "~>"
172
+ - !ruby/object:Gem::Version
173
+ version: '2.4'
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - "~>"
179
+ - !ruby/object:Gem::Version
180
+ version: '2.4'
181
+ - !ruby/object:Gem::Dependency
182
+ name: rake
183
+ requirement: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - ">="
186
+ - !ruby/object:Gem::Version
187
+ version: '0'
188
+ type: :development
189
+ prerelease: false
190
+ version_requirements: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - ">="
193
+ - !ruby/object:Gem::Version
194
+ version: '0'
195
+ - !ruby/object:Gem::Dependency
196
+ name: rspec
197
+ requirement: !ruby/object:Gem::Requirement
198
+ requirements:
199
+ - - ">="
200
+ - !ruby/object:Gem::Version
201
+ version: '0'
202
+ type: :development
203
+ prerelease: false
204
+ version_requirements: !ruby/object:Gem::Requirement
205
+ requirements:
206
+ - - ">="
207
+ - !ruby/object:Gem::Version
208
+ version: '0'
209
+ - !ruby/object:Gem::Dependency
210
+ name: sensu-extensions-system-profile
211
+ requirement: !ruby/object:Gem::Requirement
212
+ requirements:
213
+ - - '='
214
+ - !ruby/object:Gem::Version
215
+ version: 1.0.0
216
+ type: :development
217
+ prerelease: false
218
+ version_requirements: !ruby/object:Gem::Requirement
219
+ requirements:
220
+ - - '='
221
+ - !ruby/object:Gem::Version
222
+ version: 1.0.0
223
+ description: The Sensu extension loader library
224
+ email:
225
+ - portertech@gmail.com
226
+ executables: []
227
+ extensions: []
228
+ extra_rdoc_files: []
229
+ files:
230
+ - LICENSE.txt
231
+ - README.md
232
+ - lib/sensu/extensions.rb
233
+ - lib/sensu/extensions/constants.rb
234
+ - lib/sensu/extensions/loader.rb
235
+ - sensu-extensions.gemspec
236
+ homepage: https://github.com/sensu/sensu-extensions
237
+ licenses:
238
+ - MIT
239
+ metadata: {}
240
+ post_install_message:
241
+ rdoc_options: []
242
+ require_paths:
243
+ - lib
244
+ required_ruby_version: !ruby/object:Gem::Requirement
245
+ requirements:
246
+ - - ">="
247
+ - !ruby/object:Gem::Version
248
+ version: '0'
249
+ required_rubygems_version: !ruby/object:Gem::Requirement
250
+ requirements:
251
+ - - ">="
252
+ - !ruby/object:Gem::Version
253
+ version: '0'
254
+ requirements: []
255
+ rubygems_version: 3.4.10
256
+ signing_key:
257
+ specification_version: 4
258
+ summary: The Sensu extension loader library
259
+ test_files: []