Skip to content

Commit

Permalink
Add basic auth support for Apache. Fixes #410
Browse files Browse the repository at this point in the history
  • Loading branch information
elijahandrews committed May 8, 2013
1 parent 89f8e48 commit a359914
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
12 changes: 10 additions & 2 deletions checks.d/apache.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import urllib2
import urllib2, base64

from util import headers
from checks import AgentCheck
Expand Down Expand Up @@ -35,6 +35,10 @@ def check(self, instance):
tags = instance.get('tags', [])
req = urllib2.Request(url, None,
headers(self.agentConfig))
if 'apache_user' in instance and 'apache_password' in instance:
auth_str = '%s:%s' % (instance['apache_user'], instance['apache_password'])
encoded_auth_str = base64.encodestring(auth_str)
req.add_header("Authorization", "Basic %s" % encoded_auth_str)
request = urllib2.urlopen(req)
response = request.read()

Expand Down Expand Up @@ -80,5 +84,9 @@ def parse_agent_config(agentConfig):
return False

return {
'instances': [{'apache_status_url': agentConfig.get('apache_status_url')}]
'instances': [{
'apache_status_url': agentConfig.get('apache_status_url'),
'apache_user': agentConfig.get('apache_user'),
'apache_password': agentConfig.get('apache_password')
}]
}
4 changes: 3 additions & 1 deletion conf.d/apache.yaml.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@ init_config:

instances:
- apache_status_url: http://example.com/server-status?auto
apache_user: example_user
apache_password: example_password
tags:
- instance:foo
- instance: foo

0 comments on commit a359914

Please # to comment.