From eae5b92905b8675f5246af2d086d3190de7c7af1 Mon Sep 17 00:00:00 2001 From: samwiseg0 Date: Sun, 23 Dec 2018 11:25:52 -0400 Subject: [PATCH] Improve logging messaging for URLs --- varken/iniparser.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/varken/iniparser.py b/varken/iniparser.py index 5474784..b74a838 100644 --- a/varken/iniparser.py +++ b/varken/iniparser.py @@ -59,8 +59,9 @@ class INIParser(object): self.logger.error('Config file missing (varken.ini) in %s', self.data_folder) exit(1) - def url_check(self, url=None, include_port=True): + def url_check(self, url=None, include_port=True, section=None): url_check = url + module = section inc_port = include_port search = (r'(?:([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,}|' # domain... @@ -79,20 +80,20 @@ class INIParser(object): valid = match(regex, url_check) is not None if not valid: if inc_port: - self.logger.error('%s is invalid! URL must host/IP and port if not 80 or 443. ie. localhost:8080', - url_check) + self.logger.error('%s is invalid in module [%s]! URL must host/IP and port if not 80 or 443. ie. localhost:8080', + url_check, module) exit(1) else: - self.logger.error('%s is invalid! URL must host/IP. ie. localhost', url_check) + self.logger.error('%s is invalid in module [%s]! URL must host/IP. ie. localhost', url_check, module) exit(1) else: - self.logger.debug('%s is a valid URL in the config.', url_check) + self.logger.debug('%s is a valid URL in module [%s].', url_check, module) return url_check def parse_opts(self): self.read_file() # Parse InfluxDB options - url = self.url_check(self.config.get('influxdb', 'url'), include_port=False) + url = self.url_check(self.config.get('influxdb', 'url'), include_port=False, section='influxdb') port = self.config.getint('influxdb', 'port') @@ -112,7 +113,7 @@ class INIParser(object): server = None section = f"{service}-{server_id}" try: - url = self.url_check(self.config.get(section, 'url')) + url = self.url_check(self.config.get(section, 'url'), section=section) apikey = None if service != 'ciscoasa':