diff options
author | Bryn M. Reeves <bmr@redhat.com> | 2017-11-01 15:47:48 +0000 |
---|---|---|
committer | Bryn M. Reeves <bmr@redhat.com> | 2017-11-01 15:47:48 +0000 |
commit | 7d0dd322320043b465d73d4ffc75ece1f10a0cc0 (patch) | |
tree | e466ab81a18d39dde77db6007283911baa060520 | |
parent | 29d34888db8817566139ac90721de4a1e60ee1dd (diff) | |
download | sos-7d0dd322320043b465d73d4ffc75ece1f10a0cc0.tar.gz |
[haproxy] avoid exception if no provision_ip defined3.5beta1
Ensure that provision_ip is always defined, and do not attempt to
collect data if no address was found in haproxy.cfg.
Signed-off-by: Bryn M. Reeves <bmr@redhat.com>
-rw-r--r-- | sos/plugins/haproxy.py | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/sos/plugins/haproxy.py b/sos/plugins/haproxy.py index b945b723..390b6ddb 100644 --- a/sos/plugins/haproxy.py +++ b/sos/plugins/haproxy.py @@ -16,6 +16,7 @@ from sos.plugins import Plugin, RedHatPlugin, DebianPlugin from urlparse import urlparse +from re import match class HAProxy(Plugin, RedHatPlugin, DebianPlugin): @@ -43,14 +44,20 @@ class HAProxy(Plugin, RedHatPlugin, DebianPlugin): # so parse haproxy.cfg until "haproxy.stats" read, and take 2nd word # from the next line matched = None + provision_ip = None for line in open("/etc/haproxy/haproxy.cfg").read().splitlines(): if matched: provision_ip = line.split()[1] break matched = match(".*haproxy\.stats.*", line) + + if not provision_ip: + return + # check if provision_ip contains port - if not, add default ":1993" if urlparse("http://"+provision_ip).port is None: provision_ip = provision_ip + ":1993" + self.add_cmd_output("curl http://"+provision_ip+"/\;csv", suggest_filename="haproxy_overview.txt") |