Sha256: 54f46548bb8f701394e5a4700c4491bf528bcc663e7d8efcd2a97d625881d58c

Contents?: true

Size: 1.68 KB

Versions: 11

Compression:

Stored size: 1.68 KB

Contents

#!/usr/bin/env ruby

require 'dotenv'
Dotenv.load ".env.development", '.env'

token = ENV['PAGERDUTY_TOKEN'] || raise("Missing ENV['PAGERDUTY_TOKEN'], add to .env.development")

require 'pager_duty/connection'
$pagerduty = PagerDuty::Connection.new(token)

schedule_id = ENV['PAGERDUTY_SCHEDULE_ID'] || raise("Missing ENV['PAGERDUTY_SCHEDULE_ID'], add to .env.development")

# pull down schedule entires for XXX schedule in the last day (ie who has been on call, and when
time_since = 1.day.ago
time_until = Time.now

# https://v2.developer.pagerduty.com/v2/page/api-reference#!/On-Calls/get_oncalls
response = $pagerduty.get("oncalls", query_params: { since: time_since, until: time_until, schedule_ids: [schedule_id] })

entries = response['oncalls']

entries.each do |entry|
  puts "#{entry['start']} - #{entry['end']}: #{entry['user']['summary']}"

  # find incidents during that shift
  # https://v2.developer.pagerduty.com/v2/page/api-reference#!/Incidents/get_incidents
  response = $pagerduty.get('incidents', query_params: { since: entry['start'], until: entry['end'], user_ids: [entry['user']['id']] })

  response['incidents'].each do |incident|
    puts "\t#{incident.id}"

    # find log entries (acknowledged, notifications, etc) for incident:
    # https://v2.developer.pagerduty.com/v2/page/api-reference#!/Incidents/get_incidents_id_log_entries
    response = $pagerduty.get("incidents/#{incident.id}/log_entries")

    # select just the notes
    notes = response['log_entries'].select do |log_entry|
      log_entry['channel'] && log_entry['channel']['type'] == 'note'
    end

    # and print them out:
    notes.each do |log_entry|
      puts "\t\t#{log_entry['channel']['summary']}"
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
pager_duty-connection-3.0.0 examples/shifts-with-incidents-and-log-entries.rb
pager_duty-connection-2.3.0 examples/shifts-with-incidents-and-log-entries.rb
pager_duty-connection-2.2.0 examples/shifts-with-incidents-and-log-entries.rb
pager_duty-connection-2.1.0 examples/shifts-with-incidents-and-log-entries.rb
pager_duty-connection-2.0.1 examples/shifts-with-incidents-and-log-entries.rb
pager_duty-connection-2.0.0 examples/shifts-with-incidents-and-log-entries.rb
pager_duty-connection-1.4.0 examples/shifts-with-incidents-and-log-entries.rb
pager_duty-connection-1.3.0 examples/shifts-with-incidents-and-log-entries.rb
pager_duty-connection-1.2.0 examples/shifts-with-incidents-and-log-entries.rb
pager_duty-connection-1.1.0 examples/shifts-with-incidents-and-log-entries.rb
pager_duty-connection-1.0.0 examples/shifts-with-incidents-and-log-entries.rb