Created
March 14, 2016 18:10
-
-
Save anroots/1d776dcdbce1a4373223 to your computer and use it in GitHub Desktop.
Fleep.io handler for Sensu monitoring
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 | |
# | |
# DESCRIPTION: | |
# This handler formats Sensu alerts and sends them off to a Fleep.io webhook. | |
# | |
# OUTPUT: | |
# | |
# PLATFORMS: | |
# All | |
# | |
# DEPENDENCIES: | |
# gem: json | |
# | |
# USAGE: | |
# | |
# LICENSE: | |
# Released under the same terms as Sensu (the MIT license); see LICENSE | |
# for details. | |
require 'net/http' | |
require 'json' | |
event = JSON.parse(ARGF.read) | |
short_name = event['client']['name'] + ' / ' + event['check']['name'] | |
action = event['action'].eql?('resolve') ? 'RESOLVED' : 'ALERT' | |
subject = "#{action} - #{short_name}: #{event['check']['notification']}" | |
body = <<-BODY.gsub(/^ {14}/, '') | |
#{subject} | |
> #{event['check']['output']} | |
*Host:* #{event['client']['name']} | |
*Timestamp:* #{Time.at(event['check']['issued'])} | |
*Address:* #{event['client']['address']} | |
*Check Name:* #{event['check']['name']} | |
*Command:* #{event['check']['command']} | |
*Status:* #{event['check']['status']} | |
*Occurrences:* #{event['occurrences']} | |
BODY | |
response = Net::HTTP.post_form(URI.parse('https://fleep.io/hook/'+ENV['FLEEP_HOOK_ID']), {'message'=>body}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment