LogicMonitor SDKs
LogicMonitor has beta Python and Go SDKs available for v2 of our REST API. These SDKs allow more efficient and convenient interaction with v2 of LogicMonitor's REST API, and you may find them useful for building out API-based integrations and workflow processes. Note that these SDKs will be made GA over the coming releases.
Where can I download these SDKs?
You can download the Python SDK via pip:
pip install logicmonitor-sdk
Or you can download the compressed tar file directly for the Python SDK here and the Go SDK here. These SDKs will also be made available via LogicMonitor's GitHub soon.
How can I use these SDKs?
The Python and Go SDKs are auto-generated using Swagger Codegen. Detailed documentation with additional examples for these SDKs is available here. The following are examples to help you get started wth the Go and Python SDKs.
Example 1 - Get all alerts via Python SDK
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 = 'COMPANY_NAME' configuration.access_id = 'API_ACCESS_ID' configuration.access_key = 'API_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)
Example 2 - Add device via Python SDK
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 = 'COMPANY_NAME' configuration.access_id = 'API_ACCESS_ID' configuration.access_key = 'API_ACCESS_KEY' # create an instance of the API class api_instance = logicmonitor_sdk.LMApi(logicmonitor_sdk.ApiClient(configuration)) body = {"name": "8.8.8.8","displayName": "myDevice","preferredCollectorId": 10,"disableAlerting": "true"} try: # add device api_response = api_instance.add_device(body) pprint(api_response) except ApiException as e: print("Exception when calling LMApi->addDevice: %s\n" % e)
Example 3 - Get all alerts via Go SDK
package main import ( "fmt" "github.com/logicmonitor/lm-sdk-go/client" "github.com/logicmonitor/lm-sdk-go/client/lm" ) func main() { // define the client config := client.NewConfig() accessID := "API_ACCESS_ID" config.SetAccessID(&accessID) accessKey := "API_ACCESS_KEY" config.SetAccessKey(&accessKey) domain := "COMPANY.logicmonitor.com" config.SetAccountDomain(&domain) lmSdk := client.New(config) // prepare params and request params := lm.NewGetAlertListParams() filter := "acked:false" params.SetFilter(&filter) resp, err := lmSdk.LM.GetAlertList(params) if err != nil { fmt.Println(err.Error()) } // parse the alert list idList := make([]string, 0) for _, alert := range resp.Payload.Items { idList = append(idList, alert.ID) } fmt.Println(idList)
}