Created
April 10, 2020 18:51
-
-
Save htnosm/f5df0e30c0d095303b9f826ad6c424b0 to your computer and use it in GitHub Desktop.
PagerDuty の直近インシデントを取得するサンプルスクリプト
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Requirements
Usage