Improve and more verbose logging

This commit is contained in:
Stefan Reimer 2019-07-01 17:01:57 +00:00
parent dd0cc3558d
commit 3cfac622b0

View File

@ -9,7 +9,6 @@ from elasticsearch import Elasticsearch, RequestsHttpConnection
logger = logging.getLogger(__name__)
class elastalert_rules:
def __init__(self, config='config.yaml', saveto=None):
self._root = os.path.dirname(os.path.realpath(__file__))
@ -38,9 +37,10 @@ class elastalert_rules:
host = os.getenv('ES_HOST', default=self._config.get('es_host'))
port = int(os.getenv('ES_PORT', default=self._config.get('es_port')))
ssl = os.getenv('ES_USE_SSL', default=self._config.get('use_ssl'))
verify = self._config.get('verify_certs', True)
verify = self._config.get('verify_certs', False)
retry_on_status = tuple({502, 503, 504})
logger.debug("Connecting to {}:{} ssl:{}".format(host, port, ssl))
es = Elasticsearch(hosts=[host], port=port, use_ssl=ssl, verify_certs=verify,
connection_class=RequestsHttpConnection,
max_retries=5, retry_on_status=retry_on_status)
@ -54,6 +54,7 @@ class elastalert_rules:
rule = stream.read()
stream.seek(0)
yaml.safe_load(stream)
logger.info("Loaded rule {}.".format(filename))
except Exception as e:
logger.error("ERRRO loading rule: {} ({})".format(filename, e))
return rule
@ -66,6 +67,7 @@ class elastalert_rules:
with open(filename, 'w+') as outfile:
outfile.write(rule)
logger.info("Stored rule {}.".format(filename))
except Exception as e:
logger.error("ERROR saving rule: {} ({})".format(filename, e))
return e
@ -152,4 +154,8 @@ def main():
if __name__ == "__main__":
ch = logging.StreamHandler()
logging.getLogger(__name__).addHandler(ch)
logging.getLogger(__name__).setLevel(logging.DEBUG)
main()