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.
<span style="color:#000080;font-weight:bold;">def </span>rpc(action, params):
<span style="color:#808080;font-style:italic;">"""
</span><span style="color:#808080;font-style:italic;"> Make a call to the LogicMonitor RPC library and return the response
</span><span style="color:#808080;font-style:italic;"> Reference:
</span><span style="color:#808080;font-style:italic;"> https://www.logicmonitor.com/support/rpc-api-developers-guide/overview/using-logicmonitors-rpc-api/
</span><span style="color:#808080;font-style:italic;"> """
</span><span style="color:#808080;font-style:italic;"> </span><span style="color:#000080;">print</span>(<span style="color:#008080;font-weight:bold;">"Calling action: {action}"</span>.format(<span style="color:#660099;">action</span>=action))
<span style="color:#000080;">print</span>(<span style="color:#008080;font-weight:bold;">"Parameters: {params}"</span>.format(<span style="color:#660099;">params</span>=params))
param_str = parse.urlencode(params)
creds = parse.urlencode({<span style="color:#008080;font-weight:bold;">"c"</span>: COMPANY, <span style="color:#008080;font-weight:bold;">"u"</span>: USER, <span style="color:#008080;font-weight:bold;">"p"</span>: PASSWORD})
<span style="color:#000080;font-weight:bold;">if </span>param_str:
param_str = param_str + <span style="color:#008080;font-weight:bold;">"&"
</span><span style="color:#008080;font-weight:bold;"> </span>param_str = param_str + creds
<span style="color:#000080;font-weight:bold;">try</span>:
url = <span style="color:#008080;font-weight:bold;">"https://{0}.logicmonitor.com/santaba/rpc/{1}?{2}"
</span><span style="color:#008080;font-weight:bold;"> </span>f = request.urlopen(url.format(COMPANY, action, param_str))
<span style="color:#000080;font-weight:bold;">return </span>f.read()
<span style="color:#000080;font-weight:bold;">except </span><span style="color:#000080;">IOError </span><span style="color:#000080;font-weight:bold;">as </span>ioe:
<span style="color:#000080;">print</span>(ioe)
<span style="color:#808080;font-style:italic;"># end try
</span>
<span style="color:#808080;font-style:italic;"># end rpc
</span>
<span style="color:#000080;font-weight:bold;">def </span>main():
response = rpc(<span style="color:#008080;font-weight:bold;">"getAlerts"</span>, {<span style="color:#008080;font-weight:bold;">"level"</span>: <span style="color:#008080;font-weight:bold;">"critical"</span>})
tmp_text = response.decode(<span style="color:#008080;font-weight:bold;">"utf-8"</span>)
instance = json.loads(tmp_text)
<span style="color:#808080;">count </span>= <span style="color:#000080;">len</span>(instance.get(<span style="color:#008080;font-weight:bold;">'data'</span>).get(<span style="color:#008080;font-weight:bold;">'alerts'</span>))
<span style="color:#000080;font-weight:bold;">if </span>__name__ == <span style="color:#008080;font-weight:bold;">"__main__"</span>:
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
tiras
Posted 9 years ago·Last reply 9 years ago
2 comments
tiras
OP9 years agoThank 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
Sarah_Terry
·9 years agoHi 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