Skip to content

Commit

Permalink
Add monkeypatch for grafana-api package
Browse files Browse the repository at this point in the history
  • Loading branch information
amotl committed Oct 1, 2021
1 parent 91bf0ab commit b77f90b
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ in progress
- Croak when obtaining unknown report format
- Use ANSI colors only on TTYs
- Add software tests
- Add monkeypatch for grafana-api package to mitigate flaw with "replace" action.
See also https://github.com/m0nhawk/grafana_api/pull/85.

2019-11-06 0.9.0
================
Expand Down
6 changes: 6 additions & 0 deletions grafana_wtf/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,14 @@
from urllib.parse import urlparse, urljoin
from concurrent.futures.thread import ThreadPoolExecutor

from grafana_wtf.monkey import monkeypatch_grafana_api
# Apply monkeypatch to grafana-api
# https://github.com/m0nhawk/grafana_api/pull/85/files
monkeypatch_grafana_api()

from grafana_api.grafana_api import GrafanaClientError, GrafanaUnauthorizedError
from grafana_api.grafana_face import GrafanaFace

from grafana_wtf.util import JsonPathFinder

log = logging.getLogger(__name__)
Expand Down
23 changes: 23 additions & 0 deletions grafana_wtf/monkey.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# https://github.com/m0nhawk/grafana_api/pull/85/files

def update_dashboard(self, dashboard):
"""
:param dashboard:
:return:
"""

# When the "folderId" is not available within the dashboard payload,
# populate it from the nested "meta" object, if given.
if "folderId" not in dashboard:
if "meta" in dashboard and "folderId" in dashboard["meta"]:
dashboard = dashboard.copy()
dashboard["folderId"] = dashboard["meta"]["folderId"]

put_dashboard_path = "/dashboards/db"
r = self.api.POST(put_dashboard_path, json=dashboard)
return r


def monkeypatch_grafana_api():
import grafana_api.api.dashboard as dashboard
dashboard.Dashboard.update_dashboard = update_dashboard

0 comments on commit b77f90b

Please sign in to comment.