LogicMonitor seeks to disrupt AI landscape with $800M strategic investment at $2.4B valuation to revolutionize data centers.

Learn More

Updating Alert Rule Details

Last updated on 07 October, 2024

You can use LogicMonitor REST API v3 to update alert rules. You must authenticate yourself before making the API request.

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

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

ParameterTypeDescription
idInteger(Mandatory) The alert rule ID that you want to update.
datapointStringThe datapoint configured to match with the alert rule. It supports glob expression that match with any characters. Example – “datapoint” : “*”
instanceStringThe instance configured to match with the alert rule. It supports glob expressions that match with any characters. Example – “instance” : “*”
devicesString ArrayThe device name and service name configured to match with the alert rule. Example – “devices” : [ “Cisco Router” ]
escalatingChainIdInteger(Mandatory) The escalation chain ID associated with the alert rule. Example – “escalatingChainId” : 5
resourcePropertiesJSON ArrayThe resource property filter list that includes resource property name and value.
sendAnomalySuppressedAlertBoolean(Mandatory) To send anomaly suppressed alert, set the value as true, else set it as false.
priorityInteger(Mandatory) The priority associated with the alert rule. Example – "priority": 4
suppressAlertAckSdtBooleanIndicates whether or not status notifications for acknowledgements and SDTs should be sent to the alert rule. Example – “suppressAlertAckSdt” : false
datasourceStringThe datasource configured to match with the alert rule. Example – “datasource” : “Port-” 
suppressAlertClearBooleanIndicates whether or not alert clear notifications should be sent to the alert rule. Example – “suppressAlertClear” : true
nameString(Mandatory) The name of the alert rule. Example – “name”: ”Warning”
levelStrStringThe alert severity level configured to match with the alert rule. The acceptable values are: AllWarnError, and Critical. Example – “levelStr”: ”All”
deviceGroupsString ArrayThe device groups and service groups configured to match with the alert rule. Example – “deviceGroups” : [ “Devices by Type” ]
escalationIntervalIntegerThe escalation interval (in minutes) associated with the alert rule. Example – “escalationInterval” : 20

The following Python script updates the alert rule ID 74 in account 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 ='PUT'
resourcePath = '/setting/alert/rules/74'
queryParams =''
data = '{"name":"DBAlerts","priority":500,"datasource":"*MYSQL*","instance":"*","datapoint":"*","escalationInterval":15,"escalatingChainId":1}'
 
#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.put(url, data=data, headers=headers)
  
# Print status and body of response
print('Response Status:',response.status_code)
print('Response Body:',response.content)
Python 3

The following Python script gets the alert rule ID 74, changes its priority, and then makes a PUT request to update it 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/74'
queryParams =''
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)
 
#Parse response
jsonResponse = json.loads(response.content)
 
#Change Collector Id and add configuration object
rule = jsonResponse['data']
rule['priority'] = 50
 
#Request Info
httpVerb ='PUT'
resourcePath = '/setting/alert/rules/74'
queryParams =''
data = str(json.dumps(rule))
 
#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.put(url, data=data, headers=headers)
  
# Print status and body of response
print('Response Status:',response.status_code)
print('Response Body:',response.content)
Python 3