Support Center Home


Update Alert Rules

Overview

You can use LogicMonitor’s REST API to programmatically update Alert Rules. As with all of our API calls, authentication is required.

Request Information

HTTP Method: PUT

Resource URI: /setting/alert/rules/{id}
(where id is the id of the alert rule you’d like to update).

Request Parameters: You can include the following parameters in your PUT request.

Property Description Required? Type Example
name The name of the alert rule Yes String “name”:”prodDBErrors”
priority The priority associated with the alert rule Yes Integer “priority”:100
levelStr The alert severity levels the alert rule is configured to match. Possible values are All | Warn | Error | Critical No. Defaults to “All” String “levelStr”:”All”
devices The device names and service names the alert rule is configured to match No. Defaults to * for all devices JSON Array “devices” : [ “prod*” ]
deviceGroups The device groups and service groups the alert rule is configured to match No. Defaults to * for all groups. JSON Array “deviceGroups” : [ “Production*” ]
datasource The datasource the alert rule is configured to match Yes String “datasource” : “*SQL*”
instance The instance the alert rule is configured to match Yes String “instance” : “*”
datapoint The datapoint the alert rule is configured to match Yes String “datapoint” : “*”
escalationInterval The escalation interval associated with the alert rule, in minutes Yes Integer “escalationInterval” : 15
escalatingChainId The id of the escalation chain associated with the alert rule Yes Integer “escalatingChainId” : 12
suppressAlertClear Whether or not alert clear notifications should be sent to the alert rule No. Defaults to false. Boolean “suppressAlertClear” : true
suppressAlertAckSdt Whether or not status notifications for acknowledgements and SDTs should be sent to the alert rule No. Defaults to false Boolean “suppressAlertAckSdt” : false

Examples

Example: Update Alert Rule

The following example updates alert rule 74 in account api.logicmonitor.com.

#!/bin/env python

import requests
import json
import hashlib
import base64
import time
import hmac

#Account Info
AccessId ='48v2wRzfK94y53sq5EuF'
AccessKey ='H_D9i(f5~B^U36^K6i42=^nS~e75gy382Bf6{)P+'
Company = 'api'

#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
hmac1 = hmac.new(AccessKey.encode(),msg=requestVars.encode(),digestmod=hashlib.sha256).hexdigest()
signature = base64.b64encode(hmac1.encode())
 
# Construct headers
auth = 'LMv1 ' + AccessId + ':' + signature.decode() + ':' + epoch
headers = {'Content-Type':'application/json','Authorization':auth}
 
# 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

Example: Get Alert Rule

The following example gets alert rule74, changes the priority for that rule, 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

#Account Info
AccessId ='48v2wRzfK94y53sq5EuF'
AccessKey ='H_D9i(f5~B^U36^K6i42=^nS~e75gy382Bf6{)P+'
Company = 'api'

#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
hmac1 = hmac.new(AccessKey.encode(),msg=requestVars.encode(),digestmod=hashlib.sha256).hexdigest()
signature = base64.b64encode(hmac1.encode())
 
# Construct headers
auth = 'LMv1 ' + AccessId + ':' + signature.decode() + ':' + epoch
headers = {'Content-Type':'application/json','Authorization':auth}
 
# 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
hmac1 = hmac.new(AccessKey.encode(),msg=requestVars.encode(),digestmod=hashlib.sha256).hexdigest()
signature = base64.b64encode(hmac1.encode())
 
# Construct headers
auth = 'LMv1 ' + AccessId + ':' + signature.decode() + ':' + epoch
headers = {'Content-Type':'application/json','Authorization':auth}
 
# 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

In This Article