bin/handler-opsgenie.rb in sensu-plugins-opsgenie-1.0.0 vs bin/handler-opsgenie.rb in sensu-plugins-opsgenie-2.0.0
- old
+ new
@@ -20,17 +20,17 @@
@json_config = settings[config[:json_config]]
# allow config to be changed by the check
if @event['check']['opsgenie']
@json_config.merge!(@event['check']['opsgenie'])
end
- description = @event['notification'] || [@event['client']['name'], @event['check']['name'], @event['check']['output'].chomp].join(' : ')
+ message = @event['notification'] || [@event['client']['name'], @event['check']['name'], @event['check']['output'].chomp].join(' : ')
begin
timeout(30) do
response = case @event['action']
when 'create'
- create_alert(description)
+ create_alert(message)
when 'resolve'
close_alert
end
if response['code'] == 200
puts 'opsgenie -- ' + @event['action'].capitalize + 'd incident -- ' + event_id
@@ -57,24 +57,36 @@
def event_tags
@event['client']['tags']
end
- def create_alert(description)
+ def client_name
+ @event['client']['name']
+ end
+
+ def create_alert(message)
tags = []
tags << @json_config['tags'] if @json_config['tags']
tags << 'OverwriteQuietHours' if event_status == 2 && @json_config['overwrite_quiet_hours'] == true
tags << 'unknown' if event_status >= 3
tags << 'critical' if event_status == 2
tags << 'warning' if event_status == 1
unless event_tags.nil?
event_tags.each { |tag, value| tags << "#{tag}_#{value}" }
end
+ description = @json_config['description'] if @json_config['description']
recipients = @json_config['recipients'] if @json_config['recipients']
teams = @json_config['teams'] if @json_config['teams']
- post_to_opsgenie(:create, alias: event_id, message: description, tags: tags.join(','), recipients: recipients, teams: teams)
+ post_to_opsgenie(:create,
+ alias: event_id,
+ message: message,
+ description: description,
+ entity: client_name,
+ tags: tags.join(','),
+ recipients: recipients,
+ teams: teams)
end
def post_to_opsgenie(action = :create, params = {})
params['customerKey'] = @json_config['customerKey']