Skip to content

Instantly share code, notes, and snippets.

@crankycoder
Created November 22, 2013 20:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save crankycoder/7606664 to your computer and use it in GitHub Desktop.
Save crankycoder/7606664 to your computer and use it in GitHub Desktop.
netsyslog.py example
#!/usr/bin/python
import socket
import time
FACILITY = {
'kern': 0, 'user': 1, 'mail': 2, 'daemon': 3,
'auth': 4, 'syslog': 5, 'lpr': 6, 'news': 7,
'uucp': 8, 'cron': 9, 'authpriv': 10, 'ftp': 11,
'local0': 16, 'local1': 17, 'local2': 18, 'local3': 19,
'local4': 20, 'local5': 21, 'local6': 22, 'local7': 23,
}
LEVEL = {
'emerg': 0, 'alert': 1, 'crit': 2, 'err': 3,
'warning': 4, 'notice': 5, 'info': 6, 'debug': 7
}
def syslog(level=LEVEL['notice'], facility=FACILITY['daemon'],
host='localhost', port=514):
"""
Send syslog UDP packet to given host and port.
"""
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
data = "<5> blah"
sock.sendto(data, (host, port))
sock.close()
print "Sent: [%s]" % data
while True:
syslog(host='localhost', port=2514)
time.sleep(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment