Skip to content

Instantly share code, notes, and snippets.

@NetworksAreMadeOfString
Created June 10, 2012 14:34
Show Gist options
  • Save NetworksAreMadeOfString/2905942 to your computer and use it in GitHub Desktop.
Save NetworksAreMadeOfString/2905942 to your computer and use it in GitHub Desktop.
http = Net::HTTP.new("#{pagerduty_subdomain}.pagerduty.com", 443)
http.use_ssl = true
path = "/api/v1/schedules/#{pagerduty_schedule}/entries?since=#{Year}-#{Month}-#{Day}&until=#{Year}-#{Month}-#{Day}"
req = Net::HTTP::Get.new(path)
req.basic_auth pagerduty_username, pagerduty_password
resp, data = http.request(req)
#Check if the response code was a good 200
if resp.code.to_i == 200
puts "Received a 200 response"
PagerDutyJSON = JSON.parse(data)
#Do we have any entries in the returned JSON
if PagerDutyJSON.has_key? 'entries'
OnCallUser = PagerDutyJSON['entries'][0]['user']['name']
OnCallNumber = ContactDetails[OnCallUser].to_s()
puts "On call person is #{OnCallUser} which makes their contact details: #{OnCallNumber}"
system("#{asterisk_path} -rx \"database put #{asterisk_db} #{asterisk_key} #{OnCallNumber}\"")
else
#Don't change the file
puts "An error decoding the JSON occured"
end
else
#Don't change the file
puts "An error occured"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment