Closed msisam closed 1 year ago
Thank you for the PR!
Should probably look into getting rid of all the manual requests here. This code can be so much shorter and prettier that way. I will let this PR hang for a little bit so I can look into how the api can be improved.
We should be able to use the api for this for example:
req = requests.request("GET", f"{endpoint_cachet}/incidents?component_id={component_id}&per_page=1", verify=False)
Hey @einarf :) I was actually trying to find some good examples that actually work and it was hard, And I encountered an issue with getting status of component (by name) that lead for directly requests api. (btw, If there's a possibility to get status of component by name it would be great if you could comment)
Also, It's not meant to be pretty :) it's more of a way to show how to manipulate data through various of examples. so that's eventually why I was thinking of sharing this here where people can find practical code that might help them.
Thanks!
Sharing this is perfect. It highlights that the api is currently missing additional query parameters to search and order things. The manual requests could be avoided if this was exposed. Adding an additional **params
for query parameters for list(..)
methods at least a basic way of making this possible, but there might be even more elegant ways if the cachet api is consistent across more recent versions.
I'm guessing this is a thing for 4.1.x. I'll see if I can simplify your code by improving the api. I'm sure more examples or shortcut methods is a good thing. I'll merge this in the future and modify it. Sounds like a plan?
This is related to #25
Possibly something like this is better if the client supported the name
argument.
def get_compo_by_name(component_name):
components = client.components.list(name=component_name)
try:
return next(components)
except StopIteration:
return None
... or something similar.
@einarf Thanks for your answer, sounds perfect! let me know if I can help in anything :)
An example that can help to understand one way of how to retrieve status of components in a python script that can be used within several different ways.