LogicMonitor REST API v1 から API v3 への移行
最終更新日 - 25年2025月XNUMX日
LogicMonitor REST API v3はAPI v1よりもはるかに進化しています。すべての機能強化と修正はAPI v3に対してのみ行われます。API v3への移行が必須となる主な理由は以下の通りです。
- API v3 バージョン ヘッダーの更新
- トークンベースの認証のサポート
- フィルタ構文のサポート
- サポート
PATCH方法 - API URLの更新
LogicMonitor REST API v1 から API v3 への移行要件
API v3 に移行するには、次のものが必要です。
- 認証用の有効な LMv1 API トークンまたはベアラー トークン。
- API v3 リファレンスの LogicMonitor からの Swagger ドキュメントへのアクセス。
LogicMonitor REST API v1 から API v3 への変更
API v1 と API v3 の両方で次の変更点に注意する必要があります。
- 認証の更新
- へのサポート
PATCHエンドポイントを部分的に更新する方法 - バージョンヘッダーの更新
- 成功とエラーの応答形式の更新
トークンベースの認証のサポート
API v2以降、LogicMonitorはBasic認証をサポートしなくなりました。これは、認証にAPIトークンの使用を推奨するためです。APIトークンは安全であり、LogicMonitorポータルとLogicMonitor REST APIアクセスの分離、そして監査ログエントリの作成に役立ちます。
LogicMonitorは、トークンベースの認証の利用を促進するため、LMv1 APIとAPI v2およびAPI v3のベアラートークンをサポートしています。詳細については、 RESTAPI認証.
PATCH メソッドのサポート
API v3には以下のサポートが含まれています PATCH ほとんどのAPIエンドポイントでこのメソッドが利用可能です。エンドポイントの特定のフィールドを更新する場合、 PUT すべてのフィールド(つまりAPIエンドポイント全体)を更新するメソッド。詳細については、 REST API v3 Swagger ドキュメント.
REST API v1 から API v3 へのバージョン ヘッダー
次のいずれかのバージョン ヘッダーを使用して、API v3 リクエストを行うことができます。
- ヘッダーXバージョン、値3。例:「Xバージョン: 3」
- APIクエリパラメータ
v値は3です。例えば、「v=3」
詳細については、を参照してください。 REST API v3 Swagger ドキュメント.
cURL を使用してバージョン ヘッダーを追加する
次のコマンドを入力して -H or --header ヘッダー名と値が続きます:
curl -H "X-version: 3" https://COMPANY.logicmonitor.com/santaba/rest/device/devices/1curl --header "X-version: 3" https://COMPANY.logicmonitor.com/santaba/rest/device/devices/1curl "https://COMPANY.logicmonitor.com/santaba/rest/device/devices/1?v=3"Pythonを使用してバージョンヘッダーを追加する
次のコマンドを入力し、 headers 内のパラメータ requests としょうかん。
headers = {'X-Version':'3'}
response = requests.get("https://COMPANY.logicmonitor.com/santaba/rest/device/devices/1", headers=headers)response = requests.get("https://COMPANY.logicmonitor.com/santaba/rest/device/devices/1?v=3")REST API v1 から API v3 までの API レスポンス形式
API 応答形式の主な更新は次のとおりです。
- ラッパーフィールドの削除
- その
status,errmsg,dataフィールドは API v3 レスポンスから削除されます。 - すべてのフィールドから
dataJSON レスポンスのルートに直接含まれるようになりました。 - 新しいフィールドを追加しました
errorMessage,errorCode,errorDetailエラー応答形式に変更します。
- その
- 解析ロジックの更新
- 解析する必要はありません
dataAPI 応答データ値にアクセスするためのフィールド。 - JSON レスポンスのルートからフィールド値を直接使用できます。
- 解析する必要はありません
- エラー処理の更新
- 新しいフィールドを追加しました
errorMessage,errorCode,errorDetailエラー応答形式に変更します。 - 同じ API エンドポイントでも、API v3 のエラー コードは API v1 のエラー コードと異なる場合があります。
- 新しいフィールドを追加しました
REST API v1 および API v3 の成功レスポンス形式の例
API v1のレスポンスペイロードはAPI v3と異なるため、レスポンスの解析方法も変更されています。APIがレスポンスを正常に取得した場合、レスポンスの形式は以下のようになります。
- API v1 成功レスポンス
{
"status": 200,
"errmsg": "OK",
"data": {
<API specific data fields and value>
}
}- API v3 成功レスポンス
{
<API specific data, same data that we are returning in "data" field of API V1 response>
}REST API v1 および API v3 のエラー応答形式の例
エラー応答の場合、形式は次のようになります。
- API v1 エラー応答
{
"data": null,
"errmsg": <ERROR_MESSAGE>,
"status": <ERROR_CODE>
}- API v3 エラー応答
{
"errorMessage": <ERROR_MESSAGE>,
"errorCode": <ERROR_CODE>,
"errorDetail": null
}REST API v1とAPI v3のパラメータの違いの比較
API v1 から API v3 に移行する場合は、API URL、エラー コード、フィルター構文の違いを考慮する必要があります。
| フィルタ構文 | API v1 パラメータ値 | API v3 パラメータ値 |
| 値を二重引用符(“”)で囲みます | GET /device/devices?filter=name:127.0.0.1 | GET /device/devices?filter=name:"127.0.0.1" |
| 特殊文字「+」を使用して値を2回エンコードします | GET /device/devices?filter=name:Prod+Server | GET /device/devices?filter=name:"Prod%252BServer" |
| 「+」を除く特殊文字(&、-など)を含む値を一度エンコードします | GET /device/devices?filter=name:Prod&Server | GET /device/devices?filter=name:"Prod%26Server" |
REST API v1 および API v3 の API URL の更新
API v1からAPI v3に移行する場合は、API v1のURLをAPI v3のURLに置き換える必要があります。コレクターやウェブサイトなどのコンポーネントのAPI URLは変更されています。v1とv3のURLのマッピングは次の表のとおりです。
| 成分 | API v1 URL | API v3 URL |
| コレクター | POST /setting/collectors | POST /setting/collector/collectors |
GET /setting/collectors | GET /setting/collector/collectors | |
GET /setting/collectors/id/installers/id | GET /setting/collector/collectors/id/installers/id | |
POST /setting/collectors/id/ackdown | POST /setting/collector/collectors/id/ackdown | |
DELETE /setting/collectors/id | DELETE /setting/collector/collectors/id | |
PUT /setting/collectors/id | PUT /setting/collector/collectors/id | |
PATCH /setting/collectors/id | PATCH /setting/collector/collectors/id | |
GET /setting/collectors/id | GET /setting/collector/collectors/id | |
| コレクターグループ | GET /setting/collectors/groups/id | GET /setting/collector/groups/{id} |
DELETE /setting/collectors/groups/id | DELETE /setting/collector/groups/{id} | |
PUT /setting/collectors/groups/id | PUT /setting/collector/groups/id | |
GET /setting/collectors/groups | GET /setting/collector/groups | |
POST /setting/collectors/groups | POST /setting/collector/groups | |
| ウェブサイト | GET /service/smcheckpoints | GET /website/smcheckpoints |
GET /service/services/id/sdts | GET /website/websites/id/sdts | |
GET /service/services/id/properties | GET /website/websites/{id}/properties | |
GET /service/services/id/graphs/id/data | GET /website/websites/id/graphs/id/data | |
GET /service/services/id/checkpoints/id/graphs/id/data | GET /website/websites/id/checkpoints/id/graphs/id/data | |
GET /service/services/id/checkpoints/id/data | GET /website/websites/id/checkpoints/id/data | |
GET /service/services/id/alerts | GET /website/websites/id/alerts | |
DELETE /service/services/id | DELETE /website/websites/id | |
PATCH /service/services/id | PATCH /website/websites/id | |
PUT /service/services/id | PUT /website/websites/id | |
GET /service/services/id | GET /website/websites/{id} | |
POST /service/services | POST /website/websites | |
GET /service/services | GET /website/websites | |
| ウェブサイトグループ | GET /service/groups/id/services | GET /website/groups/id/websites |
GET /service/groups/id/sdts | GET /website/groups/id/sdts | |
DELETE /service/groups/id | DELETE /website/groups/id | |
PATCH /service/groups/id | PATCH /website/groups/id | |
GET /service/groups/id | GET /website/groups/{id} | |
PUT /service/groups/id | PUT /website/groups/id | |
POST /service/groups | POST /website/groups | |
GET /service/groups | GET /website/groups |
REST API v1 および API v3 のエラー コードの更新
LogicMonitorはAPI v3の一部のエラーコードを更新しました。API v1からAPI v3に移行する際は、API v3のエラーコードを考慮する必要があります。v1とv3のエラーコードのマッピングは次の表のとおりです。
注意:
- エラー コード リストには追加の行が含まれる場合があります。
- エラー メッセージは API エンドポイントによって異なる場合があります。
| APIv1エラーコード | APIv3エラーコード | デフォルトの新しいエラーメッセージ |
| 3403 | 1400 | 不正な要求 |
| 2403 | 1404 | そのような記録はありません |
| 1312 | 1400 | 不正な要求 |
| 1310 | 14042 | そんな会社ない |
| 1304 | 14041 | TSDBにそのような記録はありません |
| 1303 | 1400 | 不正な要求 |
| 1302 | 1404 | そのような記録はありません |
| 1301 | 1400 | 不正な要求 |
| 1300 | 14002 | 部分的な成功 |
| 1201 | 14002 | 部分的な成功 |
| 1104 | 14001 | リソース依存 |
| 1101 | 15001 | クエリタイムアウト |
| 1100 | 1429 | リクエストが多すぎます |
| 1091 | 1429 | リクエストが多すぎます |
| 1079 | 1400 | 不正な要求 |
| 1078 | 1400 | 不正な要求 |
| 1077 | 1400 | 不正な要求 |
| 1076 | 1400 | 不正な要求 |
| 1075 | 1413 | リクエスト エンティティが大きすぎます |
| 1074 | 1074 | タイムリーなレポートとして閲覧を拒否 |
| 1073 | 1400 | 不正な要求 |
| 1069 | 1404 | そのような記録はありません |
| 1065 | 1404 | そのような記録はありません |
| 1060 | 1404 | そのような記録はありません |
| 1058 | 1404 | そのような記録はありません |
| 1053 | 1404 | そのような記録はありません |
| 1048 | 1404 | そのような記録はありません |
| 1041 | 1403 | 許可が拒否されました |
| 1040 | 1400 | 不正な要求 |
| 1037 | 1404 | そのような記録はありません |
| 1035 | 1400 | 不正な要求 |
| 1033 | 1404 | そのような記録はありません |
| 1031 | 1400 | 不正な要求 |
| 1027 | 1404 | そのような記録はありません |
| 1026 | 1400 | 不正な要求 |
| 1025 | 1400 | 不正な要求 |
| 1022 | 1404 | そのような記録はありません |
| 1020 | 1400 | 不正な要求 |
| 1019 | 1400 | 不正な要求 |
| 1018 | 1400 | 不正な要求 |
| 1017 | 1400 | 不正な要求 |
| 1016 | 1400 | 不正な要求 |
| 1015 | 1404 | そのような記録はありません |
| 1014 | 1400 | 不正な要求 |
| 1013 | 1404 | そのような記録はありません |
| 1010 | 1400 | 不正な要求 |
| 1007 | 1400 | 不正な要求 |
| 1004 | 1404 | そのような記録はありません |
| 1001 | 1500 | 内部エラー |
| 1000 | 1500 | 内部エラー |
| 600 | 1409 | レコードはすでに存在します |
| 503 | 1404 | そのような記録はありません |
| 500 | 1500 | 内部エラー |
| 403 | 1401 | 認証に失敗しました |
| 400 | 1401 | 認証に失敗しました |
| 100 | 1202 | タスクは実行中です |
REST API v1 および API v3 のエラーコード更新例
以下は、処理フィールドの API v1 と API v3 の例です。
- API v1 コードブロック
import json
# Success Response Handling
def handle_success_response_v1(json_response):
response = json.loads(json_response)
status = response['status']
errmsg = response['errmsg']
data = response['data']
# Process the fields from the data object
# Example: total = data['total']
# Error Response Handling
def handle_error_response_v1(json_response):
response = json.loads(json_response)
status = response['status']
errmsg = response['errmsg']
data = response['data']
# Process the error message and status- API v1 処理フィールドのコードブロック
#!/bin/env python
import requests
import json
import hashlib
import base64
import time
import hmac
import getpass
#Account Info: LogicMonitor recommends to NEVER hardcode the credentials. Instead, retrieve the values from a secure storage.
#Note: The below is provided for illustration purposes only.
AccessId = getpass.getpass("Enter your AccessId: ")
AccessKey = getpass.getpass("Enter your AccessKey: ")
Company = 'apiAccount'
#Request Info
httpVerb ='GET'
resourcePath = '/device/devices/1'
fields = 'id,name,displayName'
queryParams = '?fields=' + fields
data = ''
#Construct URL
url = 'https://'+ Company +'.logicmonitor.com/santaba/rest' + resourcePath + queryParams
#Get current time in milliseconds
epoch =str(int(time.time() * 1000))
#Concatenate Request details
requestVars = httpVerb + epoch + data + resourcePath
#Construct signature
digest = hmac.new(
AccessKey.encode('utf-8'),
msg=requestVars.encode('utf-8'),
digestmod=hashlib.sha256).hexdigest()
signature = base64.b64encode(digest.encode('utf-8')).decode('utf-8')
# Construct headers
auth = 'LMv1 ' + AccessId + ':' + str(signature) + ':' + epoch
# headers = {'Content-Type':'application/json','Authorization':auth}
headers = {'X-version':'1','Content-Type':'application/json','Authorization':auth}
#Make request
response = requests.get(url, data=data, headers=headers)
#body of response
response_body = json.loads(response.content.decode('utf-8'))
print ('Response Body:',response_body)
status = response_body['status']
if (status == 200):
#Fetch data from body of response
data = response_body['data']
#Read device fields value from data
device_name = data['name']
device_displayName = data['displayName']
print ("name:", device_name)
print ("displayName:", device_displayName)
else:
data = response_body['data']
errmsg = response_body['errmsg']
print ("Error status code:",status)
print ("Error data:",data)
print ("Error message:",errmsg)- API v3 コードブロック
import json
# Success Response Handling
def handle_success_response_v3(json_response):
response = json.loads(json_response)
# Process the fields directly from the response
# Example: total = response['total']
# Error Response Handling
def handle_error_response_v3(json_response):
response = json.loads(json_response)
error_message = response['errorMessage']
error_code = response['errorCode']
error_detail = response['errorDetail']
# Process the error message, code, and detail- API v3 処理フィールドのコードブロック
#!/bin/env python
import requests
import json
import hashlib
import base64
import time
import hmac
import getpass
#Account Info: LogicMonitor recommends to NEVER hardcode the credentials. Instead, retrieve the values from a secure storage.
#Note: The below is provided for illustration purposes only.
AccessId = getpass.getpass("Enter your AccessId: ")
AccessKey = getpass.getpass("Enter your AccessKey: ")
Company = 'apiAccount'
#Request Info
httpVerb ='GET'
resourcePath = '/device/devices/1'
fields = 'id,name,displayName'
queryParams = '?fields=' + fields
data = ''
#Construct URL
url = 'https://'+ Company +'.logicmonitor.com/santaba/rest' + resourcePath + queryParams
#Get current time in milliseconds
epoch =str(int(time.time() * 1000))
#Concatenate Request details
requestVars = httpVerb + epoch + data + resourcePath
#Construct signature
digest = hmac.new(
AccessKey.encode('utf-8'),
msg=requestVars.encode('utf-8'),
digestmod=hashlib.sha256).hexdigest()
signature = base64.b64encode(digest.encode('utf-8')).decode('utf-8')
# Construct headers
auth = 'LMv1 ' + AccessId + ':' + str(signature) + ':' + epoch
headers = {'X-version':'3','Content-Type':'application/json','Authorization':auth}
#Make request
response = requests.get(url, data=data, headers=headers)
#body of response
print ('Response Status:',response.status_code)
response_body = json.loads(response.content.decode('utf-8'))
print ('Response Body:',response_body)
status = response.status_code
if (status == 200):
#Read device fields value from response_body
device_name = response_body['name']
device_displayName = response_body['displayName']
print ("name:", device_name)
print ("displayName:", device_displayName)
else:
errorMessage = response_body['errorMessage']
errorCode = response_body['errorCode']
errorDetail = response_body['errorDetail']
print ("Error status code:",errorCode)
print ("Error details:",errorDetail)
print ("Error message:",errorMessage)