Last active
August 31, 2021 23:07
-
-
Save kchristensen/1a27741af6c742908141 to your computer and use it in GitHub Desktop.
Nagios Haproxy Health Check
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import sys | |
import urllib2 | |
if len(sys.argv) != 2: | |
print('USAGE: {0} <hostname>').format(sys.argv[0]) | |
sys.exit(2) | |
try: | |
error = '' | |
haproxy_url = 'http://' + str(sys.argv[1]) + '/;csv;noreload' | |
haproxy_status = urllib2.urlopen( | |
haproxy_url, timeout=10).read().rstrip().split("\n") | |
if not len(haproxy_status): | |
error = 'Ecelerity HAProxy status page contains unexpected output' | |
else: | |
for row in haproxy_status: | |
status = row.split(',') | |
# Rows must have the correct number of fields | |
if len(status) != 56: | |
error = 'Incorrect number of fields returned from HAProxy ' + \ | |
'status page' | |
# A status of OPEN/UP is fine, so is a column header of | |
# 'status' | |
elif status[17] not in ['OPEN', 'UP', 'status']: | |
error = 'Status other than UP ({0}) found for {1}'.format( | |
status[17], status[1]) | |
except urllib2.HTTPError, e: | |
error = str(e.reason) | |
except urllib2.URLError, e: | |
error = str(e.reason) | |
if len(error): | |
print('CRITICAL - ' + error) | |
sys.exit(2) | |
else: | |
print('OK - Ecelerity HAProxy is healthy') | |
sys.exit(0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment