sensu-plugins-opsgenie 3.0.0 → 3.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG.md +8 -1
- data/bin/handler-opsgenie.rb +73 -43
- data/lib/sensu-plugins-opsgenie/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 323357f14532830637c6a10405ac536583d62e69800bf3826e779d96df4b9bf6
|
4
|
+
data.tar.gz: 35402983316c7d647a512e4744b79a2db7143e5d26a2fe96772a862a5cd1cd9d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 187b11496746b73be05ed9b7f945e49b7b25cb221599a17ea4a4a0a3efe76973c496e17dc26fff98e924cdd31a4e6ce3fe8d23cdcadf32d24ea9324172667d02
|
7
|
+
data.tar.gz: 25c68795b90f82b52a46e6941338590dce27c54b480a3388f7234f2e0651270db79689c89fceef887bb06d49a561bd07133da969c00aa2e4be289605ea952efc
|
data/CHANGELOG.md
CHANGED
@@ -5,6 +5,12 @@ This CHANGELOG follows the format listed at [Keep A Changelog](http://keepachang
|
|
5
5
|
|
6
6
|
## [Unreleased]
|
7
7
|
|
8
|
+
## [3.1.0] - 2017-11-12
|
9
|
+
### Added
|
10
|
+
- Added optional `-t, --template` parameter to specify the location of a ERB template file
|
11
|
+
- Added possibility to specify custom timeout
|
12
|
+
- Some cleanup and minor refactorings
|
13
|
+
|
8
14
|
## [3.0.0] - 2017-07-13
|
9
15
|
### Added
|
10
16
|
- Testing on Ruby 2.4.1
|
@@ -58,7 +64,8 @@ This CHANGELOG follows the format listed at [Keep A Changelog](http://keepachang
|
|
58
64
|
- initial release
|
59
65
|
- Fixed json configuration load
|
60
66
|
|
61
|
-
[Unreleased]: https://github.com/sensu-plugins/sensu-plugins-opsgenie/compare/3.
|
67
|
+
[Unreleased]: https://github.com/sensu-plugins/sensu-plugins-opsgenie/compare/3.1.0...HEAD
|
68
|
+
[3.1.0]: https://github.com/sensu-plugins/sensu-plugins-opsgenie/compare/3.0.0...3.1.0
|
62
69
|
[3.0.0]: https://github.com/sensu-plugins/sensu-plugins-opsgenie/compare/2.0.1...3.0.0
|
63
70
|
[2.0.1]: https://github.com/sensu-plugins/sensu-plugins-opsgenie/compare/2.0.0...2.0.1
|
64
71
|
[2.0.0]: https://github.com/sensu-plugins/sensu-plugins-opsgenie/compare/1.0.0...2.0.0
|
data/bin/handler-opsgenie.rb
CHANGED
@@ -8,39 +8,72 @@ require 'sensu-handler'
|
|
8
8
|
require 'net/https'
|
9
9
|
require 'uri'
|
10
10
|
require 'json'
|
11
|
+
require 'erb'
|
11
12
|
|
12
13
|
class Opsgenie < Sensu::Handler
|
14
|
+
attr_reader :json_config, :message_template
|
15
|
+
|
16
|
+
OPSGENIE_URL = 'https://api.opsgenie.com/v1/json/alert'.freeze
|
17
|
+
|
13
18
|
option :json_config,
|
14
19
|
description: 'Configuration name',
|
15
20
|
short: '-j <config-name>',
|
16
21
|
long: '--json <config-name>',
|
17
22
|
default: 'opsgenie'
|
18
23
|
|
24
|
+
option :message_template,
|
25
|
+
description: 'Location of custom erb template for advanced message formatting',
|
26
|
+
short: '-t <file_path>',
|
27
|
+
long: '--template <file_path>',
|
28
|
+
default: nil
|
29
|
+
|
19
30
|
def handle
|
20
|
-
|
31
|
+
init
|
32
|
+
process
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def init
|
38
|
+
@json_config = settings[config[:json_config]] || {}
|
39
|
+
@message_template = config[:message_template]
|
21
40
|
# allow config to be changed by the check
|
22
|
-
if @event['check']['opsgenie']
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
puts 'opsgenie -- failed to ' + @event['action'] + ' incident -- ' + event_id
|
39
|
-
end
|
41
|
+
json_config.merge!(@event['check']['opsgenie']) if @event['check']['opsgenie']
|
42
|
+
end
|
43
|
+
|
44
|
+
def process
|
45
|
+
timeout = json_config[:timeout] || 30
|
46
|
+
Timeout.timeout(timeout) do
|
47
|
+
response = case @event['action']
|
48
|
+
when 'create'
|
49
|
+
create_alert
|
50
|
+
when 'resolve'
|
51
|
+
close_alert
|
52
|
+
end
|
53
|
+
if response['code'] == 200
|
54
|
+
puts 'opsgenie -- ' + @event['action'].capitalize + 'd incident -- ' + event_id
|
55
|
+
else
|
56
|
+
puts 'opsgenie -- failed to ' + @event['action'] + ' incident -- ' + event_id
|
40
57
|
end
|
41
|
-
rescue Timeout::Error
|
42
|
-
puts 'opsgenie -- timed out while attempting to ' + @event['action'] + ' a incident -- ' + event_id
|
43
58
|
end
|
59
|
+
rescue Timeout::Error
|
60
|
+
puts 'opsgenie -- timed out while attempting to ' + @event['action'] + ' a incident -- ' + event_id
|
61
|
+
end
|
62
|
+
|
63
|
+
def message
|
64
|
+
return @event['notification'] unless @event['notification'].nil?
|
65
|
+
return default_message if message_template.nil? || !File.exist?(message_template)
|
66
|
+
custom_message
|
67
|
+
rescue StandardError
|
68
|
+
default_message
|
69
|
+
end
|
70
|
+
|
71
|
+
def custom_message
|
72
|
+
ERB.new(File.read(message_template)).result(binding)
|
73
|
+
end
|
74
|
+
|
75
|
+
def default_message
|
76
|
+
[@event['client']['name'], @event['check']['name'], @event['check']['output'].chomp].join(' : ')
|
44
77
|
end
|
45
78
|
|
46
79
|
def event_id
|
@@ -63,39 +96,36 @@ class Opsgenie < Sensu::Handler
|
|
63
96
|
@event['client']['name']
|
64
97
|
end
|
65
98
|
|
66
|
-
def create_alert
|
99
|
+
def create_alert
|
100
|
+
post_to_opsgenie(:create,
|
101
|
+
alias: event_id,
|
102
|
+
message: message,
|
103
|
+
description: json_config['description'],
|
104
|
+
entity: client_name,
|
105
|
+
tags: tags.join(','),
|
106
|
+
recipients: json_config['recipients'],
|
107
|
+
teams: json_config['teams'])
|
108
|
+
end
|
109
|
+
|
110
|
+
def tags
|
67
111
|
tags = []
|
68
|
-
tags <<
|
69
|
-
tags << 'OverwriteQuietHours' if event_status == 2 &&
|
112
|
+
tags << json_config['tags'] if json_config['tags']
|
113
|
+
tags << 'OverwriteQuietHours' if event_status == 2 && json_config['overwrite_quiet_hours'] == true
|
70
114
|
tags << 'unknown' if event_status >= 3
|
71
115
|
tags << 'critical' if event_status == 2
|
72
116
|
tags << 'warning' if event_status == 1
|
73
|
-
unless event_tags.nil?
|
74
|
-
|
75
|
-
end
|
76
|
-
|
77
|
-
description = @json_config['description'] if @json_config['description']
|
78
|
-
recipients = @json_config['recipients'] if @json_config['recipients']
|
79
|
-
teams = @json_config['teams'] if @json_config['teams']
|
80
|
-
|
81
|
-
post_to_opsgenie(:create,
|
82
|
-
alias: event_id,
|
83
|
-
message: message,
|
84
|
-
description: description,
|
85
|
-
entity: client_name,
|
86
|
-
tags: tags.join(','),
|
87
|
-
recipients: recipients,
|
88
|
-
teams: teams)
|
117
|
+
event_tags.each { |tag, value| tags << "#{tag}_#{value}" } unless event_tags.nil?
|
118
|
+
tags
|
89
119
|
end
|
90
120
|
|
91
121
|
def post_to_opsgenie(action = :create, params = {})
|
92
|
-
params['customerKey'] =
|
122
|
+
params['customerKey'] = json_config['customerKey']
|
93
123
|
|
94
124
|
# override source if specified, default is ip
|
95
|
-
params['source'] =
|
125
|
+
params['source'] = json_config['source'] if json_config['source']
|
96
126
|
|
97
127
|
uripath = (action == :create) ? '' : 'close'
|
98
|
-
uri = URI.parse("
|
128
|
+
uri = URI.parse("#{OPSGENIE_URL}/#{uripath}")
|
99
129
|
http = Net::HTTP.new(uri.host, uri.port)
|
100
130
|
http.use_ssl = true
|
101
131
|
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sensu-plugins-opsgenie
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.1.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: 2017-
|
11
|
+
date: 2017-11-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sensu-plugin
|
@@ -191,7 +191,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
191
191
|
version: '0'
|
192
192
|
requirements: []
|
193
193
|
rubyforge_project:
|
194
|
-
rubygems_version: 2.
|
194
|
+
rubygems_version: 2.7.2
|
195
195
|
signing_key:
|
196
196
|
specification_version: 4
|
197
197
|
summary: Sensu plugins for working with opsgenie
|