Getting Alert Rule Details

Last updated on 29 November, 2023

You can use LogicMonitor REST API v3 to get alert rule details. You must authenticate yourself before making the API request.

Getting List of Alert Rules

You can use the following query parameters to manage the content and format of the response.

Note: The query parameters are not part of the resource path and should not be included while calculating LMv1 authentication signature.

URI: GET /setting/alert/rules

ParameterTypeDescription
fieldsStringThe response is filtered to include only the specified fields for each object. You can provide a list of properties separated by a comma.
Example – /setting/alert/rules?fields=name,id,priority
sizeIntegerThe number of result to display. A maximum of 1000 results can be requested in a GET call. By default, a list of 50 alert rules is returned if a value is not provided for this parameter.
Example – /setting/alert/rules?size=10
offsetIntegerThe number of result to offset the displayed result.
Example – /setting/alert/rules?offset=20
filterStringThe response is filtered to include only the result that includes the specified value. You can provide a list of filters separated by a comma.
Example – /setting/alert/rules?filter=levelStr:"All"

The following Python script gets ID, name, and priority of all alert rules in api.logicmonitor.com.

#!/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

Getting Alert Rule

URI: GET /setting/alert/rules/{id}

ParameterTypeDescription
idInteger(Mandatory) The ID of the alert rule that you want to get.
fieldsStringThe response is filtered to include only the specified fields for each object. You can provide a list of properties separated by a comma. 
Example – /setting/alert/rules/id?fields=name,id,priority
In This Article