はじめに
OCI CLIでAutonomous Databaseのイベント・ベースの監視設定を行う手順を検証してみました。
今回は、Azure PortalのCloud ShellにOCI CLIをインストールし、そこからAutonomous Databaseのイベント・ベースの監視を設定しました。
注意
こちらの記事の内容はあくまで個人の実験メモ的な内容のため、こちらの内容を利用した場合のトラブルには一切責任を負いません。
また、こちらの記事の内容を元にしたOracleサポートへの問い合わせはご遠慮ください。
事前準備
こちらのマニュアルの手順に従って、Azure PortalのCloud ShellにOCI CLIをインストールします。
OCI CLIができたら、こちらのマニュアルの手順に従って、構成ファイルを設定します。
1. コンパートメントのOCIDの確認
SQL*Plus等のクライアントツールからAutonomous Databaseにadminユーザとして接続します。
[opc@tools ~]$ sqlplus admin@adb
SQL*Plus: Release 19.0.0.0.0 - Production on 火 10月 21 11:48:43 2025
Version 19.16.0.0.0
Copyright (c) 1982, 2022, Oracle. All rights reserved.
パスワードを入力してください:
最終正常ログイン時間: 火 10月 21 2025 11:46:49 +09:00
Oracle Database 23ai Enterprise Edition Release 23.0.0.0.0 - for Oracle Cloud and Engineered Systems
Version 23.10.0.25.10
に接続されました。
SQL>
以下のSQLを実行して、Autonomous Databaseが属するコンパートメントのOCIDを確認します。
SELECT JSON_VALUE(cloud_identity, '$.COMPARTMENT_OCID') outbound_id_address FROM v$pdbs;
SQL> set linesize 100
SQL> SELECT JSON_VALUE(cloud_identity, '$.COMPARTMENT_OCID') compartment_ocid FROM v$pdbs;
COMPARTMENT_OCID
----------------------------------------------------------------------------------------------------
ocid1.compartment.oc1..aaaaaaaaa4xfcxvm53g6kqpnjfsgdgiwtzwg425jsusnrm3hg43mkrltfdkq
SQL>
2. トピックの作成
イベントが発生した際に通知を行うためのトピックを作成します。
環境変数を設定します。
| 環境変数 | 値 |
|---|---|
| compartment_id | 1で取得したコンパートメントのOCID |
| topic_name | 作成するトピックの名前(ここではMyEmail) |
export compartment_id="ocid1.compartment.oc1..aaaaaaaaezrpv3jesejnvv5wm2x7xpk27cemvhrjco4wtennw74w7f3i2ixa"
export topic_name="MyEmail"
azureuser [ ~ ]$ export compartment_id="ocid1.compartment.oc1..aaaaaaaaezrpv3jesejnvv5wm2x7xpk27cemvhrjco4wtennw74w7f3i2ixa"
azureuser [ ~ ]$ export topic_name="MyEmail"
oci ons topic createコマンドでトピックを作成します。
ここではトピックの作成と同時に、環境変数topic_idに作成されたトピックのOCIDをセットしています。
export topic_id=$(oci ons topic create --compartment-id $compartment_id --name $topic_name --query 'data."topic-id"' --raw-output)
azureuser [ ~ ]$ export topic_id=$(oci ons topic create --compartment-id $compartment_id --name $topic_name --query 'data."topic-id"' --raw-output)
OCIコンソールで確認すると、「MyEmail」というトピックが作成されていることがわかりました。

