Skip to content

Commit

Permalink
Merge pull request #6 from marove2000/master
Browse files Browse the repository at this point in the history
modified haproxy-scripts to work with python 3.*
  • Loading branch information
hcooper authored Aug 11, 2019
2 parents 1799c8f + 4791ae7 commit d8260a0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
17 changes: 9 additions & 8 deletions haproxy/haproxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import os
import re
import sys
from cStringIO import StringIO
from io import StringIO
import socket
from time import time

Expand Down Expand Up @@ -100,11 +100,11 @@ def run_checks(servers):

# If any of our checks have set the crit/warn flags, act on it
if alert_crit:
print "2 HAProxy_%s %s CRITICAL - [%s]" % (server['fullname'], allperf, result)
print ("2 HAProxy_%s %s CRITICAL - [%s]" % (server['fullname'], allperf, result))
elif alert_warn:
print "1 HAProxy_%s %s WARNING - [%s]" % (server['fullname'], allperf, result)
print ("1 HAProxy_%s %s WARNING - [%s]" % (server['fullname'], allperf, result))
else:
print "0 HAProxy_%s %s OK - [%s]" % (server['fullname'], allperf, result)
print ("0 HAProxy_%s %s OK - [%s]" % (server['fullname'], allperf, result))


class HAProxyStats(object):
Expand All @@ -124,16 +124,17 @@ def getstats(self, timeout=200):

try:
client.connect(self.socket_name)
client.send('show stat' + '\n')
client.send(('show stat' + '\n').encode())

while time() <= end:
data = client.recv(4096)
databyte = client.recv(4096)
data = databyte.decode()
if data:
buff.write(data)
else:
return build_array(buff.getvalue())
except:
print "Failed to retrieve stats"
print ("Failed to retrieve stats")
sys.exit(1)
finally:
client.close()
Expand All @@ -145,7 +146,7 @@ def getstats(self, timeout=200):
socketfile = "/var/run/haproxy.socket"

if not os.path.exists(socketfile):
print "Socket does not exist"
print ("Socket does not exist")
sys.exit(1)

statssocket = HAProxyStats(socketfile)
Expand Down
2 changes: 1 addition & 1 deletion haproxy/haproxychecks.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
]

if __name__ == "__main__":
print "This file is not meant to be called directly"
print ("This file is not meant to be called directly")

0 comments on commit d8260a0

Please sign in to comment.