Skip to content

Commit

Permalink
Refine API wrapper for "Plugins"
Browse files Browse the repository at this point in the history
  • Loading branch information
amotl committed Sep 20, 2023
1 parent 434a98c commit 05759df
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 19 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## unreleased

* Refine API wrapper for "Plugins"


## 3.8.0 (2023-09-15)

Expand Down
44 changes: 25 additions & 19 deletions grafana_client/elements/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,6 @@ def __init__(self, client):
self.client = client
self.logger = logging.getLogger(__name__)

def health_check_plugin(self, pluginId):
"""
:return:
"""
path = "/plugins/%s/health" % pluginId
r = self.client.GET(path)
return r

def get_installed_plugins(self):
"""
:return:
Expand All @@ -25,7 +17,7 @@ def get_installed_plugins(self):
r = self.client.GET(path)
return r

def install_plugin(self, pluginId, version):
def install_plugin(self, pluginId, version, errors="raise"):
"""
: return:
"""
Expand All @@ -34,10 +26,15 @@ def install_plugin(self, pluginId, version):
r = self.client.POST(path, json={"version": version})
return r
except Exception as ex:
self.logger.info("Skipped installing %s and err = %s", pluginId, ex)
if errors == "raise":
raise
elif errors == "ignore":
self.logger.info(f"Skipped installing plugin {pluginId}: {ex}")
else:
raise ValueError(f"error={errors} is invalid")
return None

def uninstall_plugin(self, pluginId):
def uninstall_plugin(self, pluginId, errors="raise"):
"""
: return:
"""
Expand All @@ -46,17 +43,26 @@ def uninstall_plugin(self, pluginId):
r = self.client.POST(path)
return r
except Exception as ex:
self.logger.info("Skipped uninstalling %s and error = %s", pluginId, ex)
if errors == "raise":
raise
elif errors == "ignore":
self.logger.info(f"Skipped uninstalling plugin {pluginId}: {ex}")
else:
raise ValueError(f"error={errors} is invalid")
return None

def health_check_plugin(self, pluginId):
"""
:return:
"""
path = "/plugins/%s/health" % pluginId
r = self.client.GET(path)
return r

def get_plugin_metrics(self, pluginId):
"""
: return:
"""
try:
path = "/plugins/%s/metrics" % pluginId
r = self.client.GET(path)
return r
except Exception as ex:
self.logger.info("Got error in fetching metrics for plugin %s and error = %s", pluginId, ex)
return None
path = "/plugins/%s/metrics" % pluginId
r = self.client.GET(path)
return r

0 comments on commit 05759df

Please sign in to comment.