Forum Discussion
Ok, here's a quick tutorial on getting the python sdk up and running. I did this in docker because it's easier than installing a full vm and it's conceptually simpler (to me) than virtual python environments. Following this completely requires that you have docker installed on a machine that has access to the internet.
1. Start with the ubuntu:latest container. This should be equivalent to Ubuntu 20.04.3 LTS:
docker run --rm -it ubuntu:latest
2. Install python 3 and pip (3) (and make sure everything is up to date):
apt update
apt upgrade -y
apt install -y python3 python3-pip
pip3 install --upgrade pip
3. Install the logicmonitor sdk:
pip3 install logicmonitor-sdk
4. Write your script (this one fetches 50 alerts, see documentation for other methods you can run in the try block):
from __future__ import print_function import time import logicmonitor_sdk from logicmonitor_sdk.rest import ApiException from pprint import pprint # Configure API key authorization: LMv1 configuration = logicmonitor_sdk.Configuration() configuration.company = 'YOUR PORTAL NAME' configuration.access_id = 'YOUR ACCESS ID' configuration.access_key = 'YOUR ACCESS KEY' # create an instance of the API class api_instance = logicmonitor_sdk.LMApi(logicmonitor_sdk.ApiClient(configuration)) try: # get alert list api_response = api_instance.get_alert_list() pprint(api_response) except ApiException as e: print("Exception when calling LMApi->getAlertList: %s\n" % e)
If you will be using it a lot, or if you want to use the interactive python interpreter, you can put my LM Wrapper in the same directory as your script and call it. It will do all the messy work of setting up the objects and get you ready in one line:
4. After step 3 (Instead of writing out the whole script), install nano and curl:
apt install -y curl nano
5. Download the wrapper:
curl -o lm.py https://raw.githubusercontent.com/sweenig/lmcommunity/master/LMAutomation/lmwrapper/lm.py
6. Setup your creds file. This will be a json file in the same directory called "creds.json". It should contain JSON with your access id, key, and company name:
{ "API_ACCESS_ID": "adelarthrosomatous", "API_ACCESS_KEY": "zygomaticoauricularis", "COMPANY_NAME": "yourportalname" }
7. Either write your script or run it interactively:
from lm import lm alerts = lm.get_alert_list() devices = lm.get_device_list(size=1000)
Related Content
- 4 months ago
- 5 months ago
- 7 months ago
- 10 months ago
- 2 years ago