Improve logging messaging for URLs
This commit is contained in:
parent
b7e5c9d580
commit
eae5b92905
1 changed files with 8 additions and 7 deletions
|
@ -59,8 +59,9 @@ class INIParser(object):
|
||||||
self.logger.error('Config file missing (varken.ini) in %s', self.data_folder)
|
self.logger.error('Config file missing (varken.ini) in %s', self.data_folder)
|
||||||
exit(1)
|
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
|
url_check = url
|
||||||
|
module = section
|
||||||
inc_port = include_port
|
inc_port = include_port
|
||||||
|
|
||||||
search = (r'(?:([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,}|' # domain...
|
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
|
valid = match(regex, url_check) is not None
|
||||||
if not valid:
|
if not valid:
|
||||||
if inc_port:
|
if inc_port:
|
||||||
self.logger.error('%s is invalid! URL must host/IP and port if not 80 or 443. ie. localhost:8080',
|
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)
|
url_check, module)
|
||||||
exit(1)
|
exit(1)
|
||||||
else:
|
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)
|
exit(1)
|
||||||
else:
|
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
|
return url_check
|
||||||
|
|
||||||
def parse_opts(self):
|
def parse_opts(self):
|
||||||
self.read_file()
|
self.read_file()
|
||||||
# Parse InfluxDB options
|
# 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')
|
port = self.config.getint('influxdb', 'port')
|
||||||
|
|
||||||
|
@ -112,7 +113,7 @@ class INIParser(object):
|
||||||
server = None
|
server = None
|
||||||
section = f"{service}-{server_id}"
|
section = f"{service}-{server_id}"
|
||||||
try:
|
try:
|
||||||
url = self.url_check(self.config.get(section, 'url'))
|
url = self.url_check(self.config.get(section, 'url'), section=section)
|
||||||
|
|
||||||
apikey = None
|
apikey = None
|
||||||
if service != 'ciscoasa':
|
if service != 'ciscoasa':
|
||||||
|
|
Loading…
Reference in a new issue