Skip to content

Commit

Permalink
Update grafana_silence.py
Browse files Browse the repository at this point in the history
I am using Grafana Cloud and version is 11.3.0-75221. The function is not able to fetch major.minor.rev due to error " ValueError: invalid literal for int() with base 10"
  • Loading branch information
prahastakumar authored Aug 30, 2024
1 parent 53c9402 commit 68725ac
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions plugins/modules/grafana_silence.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,15 +269,20 @@ def organization_by_name(self, org_name):
)

def get_version(self):
url = "/api/health"
response = self._send_request(
url, data=None, headers=self.headers, method="GET"
)
version = response.get("version")
if version is not None:
major, minor, rev = version.split(".")
return {"major": int(major), "minor": int(minor), "rev": int(rev)}
raise GrafanaError("Failed to retrieve version from '%s'" % url)
url = "/api/health"
response = self._send_request(
url, data=None, headers=self.headers, method="GET"
)
version = response.get("version")
if version is not None:
try:
# Split the version by '-' to handle the build number
version_main, build_number = version.split("-")
major, minor, rev = version_main.split(".")
return {"major": int(major), "minor": int(minor), "rev": int(rev), "build": build_number}
except ValueError:
raise GrafanaError(f"Unexpected version format: '{version}'")
raise GrafanaError("Failed to retrieve version from '%s'" % url)

def create_silence(self, comment, created_by, starts_at, ends_at, matchers):
url = "/api/alertmanager/grafana/api/v2/silences"
Expand Down

0 comments on commit 68725ac

Please sign in to comment.