0
0
Fork 0
mirror of https://github.com/alerta/alerta.git synced 2025-01-30 19:46:21 +00:00
alerta_alerta/alerta/plugins/logstash.py
2014-12-15 21:58:37 +00:00

33 lines
708 B
Python

import socket
from alerta.app import app
from alerta.plugins import PluginBase
LOG = app.logger
class LogStashOutput(PluginBase):
def pre_receive(self, alert):
return alert
def post_receive(self, alert):
try:
self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.sock.connect((app.config['LOGSTASH_HOST'], app.config['LOGSTASH_PORT']))
except Exception:
raise RuntimeError("Logstash connection error")
try:
self.sock.send("%s\r\n" % alert)
except Exception as e:
LOG.exception(e)
raise RuntimeError("logstash exception")
self.sock.close()
return