Datadog公式のツール dog 使用方法まとめ downtime 編です。

目次
downtime Modes
downtime 設定を行います。

| サブコマンド | 説明 |
|---|---|
| show | ダウンタイム情報出力 |
| show_all | 全ダウンタイム情報出力 |
| post | ダウンタイムスケジュール作成 |
| update | ダウンタイムスケジュール更新 |
| delete | ダウンタイムスケジュール削除 |
show
ダウンタイム情報を出力します。
usage: dog downtime show [-h] downtime_id
実行例
JSON 形式で出力されます。
$ downtime_id=XXXXXXXX2
$ dog downtime show ${downtime_id} | jq '.'
{
"recurrence": null,
"end": null,
"parent_id": null,
"monitor_id": null,
"start": NNNNNNNNN4,
"disabled": false,
"canceled": null,
"creator_id": XXXXX8,
"scope": [
"host:i-XXXXXXXX"
],
"active": true,
"timezone": "UTC",
"message": null,
"id": XXXXXXXX2,
"updater_id": null
}
show_all
全ダウンタイム情報を出力します。
usage: dog downtime show_all [-h] [--current_only CURRENT_ONLY]
optional arguments:
| ロングオプション | 説明 |
|---|---|
| –current_only | CURRENT_ONLY を指定。active=true のみ出力 |
実行例
オプション無し
JSON 形式で出力されます。 active = false (Web画面上表示されない) 設定も含めて返却されます。
$ dog downtime show_all | jq '.'
[
{
"recurrence": null,
"end": null,
"parent_id": null,
"monitor_id": null,
"start": NNNNNNNNN1,
"disabled": true,
"canceled": NNNNNNNNN6,
"creator_id": XXXXX8,
"scope": [
"host:i-XXXXXXXX"
],
"active": false,
"timezone": "UTC",
"message": null,
"id": XXXXXXXX3,
"updater_id": XXXXX8
},
・・・略
{
"recurrence": null,
"end": null,
"parent_id": null,
"monitor_id": XXXXXXXX8,
"start": NNNNNNNNN4,
"disabled": false,
"canceled": null,
"creator_id": XXXXX8,
"scope": [
"*"
],
"active": true,
"timezone": "UTC",
"message": "Monitor muted from web",
"id": XXXXXXXX9,
"updater_id": null
},
・・・略
}
]
current_only オプション
active = true (Web画面上表示される) 設定のみ返却されます。
ロングオプション指定のみではなく、--current_only CURRENT_ONLY の記述が必要です。
$ dog downtime show_all --current_only CURRENT_ONLY | jq '.'
[
{
"recurrence": null,
"end": null,
"parent_id": null,
"monitor_id": null,
"start": NNNNNNNNN4,
"disabled": false,
"canceled": null,
"creator_id": XXXXX8,
"scope": [
"host:i-XXXXXXXX"
],
"active": true,
"timezone": "UTC",
"message": null,
"id": XXXXXXXX2,
"updater_id": null
},
{
"recurrence": null,
"end": null,
"parent_id": null,
"monitor_id": null,
"start": NNNNNNNNN7,
"disabled": false,
"canceled": null,
"creator_id": null,
"scope": [
"host:i-XXXXXXXXXXXXXXXXX"
],
"active": true,
"timezone": "UTC",
"message": "This manually stopped or terminated AWS instance has been automatically silenced by Datadog.\n\nAWS reported host i-XXXXXXXXXXXXXXXXX as 'stopping' with the reason: 'Client.UserInitiatedShutdown: User initiated (yyyy-mm-dd hh:mm:ss GMT)'",
"id": XXXXXXXX1,
"updater_id": null
},
{
"recurrence": null,
"end": null,
"parent_id": null,
"monitor_id": XXXXXXXX8,
"start": NNNNNNNNN4,
"disabled": false,
"canceled": null,
"creator_id": XXXXX8,
"scope": [
"*"
],
"active": true,
"timezone": "UTC",
"message": "Monitor muted from web",
"id": XXXXXXXX9,
"updater_id": null
}
]
自動で作成される automatically muted hosts のダウンタイムも含みます。

post
ダウンタイムスケジュールを作成します。
usage: dog downtime post [-h] [--end END] [--message MESSAGE] scope start
Monitor 指定、繰り返しスケジュールは未サポートです。 APIとしては存在します。(monitor_id指定はドキュメント記載が無いです。)

positional arguments:
| 引数 | 説明 |
|---|---|
| scope | 適用対象タグ |
| start | 開始日時を指定。POSIX timestamp |
optional arguments:
| ロングオプション | 説明 |
|---|---|
| –end | 終了日時を指定。POSIX timestamp。指定無しの場合は forever(無限) |
| –message | 関連付けるメッセージ本文 |
実行例
オプション無し
スコープ、開始日時を指定する必要があります。(現在日時の自動設定はありません)
$ dog downtime post "*" "$(date +'%s')" | jq '.'
{
"recurrence": null,
"end": null,
"parent_id": null,
"monitor_id": null,
"start": NNNNNNNNN9,
"disabled": false,
"canceled": null,
"creator_id": XXXXX8,
"scope": [
"*"
],
"active": true,
"timezone": "UTC",
"message": null,
"id": XXXXXXXX4,
"updater_id": null
}
message オプション
downtime にメッセージを関連付けます。各種通知を行うことも可能です。
$ dog downtime post --end "$(date -d '1 hour' +'%s')" --message "1時間止めます @slack-xxxxxx" "*" "$(date +'%s')" | jq '.'
{
"recurrence": null,
"end": NNNNNNNNN3,
"parent_id": null,
"monitor_id": null,
"start": NNNNNNNNN3,
"disabled": false,
"canceled": null,
"creator_id": XXXXX8,
"scope": [
"*"
],
"active": true,
"timezone": "UTC",
"message": "1時間止めます @slack-xxxxxx",
"id": XXXXXXXX8,
"updater_id": null
}

- Slackへの通知例

update
ダウンタイムスケジュールを更新します。post とほぼ同じ構文で、対象の downtime_id を指定します。
scope,start は必須オプションではなくなっています。(部分更新可能)
usage: dog downtime update [-h] [--scope SCOPE] [--start START] [--end END]
[--message MESSAGE]
downtime_id
実行例
$ dog downtime update --start "$(date -d '1 hour' +'%s')" --end "$(date -d '2 hour' +'%s')" --message "開始を1時間遅らせます" ${downtime_id} | jq '.'
{
"recurrence": null,
"end": NNNNNNNNN1,
"parent_id": null,
"monitor_id": null,
"start": NNNNNNNNN1,
"disabled": false,
"canceled": null,
"creator_id": XXXXX8,
"scope": [
"*"
],
"active": false,
"timezone": "UTC",
"message": "開始を1時間遅らせます",
"id": XXXXXXXX8,
"updater_id": XXXXX8
}

start > end を指定した場合はエラーとなります。
$ dog downtime update --start "$(date -d '2 hour' +'%s')" --end "$(date -d '1 hour' +'%s')" --message "start > end で指定" ${downtime_id} | jq '.'
ERROR: Downtime cannot end before it begins
delete
ダウンタイムスケジュールを削除します。
usage: dog downtime delete [-h] downtime_id
実行例
レスポンスはありません。 disabled = true が設定されます。(WebUI上は表示されなくなります。)
$ dog downtime delete ${downtime_id}
$
$ dog downtime show ${downtime_id} | jq '.'
{
"recurrence": null,
"end": NNNNNNNNN1,
"parent_id": null,
"monitor_id": null,
"start": NNNNNNNNN1,
"disabled": true,
"canceled": XXXXXXXX8,
"creator_id": XXXXX8,
"scope": [
"*"
],
"active": false,
"timezone": "UTC",
"message": "開始を1時間遅らせます",
"id": XXXXXXXX8,
"updater_id": XXXXX8
}