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 locationperhaps 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
If using distribution packages, you might have to use a different username. Check your distribution packages for details.

Place the zabbix_trap_receiver.pl file in this directory:

# cp misc/snmptrap/zabbix_trap_receiver.pl /home/zabbix/bin
On some distributions, Net-SNMP Perl support could be split out into a separate package, such as net-snmp-perl.

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 filesusually, /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.

If you expect to receive traps with various community strings that are not known in advance, you could disable the authorization or checking of the community string with the disableAuthorization yes option in snmptrapd.conf.

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.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.116.42.208