アラートルールの詳細の取得

最終更新日: 29 年 2023 月 XNUMX 日

LogicMonitor REST API v3 を使用して、アラート ルールの詳細を取得できます。 API リクエストを行う前に、自分自身を認証する必要があります。

アラートルールのリストの取得

次のクエリ パラメーターを使用して、応答の内容と形式を管理できます。

注: クエリ パラメータはリソース パスの一部ではないため、LMv1 認証署名の計算中に含めるべきではありません。

URI: 取得 /setting/alert/rules

タイプ説明
fields文字列応答はフィルター処理され、各オブジェクトの指定されたフィールドのみが含まれます。 プロパティのリストをカンマで区切って指定できます。
例– /setting/alert/rules?fields=name,id,priority
size整数表示する結果の数。 GET 呼び出しでは最大 1000 件の結果を要求できます。 このパラメータに値が指定されていない場合、デフォルトでは 50 個のアラート ルールのリストが返されます。
例– /setting/alert/rules?size=10
offset整数表示された結果をオフセットする結果の数。
例– /setting/alert/rules?offset=20
filter文字列応答はフィルター処理され、指定された値を含む結果のみが含まれます。 フィルタのリストをカンマで区切って指定できます。
例– /setting/alert/rules?filter=levelStr:"All"

次の Python スクリプトは、api.logicmonitor.com 内のすべてのアラート ルールの ID、名前、優先度を取得します。

#!/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 = '/setting/alert/rules'
queryParams ='?fields=id,name,priority'
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,'X-Version':3}
  
# Make request
response = requests.get(url, data=data, headers=headers)
  
# Print status and body of response
print('Response Status:',response.status_code)
print('Response Body:',response.content)
Pythonの3

アラートルールの取得

URI: 取得 /setting/alert/rules/{id}

タイプ説明
id整数(必須の) 取得するアラート ルールの ID。
fields文字列応答はフィルター処理され、各オブジェクトの指定されたフィールドのみが含まれます。 プロパティのリストをカンマで区切って指定できます。 
例– /setting/alert/rules/id?fields=name,id,priority
記事上で