sensu-plugins-victorops 2.1.0 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 965908392c154eb1fd40ded196f5f184b466cb9b49246d5e7d1429e2583844f5
4
- data.tar.gz: 5546257223f4b6b6a714f3119d5af80c49e2040e0dd5dea6cb4214cc626beff3
3
+ metadata.gz: f107aa23da5952e367c157267f700e78869668c8af37ab518050524dab9451d5
4
+ data.tar.gz: 9823e387a5394e4c0923b162d28688393b0925e46b995828ad4d89f23d19cb92
5
5
  SHA512:
6
- metadata.gz: c465485b0e6cb7ead4963755d3d8a4970c5081004838d5280cbbcf44dcf2891a3266dbf719b29ecf7b331edfd1ee2fc121faecbe04c408c46e6398610b8c4dca
7
- data.tar.gz: ec8edb81e43e88fb5eb476771f53ef230f0c26eaea6208b30bb4ff2e4b5aae9ffa6fc242feaa82dbbf5fb1a1351611ee4c607c8a86a0daf649b7704b4d88da66
6
+ metadata.gz: 51b4996bc1c53266ce88d25eda1e8a79d09a1e8bb42d34551d89cf95902a643da07b32a3609ecbe246e43a2a1def38b692c3b4e645e62f205cafb0ad2f453ca9
7
+ data.tar.gz: 5e35a6c01f6f5e69f215fcd10dc2ad0661fe406d9d42e50f7dc6d41634a742e5f5c6e475472a4836dd4f38050612b9d847856cca5b923852a9385de92a03dca4
@@ -5,6 +5,18 @@ This CHANGELOG follows the format located [here](https://github.com/sensu-plugin
5
5
 
6
6
  ## [Unreleased]
7
7
 
8
+ ## [3.0.0] - 2020-03-13
9
+ ### Added
10
+ - Adds dryrun option to help diagnose settings being used.
11
+ - Extends usages information to include envvar note
12
+
13
+ ### Changed
14
+ - Update dev dependancies
15
+ - Updated Readme with corrected Sensu Go instructions
16
+
17
+ ### Breaking Changes
18
+ - Update runtime dependancy for json to 2.3.0
19
+
8
20
  ## [2.1.0] - 2019-10-25
9
21
  ### Added
10
22
  - Adds ability to use the environment variables `VICTOROPS_API_URL` & `VICTOROPS_ROUTING_KEY` for Sensu Go
@@ -51,7 +63,8 @@ This CHANGELOG follows the format located [here](https://github.com/sensu-plugin
51
63
  ### Added
52
64
  - initial release
53
65
 
54
- [Unreleased]: https://github.com/sensu-plugins/sensu-plugins-victorops/compare/2.1.0...HEAD
66
+ [Unreleased]: https://github.com/sensu-plugins/sensu-plugins-victorops/compare/3.0.0...HEAD
67
+ [3.0.0]: https://github.com/sensu-plugins/sensu-plugins-victorops/compare/2.1.0...3.0.0
55
68
  [2.1.0]: https://github.com/sensu-plugins/sensu-plugins-victorops/compare/2.0.0...2.1.0
56
69
  [2.0.0]: https://github.com/sensu-plugins/sensu-plugins-victorops/compare/1.0.0...2.0.0
57
70
  [1.0.0]: https://github.com/sensu-plugins/sensu-plugins-victorops/compare/0.1.0...1.0.0
data/README.md CHANGED
@@ -13,39 +13,21 @@
13
13
  * bin/handler-victorops.rb
14
14
 
15
15
  ## Usage
16
-
17
- ```
18
- {
19
- "victorops": {
20
- "api_url": "YOUR_API_URL_WHITOUT_ROUTING_KEY",
21
- "routing_key": "everyone"
22
- },
23
- "handlers": {
24
- "victorops": {
25
- "type": "pipe",
26
- "command": "handler-victorops.rb"
27
- }
28
- }
29
- }
30
16
  ```
31
- ## Installation
32
-
33
- [Installation and Setup](http://sensu-plugins.io/docs/installation_instructions.html)
34
-
17
+ bin/handler-victorops.rb --help
18
+ Usage: bin/handler-victorops.rb (options)
19
+ -a, --api-url APIURL VictorOps API URL without routing key. Or use envvar VICTOROPS_API_URL.
20
+ --dryrun Report settings, and take no action
21
+ --map-go-event-into-ruby Enable Sensu Go to Sensu Ruby event mapping. Alternatively set envvar SENSU_MAP_GO_EVENT_INTO_RUBY=1.
22
+ -r, --routingkey KEY Routing key. Or use envvar VICTOROPS_ROUTING_KEY.
35
23
 
36
- ## Notes
37
- If you have multiple VictorOps accounts and need to route alerts to different endpoints, specifying the handler name in the config is necessary otherwise, the handler will attempt to route to the default `victorops`. You will therefore need to use the `-name` switch to specify the API endpoint as noted below.
38
-
39
- ```
40
- "victorops_enpoint1": {
41
- "type": "pipe",
42
- "command": "/opt/sensu/embedded/bin/handler-victorops.rb -name victorops_endpoint1"
43
- },
44
24
  ```
45
25
 
46
26
  ### Sensu Go Enabled
47
27
 
48
- This plugin is also Sensu Go enabled. You can map events into ruby by using the flag `--map_go_event_into_ruby` as part of your command. Practically, this might look like:
28
+ Plugin versions 2.0 and higher are now Sensu Go enabled. You can map Sensu Go events into Sensu Classic events by using the flag `--map_go_event_into_ruby` as part of your command. Now that Sensu Classic is now EOL, a future version of this plugin will drop support for Sensu Classic and will assume Sensu Go event structuring.
29
+
30
+ Here is an example Sensu Go handler resource definition for reference. Please note, this plugin's Sensu Asset should be used in conjunction with the Sensu Ruby runtime asset.
49
31
 
50
32
  ```
51
33
  ---
@@ -63,11 +45,43 @@ spec:
63
45
  filters:
64
46
  - is_incident
65
47
  env_vars:
66
- - KEEPALIVE_SLACK_WEBHOOK=https://alert.victorops.com/integrations/generic/01234567/alert/0123456789101112
48
+ - VICTOROPS_API_URL=https://alert.victorops.com/integrations/generic/01234567/alert/0123456789101112
67
49
  - VICTOROPS_ROUTING_KEY=testing
68
50
  runtime_assets:
69
51
  - sensu-plugins-victorops
70
52
  - sensu-ruby-runtime
71
53
  ```
72
54
 
73
- You'll also note that the plugin also supports environment variables. You can use these without having to have a file locally to load in those values.
55
+ You'll note that the plugin supports environment variables for both routing key and api url. You can define this in the Sensu Go handler resource definition. You can support multiple VictorOps accounts by having a different handler definition, each with appropriate environment variables defined.
56
+
57
+
58
+ # Sensu Classic Support
59
+ Here is an example handlers configuration for Sensu Classic. Please note, Sensu Classic has now reached EOL, and support for Sensu Classic events is planned to be removed in a future version of this plugin.
60
+
61
+ ```
62
+ {
63
+ "victorops": {
64
+ "api_url": "YOUR_API_URL_WHITOUT_ROUTING_KEY",
65
+ "routing_key": "everyone"
66
+ },
67
+ "handlers": {
68
+ "victorops": {
69
+ "type": "pipe",
70
+ "command": "handler-victorops.rb"
71
+ }
72
+ }
73
+ }
74
+ ```
75
+
76
+ If you have multiple VictorOps accounts and need to route alerts to different endpoints, specifying the handler name in the config is necessary otherwise, the handler will attempt to route to the default `victorops`. You will therefore need to use the `-name` switch to specify the API endpoint as noted below.
77
+
78
+ ```
79
+ "victorops_enpoint1": {
80
+ "type": "pipe",
81
+ "command": "/opt/sensu/embedded/bin/handler-victorops.rb -name victorops_endpoint1"
82
+ },
83
+ ```
84
+
85
+ ## Installation
86
+
87
+ [Installation and Setup](http://sensu-plugins.io/docs/installation_instructions.html)
@@ -1,4 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
2
4
  # This handler creates and resolves victorops incidents
3
5
  #
4
6
  # Released under the same terms as Sensu (the MIT license); see LICENSE
@@ -20,7 +22,7 @@ require 'json'
20
22
 
21
23
  class VictorOps < Sensu::Handler
22
24
  option :api_url,
23
- description: 'VictorOps API URL without routing key',
25
+ description: 'VictorOps API URL without routing key. Or use envvar VICTOROPS_API_URL.',
24
26
  short: '-a APIURL',
25
27
  long: '--api-url APIURL',
26
28
  default: nil
@@ -32,34 +34,103 @@ class VictorOps < Sensu::Handler
32
34
  default: 'victorops'
33
35
 
34
36
  option :routing_key,
35
- description: 'Routing key',
37
+ description: 'Routing key. Or use envvar VICTOROPS_ROUTING_KEY.',
36
38
  short: '-r KEY',
37
39
  long: '--routingkey KEY',
38
40
  default: nil
39
41
 
40
- def handle
41
- # validate that we have a settings name
42
- unless defined? settings[config[:settingsname]] && !settings[config[:settingsname]].nil?
43
- raise "victorops.rb sensu setting '#{config[:settingsname]}' not found or empty"
44
- end
42
+ option :dryrun,
43
+ description: 'Report settings, and take no action',
44
+ long: '--dryrun',
45
+ boolean: true,
46
+ default: false
45
47
 
48
+ def set_api_url
46
49
  # validate that we have an api url - environment variables take precedence
47
50
  api_url = ENV['VICTOROPS_API_URL']
48
51
  api_url = config[:api_url] if api_url.nil?
49
- api_url = settings[config[:settingsname]]['api_url'] if api_url.nil?
50
-
51
- unless defined? api_url && !api_url.nil?
52
- raise "victorops.rb sensu setting '#{config[:settingsname]}.api_url' not found or empty"
52
+ if api_url.nil?
53
+ # validate that we have a settings name
54
+ if defined?(settings[config[:settingsname]]) && !settings[config[:settingsname]].nil?
55
+ api_url = settings[config[:settingsname]]['api_url']
56
+ else
57
+ raise "victorops.rb sensu setting '#{config[:settingsname]}' not found or empty" unless config[:dryrun]
58
+ end
53
59
  end
60
+ return api_url if defined?(api_url) && !api_url.nil?
61
+
62
+ raise "victorops.rb sensu setting '#{config[:settingsname]}.api_url' not found or empty" unless config[:dryrun]
63
+ end
54
64
 
65
+ def set_routing_key
55
66
  # validate that we have a routing key - environment variables take precedence
56
67
  routing_key = ENV['VICTOROPS_ROUTING_KEY']
57
68
  routing_key = config[:routing_key] if routing_key.nil?
58
- routing_key = settings[config[:settingsname]]['routing_key'] if routing_key.nil?
69
+ if routing_key.nil?
70
+ # validate that we have a settings name in the config
71
+ if defined?(settings[config[:settingsname]]) && !settings[config[:settingsname]].nil?
72
+ routing_key = settings[config[:settingsname]]['routing_key']
73
+ else
74
+ raise "victorops.rb sensu setting '#{config[:settingsname]}' not found or empty" unless config[:dryrun]
75
+ end
76
+ end
77
+ return routing_key if defined?(routing_key) && !routing_key.nil?
78
+
79
+ raise 'routing key not defined, should be in Sensu settings or passed via command arguments' unless config[:dryrun]
80
+ end
81
+
82
+ def dry_run(api_url, routing_key, uri, payload)
83
+ return unless config[:dryrun]
59
84
 
60
- unless defined? routing_key && !routing_key.nil?
61
- raise 'routing key not defined, should be in Sensu settings or passed via command arguments'
85
+ puts 'Dryrun: reporting settings and exiting'
86
+ puts " option settingsname set: #{config[:settingsname]}"
87
+ puts 'Determing API_URL to use:'
88
+ if ENV['VICTOROPS_API_URL']
89
+ puts " envvar VICTOROPS_API_URL set: #{ENV['VICTOROPS_API_URL']}"
90
+ else
91
+ puts ' envvar VICTOROPS_API_URL not set'
92
+ end
93
+ if config[:api_url]
94
+ puts " option api-url set: #{config[:api_url]}"
95
+ else
96
+ puts ' option api-url not set'
97
+ end
98
+ if settings[config[:settingsname]]
99
+ puts " settings api_url set: #{settings[config[:settingsname]]['api_url']}" if settings[config[:settingsname]]['api_url']
100
+ else
101
+ puts " setting name: #{config[:settingsname]} does not exist"
102
+ end
103
+ puts " using: #{api_url}"
104
+ puts 'Determing ROUTING_KEY to use:'
105
+ if ENV['VICTOROPS_ROUTING_KEY']
106
+ puts " envvar VICTOROPS_ROUTING_KEY set: #{ENV['VICTOROPS_ROUTING_KEY']}"
107
+ else
108
+ puts ' envvar VICTOROPS_ROUTING_KEY not set'
109
+ end
110
+ if config[:routing_key]
111
+ puts " option routingkey set: #{config[:routing_key]}"
112
+ else
113
+ puts ' option routingkey not set'
62
114
  end
115
+ if settings[config[:settingsname]]
116
+ puts " settings routing_key set: #{settings[config[:settingsname]]['routing_key']}" if settings[config[:settingsname]]['routing_key']
117
+ else
118
+ puts " setting name: #{config[:settingsname]} does not exist"
119
+ end
120
+ puts " using: #{routing_key}"
121
+ puts " #{@event['action']}"
122
+ puts "VictorOps Message URI: #{uri}"
123
+ puts " Message type: #{payload[:message_type]}"
124
+ end
125
+
126
+ def handle
127
+ # validate that we have a client defined
128
+ unless defined?(@event['client']) && !@event['client']['name'].nil?
129
+ raise 'victorops.rb sensu client not found or has no name. If using with Sensu Go please ensure you have enabled event mapping'
130
+ end
131
+
132
+ api_url = set_api_url
133
+ routing_key = set_routing_key
63
134
 
64
135
  incident_key = @event['client']['name'] + '/' + @event['check']['name']
65
136
 
@@ -68,36 +139,39 @@ class VictorOps < Sensu::Handler
68
139
  host = @event['client']['name']
69
140
  entity_id = incident_key
70
141
  state_message = description
71
- begin
72
- timeout(10) do
73
- case @event['action']
74
- when 'create'
75
- message_type = case @event['check']['status']
76
- when 1
77
- 'WARNING'
78
- else
79
- 'CRITICAL'
80
- end
81
- when 'resolve'
82
- message_type = 'RECOVERY'
83
- end
84
-
85
- payload = {}
86
- payload[:message_type] = message_type
87
- payload[:state_message] = state_message.chomp
88
- payload[:entity_id] = entity_id
89
- payload[:host_name] = host
90
- payload[:monitoring_tool] = 'sensu'
91
-
92
- # Add in client data
93
- payload[:check] = @event['check']
94
- payload[:client] = @event['client']
95
-
96
- uri = URI("#{api_url.chomp('/')}/#{routing_key}")
97
- https = Net::HTTP.new(uri.host, uri.port)
98
-
99
- https.use_ssl = true
142
+ case @event['action']
143
+ when 'create'
144
+ message_type = case @event['check']['status']
145
+ when 1
146
+ 'WARNING'
147
+ else
148
+ 'CRITICAL'
149
+ end
150
+ when 'resolve'
151
+ message_type = 'RECOVERY'
152
+ end
153
+ payload = {}
154
+ payload[:message_type] = message_type
155
+ payload[:state_message] = state_message.chomp
156
+ payload[:entity_id] = entity_id
157
+ payload[:host_name] = host
158
+ payload[:monitoring_tool] = 'sensu'
159
+
160
+ # Add in client data
161
+ payload[:check] = @event['check']
162
+ payload[:client] = @event['client']
163
+
164
+ uri = URI("#{api_url.chomp('/')}/#{routing_key}")
165
+ https = Net::HTTP.new(uri.host, uri.port)
166
+
167
+ https.use_ssl = true
168
+ if config[:dryrun]
169
+ dry_run(api_url, routing_key, uri, payload)
170
+ return
171
+ end
100
172
 
173
+ begin
174
+ Timeout.timeout(10) do
101
175
  request = Net::HTTP::Post.new(uri.path)
102
176
  request.body = payload.to_json
103
177
  response = https.request(request)
@@ -1 +1,3 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'sensu-plugins-victorops/version'
@@ -1,7 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module SensuPluginsVictorops
2
4
  module Version
3
- MAJOR = 2
4
- MINOR = 1
5
+ MAJOR = 3
6
+ MINOR = 0
5
7
  PATCH = 0
6
8
 
7
9
  VER_STRING = [MAJOR, MINOR, PATCH].compact.join('.')
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sensu-plugins-victorops
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sensu Plugins and contributors
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-10-26 00:00:00.000000000 Z
11
+ date: 2020-03-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: 1.8.5
19
+ version: 2.3.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - '='
25
25
  - !ruby/object:Gem::Version
26
- version: 1.8.5
26
+ version: 2.3.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: sensu-plugin
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -44,28 +44,28 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '1.7'
47
+ version: '2.1'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '1.7'
54
+ version: '2.1'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: codeclimate-test-reporter
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '0.4'
61
+ version: '1.0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '0.4'
68
+ version: '1.0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: github-markup
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -100,14 +100,28 @@ dependencies:
100
100
  requirements:
101
101
  - - "~>"
102
102
  - !ruby/object:Gem::Version
103
- version: '10.0'
103
+ version: '13.0'
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
108
  - - "~>"
109
109
  - !ruby/object:Gem::Version
110
- version: '10.0'
110
+ version: '13.0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rdoc
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '6.2'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '6.2'
111
125
  - !ruby/object:Gem::Dependency
112
126
  name: redcarpet
113
127
  requirement: !ruby/object:Gem::Requirement
@@ -128,42 +142,42 @@ dependencies:
128
142
  requirements:
129
143
  - - "~>"
130
144
  - !ruby/object:Gem::Version
131
- version: '3.1'
145
+ version: '3.4'
132
146
  type: :development
133
147
  prerelease: false
134
148
  version_requirements: !ruby/object:Gem::Requirement
135
149
  requirements:
136
150
  - - "~>"
137
151
  - !ruby/object:Gem::Version
138
- version: '3.1'
152
+ version: '3.4'
139
153
  - !ruby/object:Gem::Dependency
140
154
  name: rubocop
141
155
  requirement: !ruby/object:Gem::Requirement
142
156
  requirements:
143
157
  - - "~>"
144
158
  - !ruby/object:Gem::Version
145
- version: 0.40.0
159
+ version: 0.80.1
146
160
  type: :development
147
161
  prerelease: false
148
162
  version_requirements: !ruby/object:Gem::Requirement
149
163
  requirements:
150
164
  - - "~>"
151
165
  - !ruby/object:Gem::Version
152
- version: 0.40.0
166
+ version: 0.80.1
153
167
  - !ruby/object:Gem::Dependency
154
168
  name: yard
155
169
  requirement: !ruby/object:Gem::Requirement
156
170
  requirements:
157
171
  - - "~>"
158
172
  - !ruby/object:Gem::Version
159
- version: '0.8'
173
+ version: 0.9.20
160
174
  type: :development
161
175
  prerelease: false
162
176
  version_requirements: !ruby/object:Gem::Requirement
163
177
  requirements:
164
178
  - - "~>"
165
179
  - !ruby/object:Gem::Version
166
- version: '0.8'
180
+ version: 0.9.20
167
181
  description: Sensu plugins for Victorops alerting service
168
182
  email: "<sensu-users@googlegroups.com>"
169
183
  executables: