Forum Discussion

usnishguha's avatar
3 years ago

Regarding GO API Programming

Hi All,

 I am new to both GO as well as to API Programming. I have downloaded the SDK and kept it inside one of our Linux boxes (where GO is installed). When I am running go mod tidy, this is the output I am receiving. 

[root@server]# go mod tidy
go: finding module for package
go: finding module for package
go: finding module for package
go: finding module for package
go: finding module for package
go: finding module for package
go: finding module for package
go: finding module for package imports module Get "": read tcp x.x.x.x :21126-> read: connection reset by peer imports module Get "": read tcp x.x.x.x:21130-> read: connection reset by peer imports module Get "": read tcp x.x.x.x:21132-> read: connection reset by peer

I am inside this path /home/user/LM and the SDKs are unzipped under /home/user/ I have put "x" instead of the actual server IP. 
Please suggest.


5 Replies

  • Anonymous's avatar

    I don't know anything about Go, but if you're new to both Go and Python and you have the option, I'd recommend you choose Python and use that SDK.

  • Hi @Stuart Weenig, I tried that. Python kept failing due to multiple library dependencies. I am looking for something like a "Step by Step" guide to run at least one on of the simplest programs in Python from Linux. I think I am missing something, also in our environment its not possible to "pip install ****" due to not having open internet connectivity from Linux.

  • @usnishguha if your linux host doesn't have open internet connectivity, that's probably why `go mod tidy` is failing; it can't download dependencies.

  • Anonymous's avatar

    I'll see if I can make time next week to make a walkthrough. 

    Python3 -m pip install logicmonitor-sdk

    Should work if you have internet access. 




  • Anonymous's avatar

    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 import ApiException
    from pprint import pprint
    # Configure API key authorization: LMv1
    configuration = logicmonitor_sdk.Configuration() = '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))
        # get alert list
        api_response = api_instance.get_alert_list()
    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

    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)