• 使用を開始する
  • 関連ドキュメント

Opsgenie アラートからステータス ページを生成する

This is the reference implementation to generate status pages from Opsgenie alerts. The solution uses Opsgenie Webhook Integration on alert actions (Create, Close, AddTags, RemoveTags, etc.) to trigger code that is used to calculate and update the state of your services according to the severity of the alerts. To implement such a solution, the following components would be needed:

  • コードを実行する環境

  • 上記のようにコード実行をトリガーする環境

  • ストレージ — サービス データを保持する

  • ステータス ページをホストする Web サーバー

  • アラート データを渡すための Opsgenie における Webhook 統合

ここで説明するリファレンス実装では、AWS API ゲートウェイ、Lambda、S3 の各サービスを活用します。

連携

アラートの設計

このソリューションでは、ステータス ページを作成して更新する際に使用する必要があるアラートには、次があることを前提としています。

  • “statuspage”.このタグを持つアラートのみが処理されます。

  • サービスの名前影響を受けるサービスの名前は、“servicename:” プレフィックスが付いたタグとして含まれます。たとえば、“servicename:website” です

  • インシデントの重大度。ソリューションは、インシデントに対するさまざまな重大度のレベルをサポートします。アラートには重大度を示すタグを付ける必要があり、「安全」、「重大」、「致命的」がサポートされる重要度レベルです。

Service State Calculator Lambda 関数

AWS Lambda is is the new compute service from AWS that lets you run your code without provisioning or managing any servers, practically with zero administration. and as you pay only for the time you consume, it’s practically free for these type of applications. Just upload your code and Lambda takes care of everything required to run and scale your code with high availability.

Lambda サービスは、イベントによってトリガーされた「関数」と呼ばれるコードを実行します。この関数はトリガーされるたびに実行されて、スケジュールされたイベントや API Gateway などの異なるソースによってトリガーできます。

この実装では、Opsgenie でアラートが作成されて更新されると、AWS API Gateway を介して Opsgenie によって Lambda 関数がトリガーされます。Lambda 関数は Opsgenie Webhook インテグレーションを介して Opsgenie アラート更新 (Create、Close、AddTags、RemoveTags など) を受け取って、以下に説明するロジックで状態を計算します。

Opsgenie で実行されたアラート アクションが “Create” または “AddTags” の場合:

  1. サービスの現在の状態を取得する

  2. アラートの重大度と比較する

  3. アラートの重大度が現在のサービス状態よりも高い場合は、サービス状態をアップデートする

Opsgenie で実行されたアラート アクションが “Close” または “RemoveTags” の場合:

  1. Alert API を使用して、残りのサービス アラートを取得します。

  2. すべてのアラートの重大度タグを確認して、サービスの状態として重大度を最高に設定します。

  3. サービスの状態を更新します。

Lambda 関数は config.js で次のように設定されます。

テキスト

var config = { "opsgenieApiKey": "", // the API key of the API Integration in Opsgenie, which will be used to retrieve service's incident alerts. "serviceObjectBucket" : "", // name of the S3 bucket that stores the service data "statusPageTag": "statuspage", // identifier tag for the statuspage incidents "accessKeyId": "", // accessKeyId of the user credentials which has fullAccessRight to S3 "secretAccessKey": "", // secretAccessKey of the user credentials which has fullAccessRight to S3 "serviceNameTagPrefix": "servicename:", // tag prefix for service names in statuspage alerts. // (ex: servicename:service1 -> service name will be extracted as service1) "serviceDataFolderNameInS3": "services" //folder of the service objects in S3 bucket };

Lambda 関数をトリガーする AWS API Gateway

AWS API Gateway is a service that grants you the ability to easily create, publish and maintain APIs, and can provide a URL endpoint to trigger Lambda functions. This solution uses three Lambda functions: one for calculating service state, one for retrieving incident alerts and alert notes from Opsgenie and one for retrieving service state data from S3. After creating the Lambda functions -- create an API endpoint for each of them. Please make sure that you enabled CORS for each API source.

To secure these Lambda functions, the API Key should be used in API Gateway. Once an API Gateway is enabled to use the API Key, every HTTP/HTTPS call made to these endpoints must contain the API Key as part of the request. It also must be sent in X-Api-Key header.

S3 へサービス データを保存する

AWS S3 is a secure and scalable object storage service. When the Service State Calculator Lambda function triggered through API Gateway, Lambda function calculates new service state and puts service data to AWS S3 bucket.

サービス データは、次の形式のサービス情報を含む JSON ファイルです。

テキスト

{ "state": "critical", "message": " API Outage." }

S3 Lambda 関数の Service Data Getter

It retrieves the specific data for a service or all services from S3. It is then triggered via the API Gateway endpoint by the Status Page web application. It should be configured from config.js

テキスト

var config = { "serviceObjectBucket" : "", // name of the S3 bucket that stores the service data "accessKeyId": "", // accessKeyId of the user credentials which has fullAccessRight to S3 "secretAccessKey": "", // secretAccessKey of the user credentials which has fullAccessRight to S3 "serviceDataFolderNameInS3": "services" //folder of the service objects in S3 bucket };

インシデント アラートとアラート メモ取得のための Lambda 関数

The Lambda function retrieves a given service's alerts and alert notes from Opsgenie through the Alert API. It gets triggered by its API Gateway endpoint via the Status Page web application. It should be configured from config.js

テキスト

var config = { "opsgenieApiKey": "", // the API key of the API Integration in Opsgenie, which will be used to retrieve service's incident alerts. "statusPageTag": "statuspage", // identifier tag for the statuspage incidents "serviceNameTagPrefix": "servicename:" // tag prefix for service names in statuspage alerts. //(ex: servicename:service1 -> service name will be extracted as service1) };

Opsgenie で Webhook インテグレーションを設定する

Opsgenie は、Webhook 統合を介してカスタム URL エンドポイントにアラート データを送信します。統合では、Service State Calculator Lambda 関数の API ゲートウェイ URL を Webhook URL として使用します。この場合も、エンドポイントの API キーはカスタム ヘッダーで定義する必要がありますが、無関係なアラート データを Lambda 関数に送信しないでください (非インシデント アラート)。Opsgenie Webhook インテグレーションには、フィルターが含まれている必要があります。この実装では、CreateCloseAddTagsRemoveTags の各アクションで、インシデント アラートのデータを Service State Calculator Lambda 関数に送信します。これを行うには、次の条件で 2 つの Webhook インテグレーションが必要でした (どちらも同じ URL を使用します)。

webhook
Webhook アクション

S3 のホスティング ステータス ページ

AWS S3 has Public Website hosting capabilities and status pages for the services can be hosted on S3. Status Page web application has a dashboard that lists service names and their states. From the dashboard, you can open a “services” status page and view incidents with updates (alerts and alert notes). Status pages highlight the service state and service incidents (alerts). The web application retrieves the data by making ajax calls to two separate Lambda functions through the API Gateway endpoints. The first Lambda function retrieves service data from S3 and the second one retrieves service alerts and alert notes from Opsgenie through the Alert API . The following configurations should be made in app.js

テキスト

.constant('cfg', { 'apiLambdaFunctionUrl': 'api_lambda_url', // API Gateway URL of the Lambda function that retrieves alerts and alert notes from OpsGenie. 'serviceLambdaFunctionUrl': 'service_lambda_url', // API Gateway URL of the Lambda function that retrieves service data from S3. 'apiKey': 'apiKey' // API Key to make secure calls to API Gateway (both API Gateway endpoint can use same API Key.) })

以下の画像は、Opsgenie と対応するステータス ページにあるインシデント アラートの例を示しています。

In the example below, there are two incident alerts for the API service. They both contain incident alert identifier statuspage tag, a severity tag, and a tag that contains the name of the service with the servicename as the prefix servicename:API

インシデント アラートの例

この例ではサービスが 1 つしかないため、ダッシュボードには API サービスのみが含まれています。Opsgenie にあるアラートの重大度は致命的であるため、サービスのステータスは致命的になって赤で表示されます。

API の停止

API サービスの [ステータス] ページには、ページの上部にサービスの状態が表示されてすべてのインシデント アラートがリストされます。クローズされたアラートは解決済みとして表示されます。

ステータス ページ API の停止

ソース コード

The source code of all three Lambda functions and Web application is available on GitHub.

 

さらにヘルプが必要ですか?

アトラシアン コミュニティをご利用ください。