Skip to content
This repository has been archived by the owner on Dec 11, 2022. It is now read-only.

Proxy support for pagerduty #9

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/redphone/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ def http_request(options={})
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
end
unless options[:proxy_address].nil?
http.proxy_address = options[:proxy_address]
http.proxy_port = options[:proxy_port] || 8080
end
request_uri = uri.request_uri
unless parameters.empty?
request_uri += "?"
Expand Down
38 changes: 27 additions & 11 deletions lib/redphone/pagerduty.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,30 @@ module Redphone
class Pagerduty
def initialize(options={})
has_options(options, [:subdomain, :user, :password])
@subdomain = options[:subdomain]
@user = options[:user]
@password = options[:password]
@service_key = options[:service_key]
@subdomain = options[:subdomain]
@user = options[:user]
@password = options[:password]
@service_key = options[:service_key]
@proxy_address = options[:proxy_address]
@proxy_port = options[:proxy_port]
end

def self.integration_api(request_body)
response = http_request(
:method => "post",
:ssl => true,
:uri => "https://events.pagerduty.com/generic/2010-04-15/create_event.json",
:body => request_body.to_json
:method => "post",
:ssl => true,
:uri => "https://events.pagerduty.com/generic/2010-04-15/create_event.json",
:body => request_body.to_json,
:proxy_address => @proxy_address,
:proxy_port => @proxy_port
)
JSON.parse(response.body)
end

def self.trigger_incident(options={})
has_options(options, [:service_key, :description])
@proxy_address = options[:proxy_address]
@proxy_port = options[:proxy_port]
request_body = options.merge!({:event_type => "trigger"})
integration_api(request_body)
end
Expand All @@ -33,6 +39,8 @@ def trigger_incident(options={})

def self.resolve_incident(options={})
has_options(options, [:service_key, :incident_key])
@proxy_address = options[:proxy_address]
@proxy_port = options[:proxy_port]
request_body = options.merge!({:event_type => "resolve"})
integration_api(request_body)
end
Expand All @@ -44,6 +52,8 @@ def resolve_incident(options={})

def self.acknowledge_incident(options={})
has_options(options, [:service_key, :incident_key])
@proxy_address = options[:proxy_address]
@proxy_port = options[:proxy_port]
request_body = options.merge!({:event_type => "acknowledge"})
integration_api(request_body)
end
Expand All @@ -59,7 +69,9 @@ def incidents(options={})
:password => @password,
:ssl => true,
:uri => "https://#{@subdomain}.pagerduty.com/api/v1/incidents",
:parameters => options
:parameters => options,
:proxy_address = options[:proxy_address],
:proxy_port = options[:proxy_port]
)
JSON.parse(response.body)
end
Expand All @@ -70,7 +82,9 @@ def incidents_count(options={})
:password => @password,
:ssl => true,
:uri => "https://#{@subdomain}.pagerduty.com/api/v1/incidents/count",
:parameters => options
:parameters => options,
:proxy_address = options[:proxy_address],
:proxy_port = options[:proxy_port]
)
JSON.parse(response.body)
end
Expand All @@ -82,7 +96,9 @@ def schedules(options={})
:password => @password,
:ssl => true,
:uri => "https://#{@subdomain}.pagerduty.com/api/v1/schedules/#{options[:schedule_id]}/entries",
:parameters => options
:parameters => options,
:proxy_address = options[:proxy_address],
:proxy_port = options[:proxy_port]
)
JSON.parse(response.body)
end
Expand Down