sensu-plugins-signifai 1.0.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 389f49cafeacc6ce9aefefbfe382fc61e42be369
4
+ data.tar.gz: 30027be3978d004d694a93a0ca5f14c9fe32052c
5
+ SHA512:
6
+ metadata.gz: ed36d58df46616f4279be4201ae71f425fc401d59ff3883f7ce4dffe82fb2e32df25bff2f2f170ae2c0d131a9dabb3e1f044813e804da60471ba75029b8ebdb1
7
+ data.tar.gz: 8be3b8031c2e26e231e73a924d4a4751c96888c2a0ffd7c75d52c7d6c8e4535e8ede900ca5e7c15dd86855f017fd23d2aa89fcf7db5205d8aade2c0948c5b4c7
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ v1.0.0
2
+ ======
3
+
4
+ - Initial version.
5
+
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Sensu-Plugins
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,117 @@
1
+ This is sensu-plugin-signifai, a sensu event handler for submitting your
2
+ metrics to SignifAi via the REST API.
3
+
4
+ Installation
5
+ ============
6
+
7
+ Assuming you have [installed Sensu for your platform]
8
+ (https://sensuapp.org/docs/latest/installation/), you should be able
9
+ to download our gem at http://rpm.signifai.io/sensu/sensu-plugins-signifai-1.0.0.gem .
10
+ If you elect to use the "embedded" Ruby that comes with Sensu, you may
11
+ want to (at least temporarily) add their Ruby to your PATH:
12
+
13
+ ```
14
+ export EMBEDDED_RUBY="true"
15
+ export PATH="/opt/sensu/embedded/bin:$PATH"
16
+ ```
17
+
18
+ Next, you'll want to download the gem at http://rpm.signifai.io/sensu/sensu-plugins-signifai-1.0.0.gem .
19
+
20
+ Once the gem is downloaded to your local directory, simply run:
21
+
22
+ ```
23
+ sudo -E gem install ./sensu-plugins-signifai-1.0.0.gem
24
+ ```
25
+
26
+ Verify that `which handler-signifai.rb` gives you a valid path; if
27
+ so, the plugin is installed and ready to use!
28
+
29
+ Configuration
30
+ =============
31
+
32
+ The Signifai event handler is what Sensu calls a 'pipe' handler type, and you
33
+ will need to configure it before it will forward events for you.
34
+
35
+ Write out a file, /etc/sensu/conf.d/signifai.json , that looks like this:
36
+
37
+ ```
38
+ {
39
+ "handlers": {
40
+ "signifai": {
41
+ "type": "pipe",
42
+ "filter": "state_change_only",
43
+ "command": "/opt/sensu/embedded/bin/handler-signifai.rb"
44
+ }
45
+ },
46
+ "signifai": {
47
+ "api_key": "YOUR_API_KEY"
48
+ },
49
+ "sensu_plugin": {
50
+ "disable_deprecated_filtering": true
51
+ },
52
+ "filters": {
53
+ "state_change_only": {
54
+ "negate": false,
55
+ "attributes": {
56
+ "occurrences": "eval: value == 1 || ':::action:::' == 'resolve'"
57
+ }
58
+ }
59
+ }
60
+ }
61
+ ```
62
+
63
+ If you don't want to add the sensu_plugin setting because you are currently
64
+ relying on the deprecated filtering ([more information]
65
+ (https://blog.sensuapp.org/deprecating-event-filtering-in-sensu-plugin-b60c7c500be3))
66
+ you can, instead, set the `"enable_deprecated_filtering": false` per-check.
67
+
68
+ For any check whose results you want to forward to signifai, refer to this
69
+ example:
70
+
71
+
72
+ ```
73
+ {
74
+ "checks": {
75
+ "sleep": {
76
+ "command": "/opt/sensu/embedded/bin/check-process.rb -p sleep",
77
+ "subscribers": ["dev-sensu"],
78
+ "handlers": ["signifai"],
79
+ "interval": 60
80
+ }
81
+ }
82
+ }
83
+ ```
84
+
85
+ You can use either the `handler` attribute with just the string `"signifai"`
86
+ or you can use `handlers` with `"signifai"` alongside any other handlers you
87
+ may need.
88
+
89
+ Building (for developers)
90
+ =========================
91
+
92
+ You will need to install dependencies (note that you will need the `bundler`
93
+ gem if you are using your system's native Ruby):
94
+
95
+ ```
96
+ bundle install
97
+ ```
98
+
99
+ And it's always a safe bet to run tests:
100
+
101
+ ```
102
+ bundle exec rake default
103
+ ```
104
+
105
+ If the tests are okay, you can build your gem like so:
106
+
107
+ ```
108
+ gem build sensu-plugin-signifai.gemspec
109
+ ```
110
+
111
+ If you like, you can then install your newly-built gem
112
+ using the instructions in the Installation section.
113
+
114
+ For more information on the tests/procedures the sensu-plugins
115
+ authors use when determining if a plugin is ready for release,
116
+ check http://sensu-plugins.io/docs/testing.html -- it should be
117
+ helpful when suggesting changes.
@@ -0,0 +1,135 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This handler creates and resolves SignifAi incidents, refreshing
4
+ # stale incident details every 30 minutes
5
+ #
6
+ # Based loosely on the PagerDuty sensu plugin.
7
+ #
8
+ # Copyright 2017 SignifAI, Inc <support@signifai.io>
9
+ #
10
+ # Released under the same terms as Sensu (the MIT license); see LICENSE
11
+ # for details.
12
+ #
13
+ # Dependencies:
14
+ #
15
+ # sensu-plugin >= 1.0.0
16
+ #
17
+
18
+ require 'sensu-handler'
19
+ require 'net/http'
20
+
21
+ #
22
+ # Signifai
23
+ #
24
+
25
+ PRIORITIES = %w(low medium critical critical).freeze
26
+ COLLECTORS_URI = URI('https://collectors.signifai.io/v1/incidents')
27
+
28
+ class SignifaiHandler < Sensu::Handler
29
+ option :json_config,
30
+ description: 'Config Name',
31
+ short: '-j JsonConfig',
32
+ long: '--json_config JsonConfig',
33
+ required: false,
34
+ default: 'signifai'
35
+
36
+ def json_config
37
+ @json_config ||= config[:json_config]
38
+ end
39
+
40
+ def api_key
41
+ @api_key ||= settings[json_config]['api_key']
42
+ end
43
+
44
+ def proxy_settings
45
+ proxy_settings = {}
46
+
47
+ proxy_settings['proxy_host'] = settings[json_config]['proxy_host'] || nil
48
+ proxy_settings['proxy_port'] = settings[json_config]['proxy_port'] || 3128
49
+ proxy_settings['proxy_username'] = settings[json_config]['proxy_username'] || ''
50
+ proxy_settings['proxy_password'] = settings[json_config]['proxy_password'] || ''
51
+
52
+ proxy_settings
53
+ end
54
+
55
+ def incident_with_state(state, time)
56
+ priority_index = if @event['check']['status'].nil? || PRIORITIES[@event['check']['status']].nil?
57
+ 2
58
+ else
59
+ @event['check']['status']
60
+ end
61
+
62
+ incident = {
63
+ event_source: 'sensu',
64
+ host: @event['check']['source'] || @event['client']['name'],
65
+ service: @event['client']['name'],
66
+ timestamp: time,
67
+ event_description: @event['check']['output'],
68
+ value: PRIORITIES[priority_index],
69
+ attributes: { state: state }
70
+ }
71
+
72
+ JSON.dump(incident)
73
+ end
74
+
75
+ def _http_client(http_client = nil)
76
+ proxy = proxy_settings
77
+ http = if http_client
78
+ http_client
79
+ elsif proxy['proxy_host']
80
+ Net::HTTP.new(COLLECTORS_URI.host, COLLECTORS_URI.port,
81
+ p_addr: proxy['proxy_host'],
82
+ p_port: proxy['proxy_port'],
83
+ p_user: proxy['proxy_username'],
84
+ p_pass: proxy['proxy_password'])
85
+ else
86
+ Net::HTTP.new(COLLECTORS_URI.host, COLLECTORS_URI.port)
87
+ end
88
+ http.use_ssl = true
89
+ http
90
+ end
91
+
92
+ def handle(http_client = nil, time = Time.now.to_i)
93
+ # "Redundant begin" -- the rescue retries the whole function
94
+ # so it's not redundant
95
+ begin # rubocop:disable Style/RedundantBegin
96
+ tries ||= 3
97
+ Timeout.timeout(10) do
98
+ http = _http_client(http_client)
99
+
100
+ incident = case @event['action']
101
+ when 'create', 'flapping'
102
+ incident_with_state('alarm', time)
103
+ when 'resolve'
104
+ incident_with_state('ok', time)
105
+ end
106
+
107
+ begin
108
+ log_host = @event['check']['source'] || @event['client']['name'] || '(none)'
109
+ log_svc = @event['client']['name'] || '(none)'
110
+ http_request = Net::HTTP::Post.new(COLLECTORS_URI)
111
+ http_request.body = incident
112
+ http_request.content_type = 'application/json'
113
+ http_request['Authorization'] = "Bearer #{api_key}"
114
+
115
+ http.request(http_request)
116
+
117
+ puts 'signifai -- ' + @event['action'].capitalize + 'd incident: ' + log_host + ' / ' + log_svc
118
+ rescue Net::HTTPServerException => error
119
+ if (tries -= 1) > 0
120
+ retry
121
+ else
122
+ puts 'signifai -- failed to ' + @event['action'] + ' incident -- ' + log_host + ' / ' + log_svc + ' -- ' +
123
+ error.response.code + ' ' + error.response.message + ': ' + error.response.body
124
+ end
125
+ end
126
+ end
127
+ rescue Timeout::Error
128
+ if (tries -= 1) > 0
129
+ retry
130
+ else
131
+ puts 'signifai -- timed out while attempting to ' + @event['action'] + ' a incident -- ' + incident_key
132
+ end
133
+ end
134
+ end
135
+ end
@@ -0,0 +1 @@
1
+ require 'sensu-plugins-signifai/version'
@@ -0,0 +1,9 @@
1
+ module SensuPluginsSignifai
2
+ module Version
3
+ MAJOR = 1
4
+ MINOR = 0
5
+ PATCH = 0
6
+
7
+ VER_STRING = [MAJOR, MINOR, PATCH].compact.join('.')
8
+ end
9
+ end
metadata ADDED
@@ -0,0 +1,196 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sensu-plugins-signifai
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Sensu-Plugins and contributors
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-07-12 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: '1.2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.7'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
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
+ - !ruby/object:Gem::Dependency
56
+ name: github-markup
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.3'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.3'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.10'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.10'
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
+ - !ruby/object:Gem::Dependency
98
+ name: redcarpet
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '3.2'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '3.2'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rspec
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '3.1'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '3.1'
125
+ - !ruby/object:Gem::Dependency
126
+ name: rubocop
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: 0.40.0
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: 0.40.0
139
+ - !ruby/object:Gem::Dependency
140
+ name: yard
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: '0.8'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: '0.8'
153
+ description: This plugin provides a Sensu handler for SignifAi
154
+ email: "<zcarlson@signifai.io>"
155
+ executables:
156
+ - handler-signifai.rb
157
+ extensions: []
158
+ extra_rdoc_files: []
159
+ files:
160
+ - CHANGELOG.md
161
+ - LICENSE
162
+ - README.md
163
+ - bin/handler-signifai.rb
164
+ - lib/sensu-plugins-signifai.rb
165
+ - lib/sensu-plugins-signifai/version.rb
166
+ homepage: https://github.com/signifai/sensu-plugins-signifai
167
+ licenses:
168
+ - MIT
169
+ metadata:
170
+ maintainer: sensu-plugin
171
+ development_status: active
172
+ production_status: stable - production ready
173
+ release_draft: 'false'
174
+ release_prerelease: 'false'
175
+ post_install_message: You can use the embedded Ruby by setting EMBEDDED_RUBY=true
176
+ in /etc/default/sensu
177
+ rdoc_options: []
178
+ require_paths:
179
+ - lib
180
+ required_ruby_version: !ruby/object:Gem::Requirement
181
+ requirements:
182
+ - - ">="
183
+ - !ruby/object:Gem::Version
184
+ version: 2.0.0
185
+ required_rubygems_version: !ruby/object:Gem::Requirement
186
+ requirements:
187
+ - - ">="
188
+ - !ruby/object:Gem::Version
189
+ version: '0'
190
+ requirements: []
191
+ rubyforge_project:
192
+ rubygems_version: 2.6.11
193
+ signing_key:
194
+ specification_version: 4
195
+ summary: Sensu plugins for SignifAi
196
+ test_files: []