Adding Alert Rules

Last updated on 29 November, 2023

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

URI: POST /setting/alert/rules

ParameterTypeDescription
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 expression 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” : 7
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" : 3
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” : 15

The following Python script adds a rule ‘DBAlerts’ with priority 1000 that applies to all alerts for MYSQL DataSources (any DataSource with MYSQL in the name) across all groups and devices.

#!/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 ='POST'
resourcePath = '/setting/alert/rules'
queryParams =''
data = '{"name":"DBAlerts","priority":1000,"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.post(url, data=data, headers=headers)
  
# Print status and body of response
print('Response Status:',response.status_code)
print('Response Body:',response.content)
Python 3