Source
#!/usr/bin/env perl
#
# Copyright (C) 2001-2025 Zabbix SIA
#
# This program is free software: you can redistribute it and/or modify it under the terms of
# the GNU Affero General Public License as published by the Free Software Foundation, version 3.
#
# This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
# without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License along with this program.
# If not, see <https://www.gnu.org/licenses/>.
#
#########################################
#### ABOUT ZABBIX SNMP TRAP RECEIVER ####
#########################################
# This is an embedded perl SNMP trapper receiver designed for sending data to the server.
# The receiver will pass the received SNMP traps to Zabbix server or proxy running on the
# same machine. Please configure the server/proxy accordingly.
#
# Read more about using embedded perl with Net-SNMP:
# http://net-snmp.sourceforge.net/wiki/index.php/Tut:Extending_snmpd_using_perl
#################################################
#### ZABBIX SNMP TRAP RECEIVER CONFIGURATION ####
#################################################
### Option: SNMPTrapperFile
# Temporary file used for passing data to the server (or proxy). Must be the same
# as in the server (or proxy) configuration file.
#
# Mandatory: yes
# Default:
$SNMPTrapperFile = '/tmp/zabbix_traps.tmp';
### Option: DateTimeFormat
# The date time format in strftime() format. Please make sure to have a corresponding
# log time format for the SNMP trap items.
#
# Mandatory: yes
# Default:
$DateTimeFormat = '%Y-%m-%dT%T%z';
###################################
#### ZABBIX SNMP TRAP RECEIVER ####
###################################
use qw(O_WRONLY O_APPEND O_CREAT);
use qw(strftime);
use :: ;
sub
{
my $format = shift;
my $regex = $format;
$regex =~ s/%Y/[0-9]{4}/g;
$regex =~ s/%m/[0-9]{2}/g;
$regex =~ s/%d/[0-9]{2}/g;