statusd.py: default verbosity value can changed

verbosity value can now changed with a entry in statusd.conf
This commit is contained in:
berhsi 2019-09-11 21:24:28 +02:00
parent 909f02fc1d
commit ee233e65e0

View file

@ -34,7 +34,6 @@ def read_config(CONFIGFILE, CONFIG):
key = strip_argument(key).upper()
value = strip_argument(value)
CONFIG[key] = value
logging.debug('Set {} to {}'.format(key, value))
else:
logging.error('Failed to read {}'.format(CONFIGFILE))
logging.error('Using default values')
@ -189,6 +188,28 @@ def set_values(raw_data):
return (status, timestamp)
def read_loglevel(CONFIG):
'''
The function translates the value string from config verbosity option to
a valid logging option.
param1: dictionary
return: boolean or integer
'''
if CONFIG['VERBOSITY'] == 'critical':
loglevel = logging.CRITICAL
elif CONFIG['VERBOSITY'] == 'error':
loglevel = logging.ERROR
elif CONFIG['VERBOSITY'] == 'warning':
loglevel = logging.WARNING
elif CONFIG['VERBOSITY'] == 'info':
loglevel = logging.INFO
elif CONFIG['VERBOSITY'] == 'debug':
loglevel = logging.DEBUG
else: loglevel = False
print(loglevel)
return(loglevel)
def main():
'''
The main function - opens a socket, create a ssl context, load certs and
@ -197,8 +218,12 @@ def main():
PROTOCOL_TLS: only use tls
OP_NO_COMPRESSION: prevention against crime attack
OP_DONT_ISERT_EMPTY_FRAGMENTS: prevention agains cbc 4 attack (cve-2011-3389)
'''
loglevel = logging.WARNING
formatstring = '%(asctime)s: %(levelname)s: %(message)s'
logging.basicConfig(format=formatstring, level=loglevel)
CONFIG = {
'HOST': 'localhost',
'PORT': 10001,
@ -208,13 +233,15 @@ def main():
'TIMEOUT': 3.0,
'API': './api',
'API_TEMPLATE': './api_template',
'VERBOSITY': 'info'
'VERBOSITY': 'warning'
}
CONFIG_FILE = './statusd.conf'
loglevel = logging.INFO
logging.basicConfig(format='%(levelname)s: %(message)s', level=loglevel)
read_config(CONFIG_FILE, CONFIG)
loglevel = read_loglevel(CONFIG)
if loglevel != False:
logger = logging.getLogger()
logger.setLevel(loglevel)
print_config(CONFIG)
if certs_readable(CONFIG) == False: