Skip to content

Instantly share code, notes, and snippets.

@jrossi
Created March 13, 2014 13:28
Show Gist options
  • Select an option

  • Save jrossi/9528466 to your computer and use it in GitHub Desktop.

Select an option

Save jrossi/9528466 to your computer and use it in GitHub Desktop.
import zmq
import smptlib
import json
context = zmq.Context()
socket = context.socket(zmq.SUB)
socket.connect("tcp://127.0.0.1:5000")
socket.setsockopt(zmq.SUBSCRIBE, "ossec.alerts")
ssmtp = smtplib.SMTP()
ssmtp.connect(host="smpt.host.here")
last_time = time.time()
while True:
x = socket.recv(0)
d = json.loads(x)
# http://ossec-docs.readthedocs.org/en/latest/formats/json.html <- format of the json
if d['level'] > 10:
ssmtp.sendmail(
"ossec-zmq@example.com",
["someone@example.com"],
"format you messages here".format(d),
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment