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 9, 2013
1 parent 8e3f67f commit 656ff83
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
5 changes: 5 additions & 0 deletions checks.d/apache.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import urllib2
import base64

from util import headers
from checks import AgentCheck
Expand Down Expand Up @@ -35,6 +36,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
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

2 comments on commit 656ff83

@clutchski
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@elijahandrews Can you add another instance or comment to show that these arguments are optional?

@elijahandrews
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@clutchski Sure thing. Should it be something like:

init_config:

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

Please sign in to comment.