Last active
August 29, 2015 14:06
-
-
Save danielhopkins/8137bdc71624d0049a7a to your computer and use it in GitHub Desktop.
enhanced webhooks post
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
require 'rubygems' | |
require 'sinatra' | |
# Enter your API key from the REST integration tab | |
$API_KEY = "API_KEY" | |
# Download the basic vo.rb from https://gist.github.com/danielhopkins/7569899 | |
$VO_RB = '~/bin/vo.rb' | |
post '/webhook' do | |
state = params['entity_state'].gsub('"', '') | |
service_group = params['servicegroupname'].gsub('"', '') rescue '' | |
entity_id = params['entity_id'].gsub('"', '') | |
# Come up with creative criteria for scheduling auto resolves | |
if state == 'CRITICAL' && service_group =~ /things_to_ignore/ | |
puts 'Resolving that' | |
schedule_resolve(entity_id, 10) | |
end | |
'Ok' | |
end | |
def schedule_resolve(entity_id, minutes_from_now) | |
cmd = "vo.rb -k '#{$API_KEY}' --type recovery --entity '#{entity_id}'" | |
if(minutes_from_now == 0) | |
`#{cmd}` | |
else | |
# A little unix goodness to delay sending a resolve | |
`echo "#{cmd}" | at now +#{minutes_from_now} minute` | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment