Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add documentation and support HTTP basic auth

  • Loading branch information...
commit f68ba0df938f05b13d2c94862500df7f5426ac6f 1 parent 8c77377
Tarjei Huse authored
Showing with 52 additions and 9 deletions.
  1. +36 −0 README.md
  2. +16 −9 Resources/scripts/check_symfony2.py
View
36 README.md
@@ -178,3 +178,39 @@ For documentation on the REST API see: [http://myproject/monitor/health/](http:/
Don't forget to add the bundle routes in your `routing.yml` file.
+## Nagios integration ##
+
+You can find a simple Nagios check written in Python in the Resources/scripts directory.
+It depends on the nagiosplugin library.
+
+Copy the script into your scripts directory in Nagios and create a command like this:
+
+ define command{
+ command_name check_symfony_health
+ command_line $USER1$/check_symfony2.py -w 0 -c 0 -u https://$HOSTNAME$
+ }
+
+To use the plugin with HTTP basic authentication, change the command to:
+
+ command_line $USER1$/check_symfony2.py -w 0 -c 0 -u https://$HOSTNAME$ -a username:password
+
+Add a service:
+
+ define service{
+ hostgroup_name Symfony2
+ service_description Symfony2 health check
+ check_command check_symfony_health
+ use generic-service
+ }
+
+And create a host attached to the Symfony2 hostgroup:
+
+ define host{
+ use web-host
+ host_name www.myhost.com
+ address 8.8.8.4
+ hostgroups Symfony2
+ }
+
+
+
View
25 Resources/scripts/check_symfony2.py
@@ -19,11 +19,11 @@
command_line $USER1$/check_symfony2.py -w 0 -c 0 -u https://$HOSTNAME$
}
-3. Restart nagios.
+3. Restart nagios.
4. Profit.
-5. Forgo profit as you just realized you are missing the nagiosplugin module.
+5. Forgo profit as you just realized you are missing the nagiosplugin module.
To remedy the situation, do:
pip install nagiosplugin
@@ -49,6 +49,9 @@ def __init__(self, optparser, logger):
help='warning threshold (default: %default%)')
optparser.add_option(
'-u', '--url', help='Url to check')
+ optparser.add_option(
+ '-a', '--auth', help='Authentication', default=None)
+
def process_args(self, options, args):
self.warning = options.warning.rstrip('%')
@@ -57,13 +60,16 @@ def process_args(self, options, args):
raise Exception("Missing url option")
self.url = options.url.strip() + "/monitor/health/run"
self.hostUrl = options.url.strip()
+ if options.auth is not None:
+ self.username, self.password = options.auth.split(":")
+ else:
+ self.username = None
def obtain_data(self):
self.badChecks = []
try:
content = self.fetch(self.url)
json = simplejson.loads(content)
- numFailing = 0
if json['globalStatus'] is not 'OK':
self.badChecks = []
@@ -85,12 +91,13 @@ def default_message(self):
def fetch(self, url):
- # passman = urllib2.HTTPPasswordMgrWithDefaultRealm()
- # this creates a password manager
- # passman.add_password(None, url, "username", "password")
- # authhandler = urllib2.HTTPBasicAuthHandler(passman)
- #opener = urllib2.build_opener(authhandler)
- #urllib2.install_opener(opener)
+ if self.username is not None:
+ passman = urllib2.HTTPPasswordMgrWithDefaultRealm()
+ # this creates a password manager
+ passman.add_password(None, url, self.username, self.password)
+ authhandler = urllib2.HTTPBasicAuthHandler(passman)
+ opener = urllib2.build_opener(authhandler)
+ urllib2.install_opener(opener)
handle = urllib2.urlopen(url)
data = handle.read()
return data
Please sign in to comment.
Something went wrong with that request. Please try again.