Skip to content

Instantly share code, notes, and snippets.

@htnosm
Created April 10, 2020 18:51
Show Gist options
  • Save htnosm/f5df0e30c0d095303b9f826ad6c424b0 to your computer and use it in GitHub Desktop.
Save htnosm/f5df0e30c0d095303b9f826ad6c424b0 to your computer and use it in GitHub Desktop.
PagerDuty の直近インシデントを取得するサンプルスクリプト
#!/bin/bash
# [REST API v2 Overview](https://v2.developer.pagerduty.com/docs/rest-api)
# [API Reference](https://developer.pagerduty.com/api-reference)
_TOKEN="" # REST API Key
_API_VERSION=2
_SERVICE_ID="" # service ID
_TIME_ZONE="Asia/Tokyo"
_LIMIT=100 # Def:25/Max:100
_SORT_BY="created_at:desc" # incident_number/created_at/resolved_at/urgency, asc/desc
_TIMEOUT=10
curl -XGET -sSf -m ${_TIMEOUT} \
-H "Authorization: Token token=${_TOKEN}" \
-H "Accept: application/vnd.pagerduty+json;version=${_API_VERSION}" \
"https://api.pagerduty.com/incidents?service_ids\[\]=${_SERVICE_ID}&time_zone=${_TIME_ZONE}&limit=${_LIMIT}&sort_by=${_SORT_BY}" \
| jq -r '.incidents[] | { incident_number, created_at, title, incident_key }' \
| jq -rs '(.[0]|keys_unsorted),map([.[]])[]|@csv'
@htnosm
Copy link
Author

htnosm commented Apr 10, 2020

Requirements

  • jq

Usage

  • TokenとServiceIDを指定して実行
  • 標準出力にcsv形式で出力される

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment