RESTAPI認証

最終更新日: 24 年 2024 月 XNUMX 日

LogicMonitor サーバーに送信される各要求は、HTTPS 経由で作成され、完全に認証されます。 すべてのデータは JSON として受信されます。 LogicMonitor の REST API は、API トークン認証方式をサポートしています。

LogicMonitor API 認証はバージョンごとに異なります。

  • v1 API 認証 – 基本認証をサポートします。
  • v2 and v3 API authentication– Supports token-based authentication (LMv1 and Bearer token)

ベアラートークン

The bearer token is a combination of multiple alpha numeric characters and is auto-generated by LogicMonitor. You can use bearer token to authenticate yourself to use LogicMonitor Python and GO v3 SDK files, and LogicMonitor REST API v3.

As a LogicMonitor customer, when you buy a license for a device you are eligible to get a bearer token. You do not need a specific role to get the token. It is unique for each user.

Once you get the bearer token, you must add it to the API requests just once. LogicMonitor REST API code reuses the token without you having to enter it every time. As a developer using LogicMonitor REST API, you need not develop authentication header or write commands to authenticate yourself.

To maintain secrecy of the bearer token, once you save the token, the system automatically masks some part of it with asterisks (*). For more information, see ベアラートークン.

LMv1 トークン

The LMv1 token-based authentication method requires that with every request you include a custom HTTP header containing:

  • あなたの API トークン アクセス ID
  • API トークン アクセス キーに基づく Base64 でエンコードされた HMAC 署名
  • エポックミリ秒単位のタイムスタンプ

具体的には、リクエストの詳細を連結して文字列を形成し、アクセス キーを使用してその文字列の HMAC-SHA256 を計算する必要があります。 結果をエンコードするには Base64 が必要です。 

Base64 でエンコードされた完全な HMAC 署名は、次の形式である必要があります。

signature = base64(HMAC-SHA256(Access Key,HTTP VERB + TIMESTAMP (in epoch milliseconds) + POST/PUT DATA (if any) + RESOURCE PATH) )

完全な認証ヘッダーは、次の形式である必要があります。

Authorization: LMv1 AccessId:Signature:Timestamp

認証はどのように行われますか?

LogicMonitor サーバーが API リクエストを受信すると、指定されたタイムスタンプが現在の時刻から 30 分以内であることを確認します。 その要件が満たされている場合、指定されたアクセス ID に関連付けられたアクセス キーを取得し、上記の形式で署名を計算します。 サーバーは、その署名をリクエストに含まれる署名と比較します。 XNUMX つの署名が一致する場合、リクエストは認証されますが、API トークンに関連付けられたアクセス許可が引き続き適用されます (トークンのアクセス ID とアクセス キーには、要求されたアクションを実行するための十分なアクセス許可が必要です)。 XNUMX つの署名が一致しない場合は、エラーが返されます。

注: Query parameters (for example: filter, fields, sort, and size) are not considered part of the resource path, and must not be included in the calculation of authentication signature.

基本認証

LogicMonitor の v1 用 REST API は、HTTP 基本認証をサポートしています。 HTTP 基本認証を使用するには、各要求に次の認証情報を含む HTTP ヘッダーを含める必要があります。 認証:基本 `echo -n ユーザー名:パスワード | base64`

ほとんどすべてのWebクライアントはHTTP基本認証をサポートしており、このヘッダーを作成します。

次の例では、ユーザー APIユーザー アカウントで api.logicmonitor.com ウェブサイト グループの更新をリクエストします。

curl --user 'apiUser:example' -H "Content-Type: application/json" -d '{"name":"newWebsiteGroup","description":"testSites","disableAlerting":false}' -X PUT "https://api.logicmonitor.com/santaba/rest/service/groups/7" -v

次の例では、ユーザー APIユーザー アカウントで api.logicmonitor.com すべての Web サイト グループを取得するように要求します。

wget --auth-no-challenge  --http-user='apiUser' --http-password='example' "https://api.logicmonitor.com/santaba/rest/website/groups"
記事上で