Révision 1f04d10a
Allow also digest auth mechanism.
Currently only basic auth was supported. I added the ability of doing
digest auth (via 'env.auth_type').
Also, I fixed a bug where 'env.status_url' was ignored.
| plugins/lighttpd/lighttpd_ | ||
|---|---|---|
| 10 | 10 |
# |
| 11 | 11 |
# Configuration parameters: |
| 12 | 12 |
# env.status_url - url of lighty's server-status (optional, default is http://127.0.0.1/server-status) |
| 13 |
# env.username - username to provide if status_url requires basic authentication (optional, default - no authentication) |
|
| 14 |
# env.password - password to provide if status_url requires basic authentication (optional, default - no authentication) |
|
| 13 |
# env.username - username to provide if status_url requires authentication (optional, default - no authentication) |
|
| 14 |
# env.password - password to provide if status_url requires authentication (optional, default - no authentication) |
|
| 15 |
# env.auth_type - the authentication mechanism to use -- either 'basic' (default) or 'digest'. |
|
| 15 | 16 |
# |
| 16 |
# Note: If basic HTTP authentication is required you should specify both username and password.
|
|
| 17 |
# Note: If HTTP authentication is required you should specify both username and password. |
|
| 17 | 18 |
# |
| 18 | 19 |
# ## Installation |
| 19 | 20 |
# Copy file to directory /usr/share/munin/plugins/ |
| ... | ... | |
| 23 | 24 |
#%# family=contrib |
| 24 | 25 |
#%# capabilities=autoconf suggest |
| 25 | 26 |
|
| 26 |
import os, sys, urllib2, base64
|
|
| 27 |
import os, sys, urllib2 |
|
| 27 | 28 |
|
| 28 | 29 |
program = sys.argv[0] |
| 29 | 30 |
graph_type = program[program.rfind("_")+1:]
|
| ... | ... | |
| 79 | 80 |
for item in graph_types.keys(): |
| 80 | 81 |
print item |
| 81 | 82 |
else: |
| 82 |
if "status-url" not in os.environ: |
|
| 83 |
status_url = "http://127.0.0.1/server-status" |
|
| 84 |
else: |
|
| 85 |
status_url = os.environ["status_url"] |
|
| 83 |
status_url = os.environ.get('status_url', 'http://127.0.0.1/server-status')
|
|
| 86 | 84 |
|
| 87 | 85 |
request = urllib2.Request("%s?auto" % status_url)
|
| 88 | 86 |
if "username" in os.environ and "password" in os.environ: |
| 89 |
base64str = base64.encodestring("%s:%s" % (os.environ["username"], os.environ["password"])).replace("\r", "")
|
|
| 90 |
request.add_header("Authorization", "Basic %s" % base64str)
|
|
| 87 |
mgr = urllib2.HTTPPasswordMgrWithDefaultRealm() |
|
| 88 |
mgr.add_password(None, status_url, os.environ["username"], os.environ["password"]) |
|
| 89 |
if os.environ.get("auth_type", "basic") == "digest":
|
|
| 90 |
auth = urllib2.HTTPDigestAuthHandler(mgr) |
|
| 91 |
else: |
|
| 92 |
auth = urllib2.HTTPBasicAuthHandler(mgr) |
|
| 93 |
opener = urllib2.build_opener(auth) |
|
| 94 |
urllib2.install_opener(opener) |
|
| 91 | 95 |
info = urllib2.urlopen(request).read() |
| 92 | 96 |
data = {}
|
| 93 |
lines = info.split("\n")
|
|
| 94 |
for line in lines: |
|
| 97 |
for line in info.split("\n"):
|
|
| 95 | 98 |
try: |
| 96 | 99 |
(title, value) = line.split(": ")
|
| 97 | 100 |
data[title] = value |
Formats disponibles : Unified diff