Created
April 8, 2020 09:25
-
-
Save tgrall/12efa8ce034a149476dd6481624728ba to your computer and use it in GitHub Desktop.
SYSlog demonstration
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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