Skip to content

Instantly share code, notes, and snippets.

@eurica
Last active December 18, 2015 21:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eurica/ee995180f4cdff5a9d2b to your computer and use it in GitHub Desktop.
Save eurica/ee995180f4cdff5a9d2b to your computer and use it in GitHub Desktop.
# This code is awful, don't fork it http://euri.ca/2013/ironworker-is-really-easy-to-use
def trigger
require 'net/http'
require "uri"
url = URI.parse('http://events.pagerduty.com/generic/2010-04-15/create_event.json')
request = Net::HTTP::Post.new(url.path)
request.content_type = 'application/json'
request.body = '{"service_key": "[APIKEY]","event_type": "trigger","description": "Something somewhere broke"}'
response = Net::HTTP.start(url.host, url.port) {|http| http.request(request) }
print response
end
def maybe_trigger
time = Time.new
prob = 0.05
prob += 0.02 if [9..17].include? time.hour # More errors during work hours
prob = 0.01 if [0,6].include? time.wday # less on weekends
prob = 0.2 if time.day == 1 # Something is wrong with a monthly batch job
prob += time.yday/10000.0 # gets worse over the year
r=rand()
if r < prob
print "Triggering #{r},#{prob} "
trigger()
else
print 'maybe next time'
end
end
maybe_trigger
runtime "ruby"
exec "trigger_pd.rb"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment