Telegraf creates a listen socket?
If you do service suricata start before you do service telegraf start, you’ll notice an error in the /var/log/telegraf/telegraf.log:
2021-07-29T12:43:36Z I! Starting Telegraf 1.19.0
2021-07-29T12:43:36Z E! [telegraf] Error running agent: starting input inputs.suricata: listen unix /tmp/suricata-stats.sock: bind: address already in use
If you service suricata stop, and then rm /tmp/suricata-stats.sock - followed by a service telegraf start- you’ll see
root@opnsense:/var/run # ls -alh /tmp/suricata-stats.sock
srwxr-xr-x 1 telegraf wheel 0B Jul 29 14:44 /tmp/suricata-stats.sock
And then, if you try to start suricata:
Jul 29 14:48:24 opnsense suricata[11956]: [100428] <Notice> -- This is Suricata version 5.0.7 RELEASE running in SYSTEM mode
Jul 29 14:48:24 opnsense suricata[51194]: [100601] <Error> -- [ERRCODE: SC_ERR_FOPEN(44)] - Error opening file: "/tmp/suricata-stats.sock": Operation not supported
Try to chmod 775 /tmp/suricata-stats.sock- you will get the same “Operation not supported” error.
Maybe it should read filetype: unix_stream , and not what I altered it to be; type: unix_stream. Now suricata starts without any errors. I’ll wait and see if data is beiing sent…
With type: unix_stream in suricata.yaml, suricata creates a file, not a socket. What I wrote above was wrong, it should actually be filetype: unix_stream:
file /tmp/suricata-stats.sock
/tmp/suricata-stats.sock: ASCII text, with very long lines
Further investigating this topic, I found this statement over at Suricata Fails to Create Socket - Help - Suricata :
- suricata doesn’t create the unix socket, but instead if connects to an existing one.
Opening a new terminal window as root, running sudo -u telegraf nc -U -l /tmp/suricata-stats.sock creates
srwxr-xr-x 1 telegraf wheel 0B Jul 29 15:21 /tmp/suricata-stats.sock
This is indeed a socket:
file /tmp/suricata-stats.sock
/tmp/suricata-stats.sock: socket
And watching the netcat terminal, I see that I get data from suricata! Progress. If you do ls /tmp/s*, you will notice even though as data is flowing, the socket always stays at 0Bytes.
Using sockstat, you can see that a stream is connected to suricata-sockstat.sock:
root@opnsense:/var/run # sockstat | grep suri
root suricata 93358 3 dgram -> /var/run/logpriv
root suricata 93358 4 stream -> /tmp/suricata-stats.sock
Now. Why does the metric never show up in InfluxDBv2? All other metrics are showing.