Skip to content

Instantly share code, notes, and snippets.

@tgrall
Created April 8, 2020 09:25
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 tgrall/12efa8ce034a149476dd6481624728ba to your computer and use it in GitHub Desktop.
Save tgrall/12efa8ce034a149476dd6481624728ba to your computer and use it in GitHub Desktop.
SYSlog demonstration
import time
import json
import requests
import re
import sys
# Read log
def tail(f):
f.seek(0, 2)
while True:
line = f.readline()
if not line:
time.sleep(0.1)
continue
yield line
# Parse line and send message if match
def analyze_message(line, text):
if re.search(r"\bevent_log\b", line) and re.search(r"\b"+ text + r"\b", line):
webhook_url = 'https://hooks.slack.com/services/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'
slack_data = {'text': '"' + line + '"'}
response = requests.post(
webhook_url, data=json.dumps(slack_data),
headers={'Content-Type': 'application/json'})
# Run the application
while True:
print(sys.argv[1])
auditlog = tail( open (sys.argv[1]) )
for line in auditlog:
analyze_message(line, sys.argv[2])
template(name="RedisLabsEventTemplate" type="string" string="%syslogseverity-text%:%pri-text%:%programname%:%timegenerated%:%HOSTNAME%:%syslogtag%:%msg:::drop-last-lf% \n")
if $programname startswith 'event_log' then {
action(type="omfile" file="/var/log/redislabs.log"
action(type="omfwd" protocol="tcp" target="10.0.0.12" port="514" template="RedisLabsEventTemplate" )
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment