forked from Krautspace/doorstatus
statusd.py: default verbosity value can changed
verbosity value can now changed with a entry in statusd.conf
This commit is contained in:
parent
909f02fc1d
commit
ee233e65e0
1 changed files with 33 additions and 6 deletions
39
statusd.py
39
statusd.py
|
@ -34,7 +34,6 @@ def read_config(CONFIGFILE, CONFIG):
|
||||||
key = strip_argument(key).upper()
|
key = strip_argument(key).upper()
|
||||||
value = strip_argument(value)
|
value = strip_argument(value)
|
||||||
CONFIG[key] = value
|
CONFIG[key] = value
|
||||||
logging.debug('Set {} to {}'.format(key, value))
|
|
||||||
else:
|
else:
|
||||||
logging.error('Failed to read {}'.format(CONFIGFILE))
|
logging.error('Failed to read {}'.format(CONFIGFILE))
|
||||||
logging.error('Using default values')
|
logging.error('Using default values')
|
||||||
|
@ -189,6 +188,28 @@ def set_values(raw_data):
|
||||||
return (status, timestamp)
|
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():
|
def main():
|
||||||
'''
|
'''
|
||||||
The main function - opens a socket, create a ssl context, load certs and
|
The main function - opens a socket, create a ssl context, load certs and
|
||||||
|
@ -197,8 +218,12 @@ def main():
|
||||||
PROTOCOL_TLS: only use tls
|
PROTOCOL_TLS: only use tls
|
||||||
OP_NO_COMPRESSION: prevention against crime attack
|
OP_NO_COMPRESSION: prevention against crime attack
|
||||||
OP_DONT_ISERT_EMPTY_FRAGMENTS: prevention agains cbc 4 attack (cve-2011-3389)
|
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 = {
|
CONFIG = {
|
||||||
'HOST': 'localhost',
|
'HOST': 'localhost',
|
||||||
'PORT': 10001,
|
'PORT': 10001,
|
||||||
|
@ -208,13 +233,15 @@ def main():
|
||||||
'TIMEOUT': 3.0,
|
'TIMEOUT': 3.0,
|
||||||
'API': './api',
|
'API': './api',
|
||||||
'API_TEMPLATE': './api_template',
|
'API_TEMPLATE': './api_template',
|
||||||
'VERBOSITY': 'info'
|
'VERBOSITY': 'warning'
|
||||||
}
|
}
|
||||||
CONFIG_FILE = './statusd.conf'
|
CONFIG_FILE = './statusd.conf'
|
||||||
|
|
||||||
loglevel = logging.INFO
|
|
||||||
logging.basicConfig(format='%(levelname)s: %(message)s', level=loglevel)
|
|
||||||
read_config(CONFIG_FILE, CONFIG)
|
read_config(CONFIG_FILE, CONFIG)
|
||||||
|
loglevel = read_loglevel(CONFIG)
|
||||||
|
if loglevel != False:
|
||||||
|
logger = logging.getLogger()
|
||||||
|
logger.setLevel(loglevel)
|
||||||
|
|
||||||
print_config(CONFIG)
|
print_config(CONFIG)
|
||||||
|
|
||||||
if certs_readable(CONFIG) == False:
|
if certs_readable(CONFIG) == False:
|
||||||
|
|
Loading…
Reference in a new issue