Skip to content

Instantly share code, notes, and snippets.

@julianeon
Last active August 29, 2015 13:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save julianeon/8743617 to your computer and use it in GitHub Desktop.
Save julianeon/8743617 to your computer and use it in GitHub Desktop.
A script to create in incident in a given service.
require 'json'
subdomain="change_this"
api_key="change_this"
endpoint="https://events.pagerduty.com/generic/2010-04-15/create_event.json"
service_access_key="change_this"
incident_key="change_this"
subject="change_this"
client="change_this"
client_url="change_this"
details_hash={"ping time" => "1200ms", "load average" => "200ms"}
def curl_command_post_schedules(token_string,schedule_json,endpoint)
curl_command='curl -H "Content-type: application/json" -X POST -d '+schedule_json+' "'+endpoint+'"'
end
def hash_to_json(hash)
string=""
hash.each do |key,value|
string+='"'+key+'": "'+value+'", '
end
string
end
sched_json= '\'{
"service_key": "'+service_access_key+'",
"incident_key": "'+incident_key+'",
"event_type": "trigger",
"description": "'+subject+'",
"client": "'+client+'",
"client_url": "'+client_url+'" } }\''
curl_string = curl_command_post_schedules(api_key,sched_json,endpoint)
puts curl_string
system(curl_string)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment