Skip to content

Commit

Permalink
Modifie le plugin pour correspondre à la version en prod
Browse files Browse the repository at this point in the history
  • Loading branch information
Arnaud-D committed Feb 24, 2024
1 parent daeb51a commit 0bffb12
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions django_munin/plugins/django.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,27 @@
#!/usr/bin/env python3
import sys
import urllib.request
import os
import base64

url = os.environ["url"]
category = os.environ.get("graph_category", "")

plugin_name = os.path.basename(__file__)
route = plugin_name[plugin_name.find("_") + 1 :]

url_base = os.environ.get("url_base", "http://127.0.0.1")
category = os.environ.get("graph_category", plugin_name[: plugin_name.find("_")])
login = os.environ.get("login", "")
password = os.environ.get("password", "")
base64string = base64.encodestring(f"{login}:{password}").replace("\n", "")
base64string = base64.b64encode(f"{login}:{password}".encode())

url = url_base + "/munin/" + route + "/"

if len(sys.argv) == 2:
url = url + "?" + sys.argv[1] + "=1"
request = urllib.request.Request(url)
if login != "" and password != "":
request.add_header("Authorization", "Basic %s" % base64string)
print(urllib.request.urlopen(request).read())
print(urllib.request.urlopen(request).read().decode())
# they can set the category in the config
if category != "":
print("graph_category " + category)
Expand All @@ -24,7 +31,7 @@
request.add_header("Authorization", "Basic %s" % base64string)
data = urllib.request.urlopen(request).readlines()
for line in data:
parts = line.split(" ")
parts = line.decode().split(" ")
label = parts[0]
value = " ".join(parts[1:])
print(label + ".value " + value)

0 comments on commit 0bffb12

Please sign in to comment.