monolith/core/logstash.py

29 lines
528 B
Python
Raw Normal View History

import logging
2022-07-21 12:40:05 +00:00
from json import dumps
2022-07-21 12:40:09 +00:00
import logstash
2021-08-24 20:08:18 +00:00
import main
logger = None
2022-07-21 12:39:41 +00:00
2021-08-24 20:08:18 +00:00
def init_logstash():
global logger
2022-07-21 12:39:41 +00:00
logger = logging.getLogger("ingest")
2021-08-24 20:08:18 +00:00
logger.setLevel(logging.INFO)
2022-07-21 12:39:41 +00:00
logger.addHandler(
logstash.TCPLogstashHandler(
main.config["Logstash"]["Host"],
int(main.config["Logstash"]["Port"]),
version=1,
)
)
2021-08-24 20:08:18 +00:00
def sendLogstashNotification(text):
2022-07-21 12:40:05 +00:00
if logger is not None:
2021-08-24 20:08:18 +00:00
logger.info(dumps(text))
return True
return False