Class: Tapjoy::PagerDuty::Base
- Inherits:
-
Object
- Object
- Tapjoy::PagerDuty::Base
- Defined in:
- lib/tapjoy/pagerduty/base.rb
Instance Method Summary collapse
- #get_incidents(query_start:, query_end:) ⇒ Object
-
#get_schedule_id(schedule_name) ⇒ Object
Given the name of a schedule return the schedule_id that pagerduty uses for lookups.
-
#get_user_details(user_id) ⇒ Object
Given a specific user, return all details about the user that we can parse through as needed.
-
#get_user_id(email) ⇒ Object
Given an email address return the user_id that pagerduty uses for lookups.
-
#get_users_on_call ⇒ Object
Return all users on call for all schedules, which we can parse through later.
-
#initialize ⇒ Base
constructor
Initializer services to import values from pg_connect.yaml to configure organization-specific values (currently, subdomain and api_token).
-
#post_trigger(service_key:, incident_key:, description:, client:, client_url:, details:) ⇒ Object
Create a page to the first person on call for a given service key.
-
#set_override(query_start:, query_end:, override_start:, override_end:, user_id:, schedule_id:) ⇒ Object
The set_override method takes in several variables and returns the REST response upon (attempting) completion of an override action.
Constructor Details
#initialize ⇒ Base
Initializer services to import values from pg_connect.yaml to configure organization-specific values (currently, subdomain and api_token)
7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/tapjoy/pagerduty/base.rb', line 7 def initialize config_file = "#{ENV['PAGERDUTY_CONFIG_DIR'] ? ENV['PAGERDUTY_CONFIG_DIR'] + 'pgconnect.yml' : ENV['HOME'] + '/.pgutils/pgconnect.yaml'}" pg_conn = YAML.load_file(config_file) if File.readable?(config_file) @AUTH_HEADER = { subdomain: ENV['PAGERDUTY_SUBDOMAIN'] || pg_conn[:subdomain], token_string: "Token token=#{ENV['PAGERDUTY_API_TOKEN'] || pg_conn[:api_token]}" } raise 'Missing subdomain value' if @AUTH_HEADER[:subdomain].nil? raise 'Missing API token' if @AUTH_HEADER[:token_string].nil? end |
Instance Method Details
#get_incidents(query_start:, query_end:) ⇒ Object
85 86 87 88 89 90 |
# File 'lib/tapjoy/pagerduty/base.rb', line 85 def get_incidents(query_start:, query_end:) since_date = Date.today - query_start until_date = since_date + query_end endpoint = "#{return_pagerduty_url(:incidents)}?since=#{since_date}&until=#{until_date}" return get_object(endpoint) end |
#get_schedule_id(schedule_name) ⇒ Object
Given the name of a schedule return the schedule_id that pagerduty uses for lookups
28 29 30 31 32 |
# File 'lib/tapjoy/pagerduty/base.rb', line 28 def get_schedule_id(schedule_name) endpoint = return_pagerduty_url(:schedules) out_array = get_object(endpoint)['schedules'].select { |i| i['name'].eql?(schedule_name)} return Hash[*out_array]['id'] end |
#get_user_details(user_id) ⇒ Object
Given a specific user, return all details about the user that we can parse through as needed
61 62 63 64 |
# File 'lib/tapjoy/pagerduty/base.rb', line 61 def get_user_details(user_id) endpoint = return_pagerduty_url(:users) + "/#{user_id}/on_call" return get_object(endpoint) end |
#get_user_id(email) ⇒ Object
Given an email address return the user_id that pagerduty uses for lookups
21 22 23 24 25 |
# File 'lib/tapjoy/pagerduty/base.rb', line 21 def get_user_id(email) endpoint = return_pagerduty_url(:users) out_array = get_object(endpoint)['users'].select { |i| i['email'].eql?(email) } return Hash[*out_array]['id'] end |
#get_users_on_call ⇒ Object
Return all users on call for all schedules, which we can parse through later
54 55 56 57 |
# File 'lib/tapjoy/pagerduty/base.rb', line 54 def get_users_on_call endpoint = return_pagerduty_url(:escalation_on_call) return get_object(endpoint) end |
#post_trigger(service_key:, incident_key:, description:, client:, client_url:, details:) ⇒ Object
Create a page to the first person on call for a given service key
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/tapjoy/pagerduty/base.rb', line 67 def post_trigger(service_key:, incident_key:, description:, client:, client_url:, details:) # Ruby 2.x style kw-args is required here to make hash passing easier endpoint = return_pagerduty_url(:create_trigger) data = { service_key: service_key, incident_key: incident_key, event_type: 'trigger', description: description, client: client, client_url: client_url, details: details, } post_object(endpoint, data) end |
#set_override(query_start:, query_end:, override_start:, override_end:, user_id:, schedule_id:) ⇒ Object
The set_override method takes in several variables and returns the REST response upon (attempting) completion of an override action
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/tapjoy/pagerduty/base.rb', line 36 def set_override(query_start:, query_end:, override_start:, override_end:, user_id:, schedule_id:) # Ruby 2.x style kw-args is required here to make hash passing easier endpoint = "#{return_pagerduty_url(:schedules)}/#{schedule_id}/overrides?since=#{query_start}&until=#{query_end}" data = { override: { user_id: user_id, start: override_start, end: override_end, } } post_object(endpoint, data) end |