aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPavel Moravec <pmoravec@redhat.com>2018-06-18 20:44:42 +0200
committerBryn M. Reeves <bmr@redhat.com>2018-06-20 16:26:16 +0100
commitbba78dd1a0b45896848e36ec375f7dc78bd4eeb3 (patch)
treed4dca67ecb42c8f09784aef75eed5ac3dc959586
parentf57e6df8b59fe81024cac58bf81bcc536e6dafc5 (diff)
downloadsos-bba78dd1a0b45896848e36ec375f7dc78bd4eeb3.tar.gz
[elastic] handle cases when config file isnt present
Catch and log any exception and set port as string before concatenating it. Resolves: #1352 Signed-off-by: Pavel Moravec <pmoravec@redhat.com>
-rw-r--r--sos/plugins/elastic.py25
1 files changed, 14 insertions, 11 deletions
diff --git a/sos/plugins/elastic.py b/sos/plugins/elastic.py
index d4d93bc4..9f8e12e8 100644
--- a/sos/plugins/elastic.py
+++ b/sos/plugins/elastic.py
@@ -23,17 +23,20 @@ class Elastic(Plugin, RedHatPlugin, DebianPlugin, UbuntuPlugin):
def get_hostname_port(self, els_config_file):
hostname = "localhost"
- port = 9200
- with open(els_config_file) as fread:
- for line in fread:
- network_host = re.search(r'(^network.host):(.*)', line)
- network_port = re.search(r'(^http.port):(.*)', line)
- if network_host and len(network_host.groups()) == 2:
- hostname = network_host.groups()[-1].strip()
- hostname = re.sub(r'"|\'', '', hostname)
- continue
- if network_port and len(network_port.groups()) == 2:
- port = network_port.groups()[-1].strip()
+ port = "9200"
+ try:
+ with open(els_config_file) as fread:
+ for line in fread:
+ network_host = re.search(r'(^network.host):(.*)', line)
+ network_port = re.search(r'(^http.port):(.*)', line)
+ if network_host and len(network_host.groups()) == 2:
+ hostname = network_host.groups()[-1].strip()
+ hostname = re.sub(r'"|\'', '', hostname)
+ continue
+ if network_port and len(network_port.groups()) == 2:
+ port = network_port.groups()[-1].strip()
+ except Exception as e:
+ self._log_info("Failed to parse %s: %s" % (els_config_file, e))
return hostname, port
def setup(self):