3. サブスクリプションの作成
イベントが発生した際の通知先となるサブスクリプションを作成します。
環境変数を設定します。
| 環境変数 | 値 |
|---|---|
| protocol | |
| subscription_endpoint | 通知の宛先メールアドレス |
export protocol="EMAIL"
export subscription_endpoint="xxxxxxxxx@xxxxxx.com"
azureuser [ ~ ]$ export protocol="EMAIL"
azureuser [ ~ ]$ export subscription_endpoint="xxxxxxxxx@xxxxxx.com"
oci ons subscription createコマンドでサブスクリプションを作成します。
oci ons subscription create --compartment-id $compartment_id --protocol $protocol --subscription-endpoint $subscription_endpoint --topic-id $topic_id
azureuser [ ~ ]$ oci ons subscription create --compartment-id $compartment_id --protocol $protocol --subscription-endpoint $subscription_endpoint --topic-id $topic_id
{
"data": {
"compartment-id": "ocid1.compartment.oc1..aaaaaaaaezrpv3jesejnvv5wm2x7xpk27cemvhrjco4wtennw74w7f3i2ixa",
"created-time": 1761011730361,
"defined-tags": {
"Oracle-Tags": {
"CreatedBy": "default/******@*******.com",
"CreatedOn": "2025-10-21T01:55:30.317Z"
}
},
"deliver-policy": "{\"maxReceiveRatePerSecond\":0,\"backoffRetryPolicy\":{\"initialDelayInFailureRetry\":60000,\"maxRetryDuration\":7200000,\"policyType\":\"EXPONENTIAL\"}}",
"endpoint": "xxxxxxxxx@xxxxxx.com",
"etag": "5f78b838",
"freeform-tags": {},
"id": "ocid1.onssubscription.oc1.ap-tokyo-1.aaaaaaaaxsla66bqpzab3a5irmscovjultfely5unyzbo4cbc7xpfyruvbla",
"lifecycle-state": "PENDING",
"protocol": "EMAIL",
"topic-id": "ocid1.onstopic.oc1.ap-tokyo-1.amaaaaaaolwnn3yavisiaxvvjc7dbkwtc4j4hr37jc67hvzva4qmiaj4tg7a"
},
"etag": "5f78b838--gzip"
}
azureuser [ ~ ]$
サブスクリプションを作成すると、subscription_endpointで指定した通知の宛先メールアドレスに確認のためのメールが送信されます。
メールを受信したら、メール内の「Confirm subscription」をクリックします。
サブスクリプションへの登録が確認された旨のページが表示されます。
OCIコンソールで確認すると、サブスクリプションが作成されていることがわかりました。
4. イベント・ルールの作成
oci events rule createコマンドで使用するactions.jsonファイルを作成するためのテンプレートactions.templateを作成します。
{
"actions": [
{
"actionType": "ONS",
"description": "MyEMail",
"isEnabled": true,
"topicId": "TOPIC_ID"
}
]
}
sedコマンドでactions.template内のTOPIC_IDを作成したトピックのOCIDで置き換えます。
sed s/TOPIC_ID/$topic_id/ actions.template > actions.json
azureuser [ ~ ]$ sed s/TOPIC_ID/$topic_id/ actions.template > actions.json
actions.jsonの内容を確認します。
azureuser [ ~ ]$ cat actions.json
{
"actions": [
{
"actionType": "ONS",
"description": "MyEMail",
"isEnabled": true,
"topicId": "ocid1.onstopic.oc1.ap-tokyo-1.amaaaaaaolwnn3yavisiaxvvjc7dbkwtc4j4hr37jc67hvzva4qmiaj4tg7a"
}
]
}
azureuser [ ~ ]$
環境変数を設定します。
| 環境変数 | 値 |
|---|---|
| event_display_name | 作成するイベントルールの名前 (ここではADB_Information_and_Critical) |
| condition | アクションをトリガーするイベントの条件 (ここでは「Autonomous Database - Information」と「Autonomous Database - Critical」) |
Autonomous Databaseで利用可能なイベントの種類や詳細はこちらのマニュアルを参照
export event_display_name="ADB_Information_and_Critical"
export condition="{\"eventType\":[\"com.oraclecloud.databaseservice.autonomous.database.critical\",\"com.oraclecloud.databaseservice.autonomous.database.information\"]}"
azureuser [ ~ ]$ export event_display_name="ADB_Information_and_Critical"
azureuser [ ~ ]$ export condition="{\"eventType\":[\"com.oraclecloud.databaseservice.autonomous.database.critical\",\"com.oraclecloud.databaseservice.autonomous.database.information\"]}"
oci events rule createコマンドを使用して、イベント・ルールを作成します。
oci events rule create --display-name $event_display_name --compartment-id $compartment_id --condition $condition --actions file://actions.json --is-enabled true
azureuser [ ~ ]$ export condition="{\"eventType\":[\"com.oraclecloud.databaseservice.autonomous.database.critical\",\"com.oraclecloud.databaseservice.autonomous.database.information\"]}"
azureuser [ ~ ]$ oci events rule create --display-name $event_display_name --compartment-id $compartment_id --condition $condition --actions file://actions.json --is-enabled true
{
"data": {
"actions": {
"actions": [
{
"action-type": "ONS",
"description": "MyEMail",
"id": "ocid1.eventaction.oc1.ap-tokyo-1.abxhiljrhbngrwikd5z4r22ftfufwwmkhz2rcuxwkqign2qjy27xg2zrnxpq",
"is-enabled": true,
"lifecycle-message": null,
"lifecycle-state": "ACTIVE",
"topic-id": "ocid1.onstopic.oc1.ap-tokyo-1.amaaaaaaolwnn3yavisiaxvvjc7dbkwtc4j4hr37jc67hvzva4qmiaj4tg7a"
}
]
},
"compartment-id": "ocid1.compartment.oc1..aaaaaaaaezrpv3jesejnvv5wm2x7xpk27cemvhrjco4wtennw74w7f3i2ixa",
"condition": "{\"eventType\":[\"com.oraclecloud.databaseservice.autonomous.database.critical\",\"com.oraclecloud.databaseservice.autonomous.database.information\"]}",
"defined-tags": {
"Oracle-Tags": {
"CreatedBy": "default/****@**********.com",
"CreatedOn": "2025-10-21T04:30:44.899Z"
}
},
"description": null,
"display-name": "ADB_Information_and_Critical",
"freeform-tags": {},
"id": "ocid1.eventrule.oc1.ap-tokyo-1.amaaaaaaolwnn3yaesw773vx4jma3tbrpnukhmgp7rdet3g6ivdeck5fqehq",
"is-enabled": true,
"lifecycle-message": null,
"lifecycle-state": "ACTIVE",
"time-created": "2025-10-21T04:30:45.081000+00:00"
},
"etag": "4daf42113737578cf443c701f14c8e4f3de20d24cf1d99fc1b3ae36e614ee21f--gzip"
}
azureuser [ ~ ]$
OCIコンソールで確認すると、イベント・ルールが作成されていることがわかりました。
イベント・ルール名をクリックすると詳細が表示されます。
左側のResourceセクションにある「イベントの一致」をクリックします。
イベント・タイプとして「Autonomous Database - Critical」と「Autonomous Database - Information」が設定されていることが確認できました。
左側のResourceセクションにある「アクション」をクリックします。
アクション・タイプが「通知」で通知先のトピックが「MyEmail」のアクションが登録されていることが確認できました。
この設定によって、「Autonomous Database - Critical」または「Autonomous Database - Information」のイベントが発生した場合に、トピック「MyEmail」に関連づけられているサブスクリプションに登録されているメールアドレスに通知が送られます。
以上で、OCI CLIを使用して、Autonomous Databaseのイベント・ベースの監視を設定できることが確認できました。








