Come join our live training webinar every other Wednesday at 11am PST and hear LogicMonitor experts explain best practices and answer common questions. We understand these are uncertain times, and we are here to help!
LogicMonitor’s REST API allows you to programmatically get alerts for your account. As with all of our API calls, authentication is required.
Note: If you’re trying to request alerts for a specific device, device group, or service, consider using the alerts sub-resources for those resources.
Returns a list of alerts
HTTP Method: GET
URI: /alert/alerts
Request Parameters: By default, a list of 50 alerts will be returned. You can include the following query parameters that control what data is included in the response and how it is formatted. Query parameters are not considered part of the resource path, and should not be included in the calculation of the LMv1 authentication signature.
Note: By default, only active alerts are returned. To get cleared alerts and active alerts in the response, add a filter for ‘cleared:*’. If you are using LogicMonitor REST API v2, add a filter for ‘cleared: “”*’.
Note: The response ‘total’ will be a negative number if there are additional alerts that satisfy the request criteria that weren’t included in the request, and that “at least” that number of alerts exist. For example, if you request the first 500 alerts and you have 3000 alerts in your account, the response may include total=-1000 (i.e. you have at least 1000 alerts, but you didn’t ask for them all).
The following Python script requests a list of alerts, and the value of ##externalticketid## for each alert.
#!/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 #Request Info httpVerb ='GET' resourcePath = '/alert/alerts' data='' queryParams ='?customColumns=%2523%2523externalticketid%2523%2523' #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) # Print status and body of response print('Response Status:',response.status_code) print('Response Body:',response.content)
In This Article