olo
olo

Reputation: 5271

Sending logs as MQTT topic

I've been searching a few hours but couldn't find useful information. Just wondering if anyone know how to send log information by mosquitto_pub whenever logs get updated

I use syslog-ng I'd like to use mosquitto_pub to publish topic and message whenever the log (/var/log/syslog or other logs that are located in /var/log/) get updated. eg.

/var/log/syslog new log Started on ttyS1.

then

mosquitto_pub -h 127.0.0.1 -t Started on ttyS1 -m "Started on ttyS1." automatically fires

Upvotes: 2

Views: 1612

Answers (1)

hardillb
hardillb

Reputation: 59608

mosquitto_pub supports reading messages from stdin a line at a time so something like the following will work:

tail -f /var/log/syslog | mosquitto_pub -t syslog -l

This will publish each line from /var/log/syslog to the topic syslog

Upvotes: 6

Related Questions