Last active
April 25, 2017 12:06
-
-
Save fragolinux/728762449e885b90ce7a0c6ad5a14520 to your computer and use it in GitHub Desktop.
json rsyslog
This file contains 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
# create a conf file (/etc/rsyslog.d/10-mylog.conf) as follows | |
# then restart rsyslog: sudo /etc/init.d/rsyslog restart | |
# in this example, i search log entries for the word "sda" | |
# and log in text format in /var/log/hdt.log and in json in /var/log/hdj.log | |
module(load="mmjsonparse") | |
template(name="json-template" | |
type="list") { | |
constant(value="{") | |
constant(value="\"@timestamp\":\"") property(name="timereported" dateFormat="rfc3339") | |
constant(value="\",\"@version\":\"1") | |
constant(value="\",\"message\":\"") property(name="msg" format="json") | |
constant(value="\",\"sysloghost\":\"") property(name="hostname") | |
constant(value="\",\"severity\":\"") property(name="syslogseverity-text") | |
constant(value="\",\"facility\":\"") property(name="syslogfacility-text") | |
constant(value="\",\"programname\":\"") property(name="programname") | |
constant(value="\",\"procid\":\"") property(name="procid") | |
constant(value="\"}\n") | |
} | |
# old format: | |
:msg, contains, "sda" -/var/log/hdt.log | |
:msg, contains, "sda" -/var/log/hdj.log;json-template | |
# new format: | |
if $msg contains_i 'ttyusb0' then /home/pi/.node-red/public/usb.json;json-template |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment