1
0
Fork 0
mirror of https://github.com/munin-monitoring/contrib.git synced 2025-07-21 10:39:53 +00:00

Plugin lighttpd_: migrate to Python3

This commit is contained in:
Lars Kruse 2020-11-26 02:39:29 +01:00
parent 4a6d44a42c
commit 91eaee39f5

View file

@ -1,6 +1,4 @@
#!/usr/bin/env python #!/usr/bin/env python3
# -*- coding: utf-8 -*-
# vim: set fileencoding=utf-8
""" """
=head1 NAME =head1 NAME
@ -54,7 +52,7 @@ SPDX-License-Identifier: GPL-3.0-only
import os import os
import sys import sys
import urllib2 import urllib.request
program = sys.argv[0] program = sys.argv[0]
@ -114,17 +112,17 @@ elif len(sys.argv) == 2 and sys.argv[1] == "suggest":
else: else:
status_url = os.environ.get('status_url', 'http://127.0.0.1/server-status') status_url = os.environ.get('status_url', 'http://127.0.0.1/server-status')
request = urllib2.Request("%s?auto" % status_url) request = urllib.request.Request("%s?auto" % status_url)
if "username" in os.environ and "password" in os.environ: if "username" in os.environ and "password" in os.environ:
mgr = urllib2.HTTPPasswordMgrWithDefaultRealm() mgr = urllib.request.HTTPPasswordMgrWithDefaultRealm()
mgr.add_password(None, status_url, os.environ["username"], os.environ["password"]) mgr.add_password(None, status_url, os.environ["username"], os.environ["password"])
if os.environ.get("auth_type", "basic") == "digest": if os.environ.get("auth_type", "basic") == "digest":
auth = urllib2.HTTPDigestAuthHandler(mgr) auth = urllib.request.HTTPDigestAuthHandler(mgr)
else: else:
auth = urllib2.HTTPBasicAuthHandler(mgr) auth = urllib.request.HTTPBasicAuthHandler(mgr)
opener = urllib2.build_opener(auth) opener = urllib.request.build_opener(auth)
urllib2.install_opener(opener) urllib.request.install_opener(opener)
info = urllib2.urlopen(request).read() info = urllib.request.urlopen(request).read()
data = {} data = {}
for line in info.split("\n"): for line in info.split("\n"):
try: try: