カスタム Agent チェックを使用したイベント

送信

カスタム Agent チェックからイベントを送信するには、以下の event(<イベント_辞書>) 関数を使用します。

self.event(
            {
              "timestamp": <タイムスタンプ_エポック>,
              "event_type": "<イベント名>",
              "msg_title": "<タイトル>",
              "msg_text": "<メッセージ>",
              "aggregation_key": "<集計キー>",
              "alert_type": "<アラートタイプ>",
              "source_type_name": "<ソースタイプ>",
              "host": "<ホスト名>",
              "tags": ["<タグ>"],
              "priority": "<優先度>"
            }
)

イベントの辞書では、以下のキーとデータ型を使用できます。

キータイプ必須説明
timestamp整数はいイベントのエポックタイムスタンプ
event_type文字列はいイベント名
msg_title文字列はいイベントのタイトル
msg_text文字列はいイベントのテキスト本文
aggregation_key文字列イベントを集計するために使用するキー
alert_type文字列errorwarningsuccess、または info (デフォルトは info)
source_type_name文字列ソースタイプの名前
host文字列ホスト名
tags文字列のリストこのイベントに関連付けられるタグのリスト
priority文字列イベントの優先度を指定します (normal または low)。

カスタム Agent チェックを使用して、1 つのイベントを定期的に送信する例を示します。詳細については、カスタム Agent チェックの書き方を参照してください。

  1. Agent のコンフィギュレーションディレクトリのルートにある conf.d/ フォルダーに、ディレクトリ event_example.d/ を作成します。

  2. event_example.d/ フォルダーに次の内容でコンフィギュレーションファイルを作成し、event_example.yaml と名付けます。

    instances: [{}]
    
  3. conf.d/ フォルダーから階層を 1 つ上がり、checks.d/ フォルダーに移動します。

  4. このフォルダーに次の内容でカスタムチェックファイルを作成し、event_example.py と名付けます。

    event_example.py

        from datadog_checks.base import AgentCheck
    
        __version__ = "1.0.0"
    
        class MyClass(AgentCheck):
            def check(self, instance):
                self.event(
                    {
                        "timestamp": time.time(),
                        "event_type": "Error",
                        "msg_title": "サンプルイベント",
                        "msg_text": "これは Datadog から送られたサンプルのイベントです。",
                        "alert_type": "error",
                    }
                )
        
  5. Agent を再起動します

  6. 検証するには、Agent の status コマンドを実行し、Checks セクションで event_example を探します。

    =========
    Collector
    =========
    
      Running Checks
      ==============
    
        (...)
    
        event_example (1.0.0)
        ---------------------
          Instance ID: event_example:d884b5186b651429 [OK]
          Total Runs: 2
          Metric Samples: Last Run: 0, Total: 0
          Events: Last Run: 1, Total: 2
          Service Checks: Last Run: 0, Total: 0
          Average Execution Time : 0s
    
        (...)
    

その他の参考資料

お役に立つドキュメント、リンクや記事: