Skip to content

Instantly share code, notes, and snippets.

@IlyaSemenov
Last active December 24, 2015 02:29
Show Gist options
  • Save IlyaSemenov/6730474 to your computer and use it in GitHub Desktop.
Save IlyaSemenov/6730474 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import socket
import subprocess
SYSLOG_HOST = "graylog2.local"
SYSLOG_PORT = 514
LOG_FILE = "/var/log/nginx/access.log"
pipe = subprocess.Popen(["tail", "-n0", "-F", "-q", LOG_FILE], stdout=subprocess.PIPE).stdout
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
while True:
line = pipe.readline()
if not line:
break
line = line.rstrip()
message = "<181>nginx: "+line # 181 is local6 (reverse engineered)
sock.sendto(message, (SYSLOG_HOST, SYSLOG_PORT))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment