Forum Discussion

tiras's avatar
8 years ago

Post a crictical issue count to API server

Hi

I want to POST an critical issue count to my API server. My python script is as follow.

import json
from urllib import parse, request
from config import (USER, PASSWORD, COMPANY)
def rpc(action, params):
    """
    Make a call to the LogicMonitor RPC library and return the response
    Reference:
    https://www.logicmonitor.com/support/rpc-api-developers-guide/overview/using-logicmonitors-rpc-api/
    """
    print("Calling action: {action}".format(action=action))
    print("Parameters: {params}".format(params=params))
    param_str = parse.urlencode(params)
    creds = parse.urlencode({"c": COMPANY, "u": USER, "p": PASSWORD})
    if param_str:
        param_str = param_str + "&"
    param_str = param_str + creds
    try:
        url = "https://{0}.logicmonitor.com/santaba/rpc/{1}?{2}"
        f = request.urlopen(url.format(COMPANY, action, param_str))
        return f.read()
    except IOError as ioe:
        print(ioe)
        # end try


# end rpc


def main():
    response = rpc("getAlerts", {"level": "critical"})
    tmp_text = response.decode("utf-8")
    instance = json.loads(tmp_text)
    count = len(instance.get('data').get('alerts'))


if __name__ == "__main__":
    main()

 

I know to do this job in python webserver, but I want to use `LogicMonitor` integration.

How can I convert it to `Custom HTTP Delivery`?

I have been reading the docs for a while, but it seems not answer exactly what I want at all

Hope communities can support me figure out how to finish this job

Best regards

Sarit

  • Sarah_Terry's avatar
    Sarah_Terry
    Icon for Product Manager rankProduct Manager

    Hi Sarit,

    It sounds like you're looking to send a count of critical alerts to an external server or application, is that correct?  The Custom HTTP Delivery option in LogicMonitor is intended to provide a way to send an HTTP request in response to an alert, and since there isn't an alert to trigger based on here I'm not sure it's the best fit for this scenario.  Can you explain a little bit more about what you're trying to accomplish?

    Thanks,

    Sarah

  • Thank you Sarah.

    My customer raises a new issue and would like me an alternative approach

    I will come back to forum again with new question

    Thanks

    Sarit