Unable to get eventsources list using REST API
I am trying to get eventsources information using REST API, as documented here.
I am using a small python script to try to get any results, but can only get this output:
<span class="pln">('Response Status:', 406)
('Response Body:', '</span><span class="dec"><!doctype html></span><span class="tag"><html</span><span class="pln"> </span><span class="atn">lang</span><span class="pun">=</span><span class="atv">"en"</span><span class="tag">><head><title></span><span class="pln">HTTP Status 406 \xe2\x80\x93 Not Acceptable</span><span class="tag"></title><style</span><span class="pln"> </span><span class="atn">type</span><span class="pun">=</span><span class="atv">"text/css"</span><span class="tag">></span><span class="pln">body </span><span class="pun">{</span><span class="kwd">font-family</span><span class="pun">:</span><span class="pln">Tahoma</span><span class="pun">,</span><span class="pln">Arial</span><span class="pun">,</span><span class="pln">sans-serif</span><span class="pun">;}</span><span class="pln"> h1</span><span class="pun">,</span><span class="pln"> h2</span><span class="pun">,</span><span class="pln"> h3</span><span class="pun">,</span><span class="pln"> b </span><span class="pun">{</span><span class="kwd">color</span><span class="pun">:</span><span class="pln">white</span><span class="pun">;</span><span class="kwd">background-color</span><span class="pun">:</span><span class="lit">#525D76</span><span class="pun">;}</span><span class="pln"> h1 </span><span class="pun">{</span><span class="kwd">font-size</span><span class="pun">:</span><span class="lit">22px</span><span class="pun">;}</span><span class="pln"> h2 </span><span class="pun">{</span><span class="kwd">font-size</span><span class="pun">:</span><span class="lit">16px</span><span class="pun">;}</span><span class="pln"> h3 </span><span class="pun">{</span><span class="kwd">font-size</span><span class="pun">:</span><span class="lit">14px</span><span class="pun">;}</span><span class="pln"> p </span><span class="pun">{</span><span class="kwd">font-size</span><span class="pun">:</span><span class="lit">12px</span><span class="pun">;}</span><span class="pln"> a </span><span class="pun">{</span><span class="kwd">color</span><span class="pun">:</span><span class="pln">black</span><span class="pun">;}</span><span class="pln"> </span><span class="pun">.</span><span class="pln">line </span><span class="pun">{</span><span class="kwd">height</span><span class="pun">:</span><span class="lit">1px</span><span class="pun">;</span><span class="kwd">background-color</span><span class="pun">:</span><span class="lit">#525D76</span><span class="pun">;</span><span class="kwd">border</span><span class="pun">:</span><span class="pln">none</span><span class="pun">;}</span><span class="tag"></style></head><body><h1></span><span class="pln">HTTP Status 406 \xe2\x80\x93 Not Acceptable</span><span class="tag"></h1><hr</span><span class="pln"> </span><span class="atn">class</span><span class="pun">=</span><span class="atv">"line"</span><span class="pln"> </span><span class="tag">/><p><b></span><span class="pln">Type</span><span class="tag"></b></span><span class="pln"> Status Report</span><span class="tag"></p><p><b></span><span class="pln">Message</span><span class="tag"></b></span><span class="pln"> Not Acceptable</span><span class="tag"></p><p><b></span><span class="pln">Description</span><span class="tag"></b></span><span class="pln"> The target resource does not have a current representation that would be acceptable to the user agent, according to the proactive negotiation header fields received in the request, and the server is unwilling to supply a default representation.</span><span class="tag"></p><hr</span><span class="pln"> </span><span class="atn">class</span><span class="pun">=</span><span class="atv">"line"</span><span class="pln"> </span><span class="tag">/><h3></span><span class="pln">LogicMonitor Technical Operations</span><span class="tag"></h3></body></html></span><span class="pln">')</span>Did anybody get this type of call working anytime?
Apart from this, I would like to add new eventsources using the REST API. It looks like there is only an import method to get this, using a XML file.
Are there any examples or templates of that XML file?
Thanks and regards.
Javier Llorente
Posted 5 years ago·Last reply 5 years ago
10 comments
Javier Llorente
OP5 years agoI finally changed my code to use the SDK. I recognize I didn't use it at the first time as it looked somehow complicated. When I saw this example code I realized it was really simple to use.
Now my code works perfectly! Thanks a lot for your help!
Michael Baker
·5 years ago^^ I highly suggest when ever looking at the SDK go here first https://github.com/logicmonitor/lm-sdk-python/blob/master/LMApi.md has all the methods with example code ie https://github.com/logicmonitor/lm-sdk-python/blob/master/LMApi.md#import_event_source
LM User
·5 years agoThat data dictionary must be converted to JSON before being concatenated with the requestVars. As suggested, try the SDK. Note that the SDK example is auto-generated and in this case is missing the quotes around the path to the file.
Javier Llorente
OP5 years agoI am trying this and found several problems.
When using on the header, the "Content-Type" spec, I always get an error 500 with an "Unknown error" message. I tried removing it and it looks to work better.
Now I am getting a clear "Authentication failed" error message. I think the problem I have now is creating the correct authentication string. As this string is build with, among others, the request details, I don't know how to correctly append this "files" variable (a dictionary object) to the request variable using this piece of code:
In this case, "data" is not a string, but a dictionary containing a file object.
How authorization string should be built for this particular case?
I will have a look at the SDK anytime, as suggested.
Michael Baker
·5 years agoSet the content type as multipart/form-data then send a file object as a local file read for python
You would be much better using the SDK though
Javier Llorente
OP5 years agoHi again,
I prepared my script to programmatically create the XML file to define new EventSources. I test it successfully from the UI, using "Add" - "From File".
Now I would like to use the API to make such a call. According swagger documentation here, it looks like I need to provide this file as a parameter, but I don't have a clear idea on how to provide that. I tried several methods, but none of them worked so far:
Using any of these methods, I always get an error "HTTP 415 Unsupported Media Type".
What am I doing wrong?
LM User
·5 years agoNo problem. FWIW, adding it as a query parameter is one supported way. The other supported way is to specify "2" in the header "X-Version". https://www.logicmonitor.com/support/rest-api-developers-guide/v2/rest-api-v2-overview#:~:text=you can make v2 requests by including a ‘%3Fv%3D2’ query parameter or by including a ‘X-Version%3A2’ header.
Javier Llorente
OP5 years agoThanks for the clue!!
I solved the problem with my python script. The solution was to include ?v=2 as the first parameter:
I also found that option to export an eventsource to a XML file using the UI. I hope I can work with that pretty well.
Thanks a lot for your help!
LM User
·5 years agoYou can get an example XML file by exporting any EventSource from the UI. Just navigate to an EventSource >> More >> Export.
As far as the get request, i get the same thing if i don't specify "2" in the X-Version header. Basically, the endpoint for v1 appears to be only partially implemented. Use v2 of the API.