Telegraf container setup with syslog receiver input plugin
Introduction
I discovered that a smart power strip could communicate with a syslog server, but couldn’t find documentation for this feature. This provided an excellent opportunity to set up a Telegraf container as a syslog server to see what the device would send. This setup could potentially be used for the Unifi Network Application as well.
Telegraf from InfluxData is a server agent for collecting metrics from sensors and systems, and writing them to InfluxDB or other outputs.
The plan was as follows:
- Adjust the firewall to allow the IoT device to communicate from the IoT VLAN to the Telegraf Syslog Plugin via UDP port 6514 in the Server VLAN.
- Set up Telegraf with the syslog plugin as input and a file as output in influx format (InfluxDB can be set as output later).
- Test the syslog server via the command line with tcpdump and logger, as the IoT device initially did not write anything to the syslog server.
- View the Telegraf output in influx data format.
I won’t describe adding the firewall rule, but you can read more about the firewall setup and the Unifi Network Application here.
Setup
-
Create the folders needed by the container
Run the following commands inside your home folder:
-
Create the configuration
Save the following script as
config/telegraf.conf
: -
Create the script needed to run the container
Save the following script as
telegraf_run.sh
:Instructions:
- Optional Replace
docker
withpodman
if needed - Required Replace port number
6514
(on the left side of:
) with a port number that is available if needed - Optional Replace
$PWD/config/telegraf.conf
with the location of your Telegraf configuration if needed - Required Replace
Europe/Amsterdam
with your own timezone
- Optional Replace
-
Run the script to create the container
Run the following command:
The image
telegraf
is automatically pulled and the container is created. -
Check the results
If needed you can check if the container is running properly.
Then I configured the IoT device with the syslog server:
- IP address of Telegraf (the docker host)
- Port 6514 (udp)
Make sure the container is started and run the following commands:
For me the file was empty and this was because the IoT device had not sent anything. So I tested the Telegraf syslog server with the
logger
command with which you can send syslog messages to the server yourself. The output ofmetrics.out
then looks like this:Now everything works the output can be modified to InfluxDB.
No comments found for this note.
Join the discussion for this note on Github. Comments appear on this page instantly.