Created
January 8, 2021 20:49
-
-
Save phumpal/f0a58698111a712e2c21a22d423a8ae2 to your computer and use it in GitHub Desktop.
Humanized mutator output for not-so-boring sensu-core alerts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"mutators": { | |
"glyphify": { | |
"command": "/etc/sensu/mutators/glyphify.rb" | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env ruby | |
# frozen_string_literal: true | |
# | |
# Custom 'Humanized' Sensu Mutator for Slack based alerts | |
# | |
# USAGE: | |
# | |
# | |
# NOTES: | |
# Compatible with sensu-core (Ruby) https://docs.sensu.io/sensu-core/latest/ | |
# | |
# LICENSE: | |
# Copyright (c) 2015-2020 Airbrake Technologies, Inc <[email protected]> | |
# Author Patrick Humpal <[email protected]> | |
# Released under the same terms as Sensu (the MIT license); see LICENSE | |
# for details. | |
require 'sensu-mutator' | |
class Glyphify < Sensu::Mutator | |
def human_check_status | |
case @event['check']['status'] | |
when 0 | |
'OK' | |
when 1 | |
'WARNING' | |
when 2 | |
'CRITICAL' | |
else | |
'UNKNOWN' | |
end | |
end | |
def mutate | |
dashboard_url = "https://IP-ADDRESS-OF-YOUR-SENSU-DASH" | |
dashboard_link = "#{dashboard_url}/#/client/sensu/#{@event['client']['name']}?check=#{@event['check']['name']}" | |
case @event['check']['status'] | |
when 0 | |
output = <<-BODY | |
Check Name: #{@event['check']['name']} | |
Status: #{human_check_status()} (#{@event['check']['status']}) | |
BODY | |
when 2 | |
output = <<-BODY | |
Check Name: #{@event['check']['name']} | |
Status: #{human_check_status()} (#{@event['check']['status']}) | |
Address: `#{@event['client']['address']}` | |
Dashboard Link: <#{dashboard_link}|Click here> for sensu dashboard | |
BODY | |
end | |
@event['check']['output'] = output | |
@event.merge!(:mutated => true) | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"icon_emoji": ":bell:", | |
"attachments": [ | |
{ | |
"fallback": "<%= @event["check"]["output"] %>", | |
"color": "<%= color %>", | |
"title": "<%= @event["client"]["name"] %>", | |
"text": "<%= @event["check"]["output"].gsub('"', '\\"') %>" | |
} | |
] | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%= | |
@event["check"]["output"] | |
%> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"handlers": { | |
"slack": { | |
"type": "pipe", | |
"mutator": "glyphify", | |
"command": "/etc/sensu/handlers/slack.rb" | |
} | |
}, | |
"slack": { | |
"webhook_url": "{{ sensu_slack_webhook }}", | |
"token": "{{ sensu_slack_token }}", | |
"channel": "#{{ sensu_slack_channel }}", | |
"message_template": "/etc/sensu/slack-template.eruby", | |
"payload_template": "/etc/sensu/slack-payload.eruby", | |
"bot_name": "sensu" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment