- Zabbix 4 Network Monitoring
- Patrik Uytterhoeven Rihards Olups
- 329字
- 2021-07-02 14:08:25
Using embedded Perl code
Using embedded Perl code in snmptrapd is the easiest method to set up. Unless you need extra functionality, it is suggested to stick with this method.
We'll start by configuring snmptrapd to pass information to Zabbix. There is an example script in the Zabbix sources called misc/snmptrap/zabbix_trap_receiver.pl. Place this file in some reasonable location—perhaps a bin subdirectory in the Zabbix home directory. If the directory does not exist, create it, as follows:
# mkdir -p /home/zabbix/bin; chown zabbix /home/zabbix
Place the zabbix_trap_receiver.pl file in this directory:
# cp misc/snmptrap/zabbix_trap_receiver.pl /home/zabbix/bin
Now, on to instructing snmptrapd to use that script. We only need to tell the trap daemon to process all of the received traps with this script. To do this, you'll have to find the location where your distribution places the Net-SNMP configuration files—usually, /etc/snmp/. In this directory, look for a file named snmptrapd.conf. If it's there, edit it (create a backup copy before you do anything); if it's missing, create it. Edit it as root and make it look as follows:
authCommunity execute public perl do "/home/zabbix/bin/zabbix_trap_receiver.pl";
This will accept all traps that have the community set to public and pass them to the Perl receiver script.
Start or restart the trap daemon. It might be worth taking a quick look at the zabbix_trap_receiver.pl file. Notice the line that specifies the path:
$SNMPTrapperFile = '/tmp/zabbix_traps.tmp';
Behind the scenes, traps are passed to the Zabbix server through a temporary file. We'll discuss this in a bit more detail later in this chapter.