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