Ubuntu 18.04 and 20.04, snmptrapd, versions around 5.7.3.
Trap events go into syslog. Great.
How can you make the log files go to a custom location besides syslog?
logoption or logOption as seen in many internet answers and tutorials does NOT work in snmptrapd.conf.
You can put logoption in snmp.conf, but then ALL snmp logs go there, not JUST the traps. For example, error messages when you run snmpwalk. I can find NO way to create a log file of ONLY snmp traps received by snmptrapd.
I thought a sneaky workaround would be an execute and traphandle, and just have a script write to disk. But traphandle doesn't seem to pass arguments?
something like :
authCommunity log,execute trap-dat
traphandle default /usr/local/bin/logger.rb
So you want snmptrapd to DO SOMETHING. How do you pass arguments? How do you make this thing write to a custom logfile?
There is ONE distasteful method to write a custom log file : change or over-ride snmptrapd's startup unit like : /lib/systemd/system/snmptrapd.service or the override in /etc/whatever
like this :
ExecStart=/usr/sbin/snmptrapd -Ln -f -Lf /var/log/snmptrapd.log
The systemd startup unit / service IS the only way.
ExecStart=/usr/sbin/snmptrapd -Ln -f -Lf /var/log/snmptrapd.log