From 981bd3ad7fd69e69a48d5fa7734529301968c168 Mon Sep 17 00:00:00 2001 From: Jonathan Creasy Date: Tue, 27 Oct 2020 23:41:39 -0400 Subject: [PATCH] hadoop_http.py: use exit 1 when interfaces are not listening --- collectors/lib/hadoop_http.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/collectors/lib/hadoop_http.py b/collectors/lib/hadoop_http.py index e99aee8ad..0a50ad9c6 100644 --- a/collectors/lib/hadoop_http.py +++ b/collectors/lib/hadoop_http.py @@ -27,9 +27,11 @@ try: # noinspection PyCompatibility from http.client import HTTPConnection + from http.client import NotConnected except ImportError: # noinspection PyUnresolvedReferences,PyCompatibility from httplib import HTTPConnection + from httplib import NotConnected EXCLUDED_KEYS = ( @@ -65,7 +67,11 @@ def request(self): try: self.server.request('GET', self.uri) resp = self.server.getresponse().read() - except: + except ConnectionRefusedError as exc: + sys.stderr.write("Could not connect to %s" % (self.uri)) + sys.exit(1) + except Exception as exc: + sys.stderr.write("Unexpected error: %s" % (exc)) resp = '{}' finally: self.server.close()