In this example, we use a Cisco switch (SF300-24P) to send SNMP traps to our Zabbix server. We’ll install a zabbix_trap_receiver.pl (perl script) on Zabbix server in order to process the SNMP traps.
Enable SNMP Traps On Cisco Switch
enable
conf t
snmp-server enable traps
snmp-server host <zabbix server ip> version 2c <your community string>
exit
copy run start
You can verify your SNMP config with:
show snmp
Enable SNMP On Cisco Switch
enable
conf t
Use the below command if you wish to add a Read-Only community string:
snmp-server community public RO
(where “public” is the Read-only community string)
Use the below command if you wish to add a Read-Write community string:
snmp-server community private RW
(where “private” is the Read-write community string)
Exit the configuration mode and save the settings with ->
exit
write memory
Bonus SNMP Commands
Disable SNMP:
no snmp server
Check SNMP status:
show snmp server
Re-enable SNMP:
snmp server
Set Up Your Zabbix Server To Receive And Process SNMP Traps
Step 1 – Ensure Port 162 Is Open On Your Zabbix Server
If the Linux distro you’re running Zabbix on has port 162 blocked, you will need to open it as SNMP traps are typically sent on port 162.
For Ubuntu, Rspbian, Debian distros you can try this cmd to open port 162
iptables -A INPUT -p udp --dport 162 -J ACCEPT
sudo service iptables restart
For Centos, you can try these cmd’s:
firewall-cmd --add-port=162/udp --permanent
firewall-cmd --reload
If you can’t get the ports opened with those commands, ask ChatGPT
Step 2 – Enable And Configure SNMP Traps On Your Device
(using a Cisco switch in my case as outlined in the beginning of this blog)
Step 3 – Edit Zabbix Server Config
sudo vim /etc/zabbix/zabbix_server.conf
Comment out log file path like so: #SNMPTrapperFile=/var/log/snmptrap.log
Since we will be using the tmp path, you need to uncomment (remove the hashtag) ‘SNMPTrapperFile=/tmp/zabbix_traps.tmp’
Turn on SNMP Trapper by removing the hastag and changing 0 to 1 like so:
StartSNMPTrapper=1
Step 4 – Install zabbix_trap_receiver.pl File To /usr/bin
sudo wget https://git.zabbix.com/projects/ZBX/repos/zabbix/raw/misc/snmptrap/zabbix_trap_receiver.pl -O /usr/bin/zabbix_trap_receiver.pl
If you’re having trouble using the wget command to get the perl script, you can download the zabbix_trap_receiver.pl (perl script) directly from us here and we can get it on the server another way.
Recommend you stick the file on your desktop so you can conveniently copy it up to your Zabbix server in the next coming steps.
From windows cmd line and copy the file up to your Zabbix server with SCP:
scp "C:\Users\reasonableit\Desktop\zabbix_trap_receiver.pl" reasonableit@172.16.10.4:~
(you will need to replace the bolded text of that command with your own unique information, such as username and your zabbix server IP)
Now we need to move the file to the correct directory.
ssh to your Linux/Zabbix server and run this cmd
sudo mv ~/zabbix_trap_receiver.pl /usr/bin/zabbix_trap_receiver.pl
Step 5 – Set Permissions For The Perl Script
Run this cmd from your Linux/Zabbix server
sudo chmod a+x /usr/bin/zabbix_trap_receiver.pl
Step 6 – Install snmptrapd On Your Zabbix Server
sudo apt install snmp snmp-mibs-downloader snmptrapd
Step 7 – Edit snmptrapd.conf File
sudo vim /etc/snmp/snmptrapd.conf
Add these two lines to bottom of config file with your correct community string (change ‘public’ to your community string):
authCommunity execute <your community string>
perl do “/usr/bin/zabbix_trap_receiver.pl”;
Step 8 – Install libssnmp-perl
Perl is often missing in modern Linux distributions so we will need to install it with this command:
sudo apt-get install libsnmp-perl
Step 9 – Restart Zabbix Server & snmptrapd Services
sudo service zabbix-server restart
sudo service snmptrapd restart
sudo zabbix_server -R config_cache_reload
Step 10 – Add the host to Zabbix Frontend
Refer to video for details but basically, just add your switch with an SNMP template, generate an snmp trap (WR command on Cisco switch should generate one) and check the SNMP Trap (fallback) item of your device in Zabbix.
Note – You will add your device just like any normal SNMP monitored device with an SNMP template, you do not need to change the port to 162 (what the switch sends snmp traps out on) as the perl script and the Zabbix snmp Trap (fallback) item will handle the snmp trap processing for you. You just need to make sure port 162 is open on your Zabbix server.
Bonus
Zabbix SNMP Trap Documentation
You should also be able to send test traps from your Zabbix server to itself with the following cmd
snmptrap -v2c -cpublic 172.16.10.4 '' .1.3.6.1.6.3.1.1.5.3 .1.3.6.1.6.3.1.1.5.3 s "test trap v2c"
#how to setup SNMP traps in Zabbix 6.4
#how to enable snmp traps on Cisco Switch and monitor with Zabbix 6.4
For anyone having snmptrapd fail to start with 255 exception and an unrecognized character, I had to edit the string in /etc/snmp/snmptrapd.conf to replace the double quotes with the proper double quotes. I believe this website replaces them. so I needed to replace ” with “.
Great guide!