Skip to content

Instantly share code, notes, and snippets.

@fragolinux
Last active April 25, 2017 12:06
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 fragolinux/728762449e885b90ce7a0c6ad5a14520 to your computer and use it in GitHub Desktop.
Save fragolinux/728762449e885b90ce7a0c6ad5a14520 to your computer and use it in GitHub Desktop.
json rsyslog
# 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