-
-
Save eurica/ee995180f4cdff5a9d2b to your computer and use it in GitHub Desktop.
This file contains 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
# 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 |
This file contains 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
runtime "ruby" | |
exec "trigger_pd.rb" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment