ZPascal / grafana_api_sdk

The repository includes a Python SDK for the Grafana API
https://zpascal.github.io/grafana_api_sdk/
Apache License 2.0
20 stars 7 forks source link

api_call is checked to be an empty dictionary although a non-empty dictionary is returned if API call is successful #92

Open msaimper opened 1 week ago

msaimper commented 1 week ago

In a few locations in the alerting.py code, for instance here (there may be more I did not check)

https://github.com/ZPascal/grafana_api_sdk/blob/main/grafana_api/alerting.py#L99-L101 and https://github.com/ZPascal/grafana_api_sdk/blob/main/grafana_api/alerting.py#L164-L166

the return object from the api_call is checked to be an empty dictionary, and if it is not then an exception is raised.

ERROR:root:Check the error: {'silenceID': 'd29d20c9-08f3-4269-9c55-6363a552e535'}.
ERROR:root:Please, check the error: {'message': 'silence deleted'}.

However according to the Grafana API documentation: https://editor.swagger.io/?url=https://raw.githubusercontent.com/grafana/grafana/main/pkg/services/ngalert/api/tooling/post.json

and as illustrated above (exceptions obtained from successful requests), for these 2 API functions the normal behaviour if the request is processed successfully is to return a non-empty dictionary with some info.

So it seems that api_call should not be checked to be an empty dictionary here ; instead, for instance, a copy of it from which the regular key,value pairs returned upon successful operation are removed could be, but other possibilities exist.

ZPascal commented 1 week ago

Thank you for reporting the problem. I think the new Grafana Alerting API is stable now.

I will check it and prepare a fix for it.