hello,
I have a problem to receive trap and add it to zabbix for some week ago!
The problem is that i receive trap from equipment ( i can see that in /var/log/messages ), when this trap is received the script snmptrap.pl is running correctly but at the end nothing appear in zabbix web page.
This is host config:

this is item config on this host :

and this is my snmptrap script:
do you have idea to resolve my problem, TX
I have a problem to receive trap and add it to zabbix for some week ago!
The problem is that i receive trap from equipment ( i can see that in /var/log/messages ), when this trap is received the script snmptrap.pl is running correctly but at the end nothing appear in zabbix web page.
This is host config:

this is item config on this host :

and this is my snmptrap script:
Code:
cat /etc/snmp/snmptrapd.conf # Example configuration file for snmptrapd # # No traps are handled by default, you must edit this file! # # authCommunity log,execute,net public disableAuthorization yes # traphandle default /bin/bash /etc/zabbix/bin/snmptrap.sh traphandle default perl /etc/zabbix/bin/snmptrap.pl cat /etc/zabbix/bin/snmptrap.pl # Version 1.0 # Author: Dennis Ploeger <[email protected]> # ############################################ # # This Script has been designed for Zabbix 1.4.4 # I don't know, if it's working with older versions, but I don't suppose so. # # Description: # A better snmp trap-handler for zabbix. To use it, add a SNMP Trapper item # (character) to any host you would like to receive traps for. # After that, create a wildcard-host with a trapper item that will receive # all snmptraps for non-existent hosts. # # To use it, add this script to the snmptrapd.conf: # # traphandle default /bin/bash {zabbix-bin-path}/snmptrap.pl touch /tmp/bidondon ; use constant TRUE => 1; use constant FALSE => 0; # configuration part # SNMP-Parsing $onlyinteresting = TRUE; # Only send interesting trap informations # (the host's uptime, the trap's oid, community and SMI-information) # Zabbix-Server $zabbix_server ="localhost"; # Hostname/IP-Address of zabbix-server $zabbix_port = 10051; # Port of zabbix-server (Default: 10051) $item = "snmptraps"; # Item to save snmptraps to # Wildcard-Host $wildcard_host = "defaultTrapperHost"; # Hostname or IP-Adress of wildcard-host within zabbix $alltowildcard = TRUE; # Send all traps to wildcard host # Mapping of hostname/ip-address to zabbix hostname # Configure, how the hostname or ipaddress from the trap should be mapped to your zabbix host # Sadly, zabbix_sender only accept the configured name of the host in zabbix, not it's hostname # or ipaddress. Hopefully this will change in future versions. # For now, you have the following possibilities to map the real hostname or the ip address gathered # from the trap to your zabbix host by configuring "mapping_method" and possibly the "mapping_option": # # mapping_method: # "hostname" - just use the received hostname from the trap # "ip" - just use the received ip address from the trap # "hostname_nonfqdn" - extract the hostname from the fqdn hostname from the trap and use that one # "mapfile" - use the contents of the mapfile given in "mapping_option" as a "<hostname>:<zabbix-host>"-map # "mapfile_ip" - same as "mapfile", but use a "<ip-address>:<zabbix-host>"-map # "regexp" - use the first group of the regexp in "mapping_option" as the zabbix-host # "regexp_ip" - like "regexp", but use the ipaddress information $mapping_method = "hostname_nonfqdn"; $mapping_option = ""; # Zabbix-Programs $path_to_zabbix = "/usr/sbin"; # Path to your zabbix-installation $zabbix_sender = $path_to_zabbix."/zabbix_sender"; # Zabbix-Sender-prog $log = "/tmp/snmptraper.log"; open(LOG,">>".$log) || die("Log file openning error !"); print LOG "snmptraphandler for Zabbix (". localtime(time).")\n"; # End of configuration section # main() # hostname_nonfqdn is basically a simple regexp if ($mapping_method eq "hostname_nonfqdn") { $mapping_method = "regexp"; $mapping_option = qr/^([^\.]*)\..*$/i; } # gather hostname and ip address $hostname = <STDIN>; chomp($hostname); $ipaddress = <STDIN>; chomp($ipaddress); # map the hostname or the ip address to the zabbix host if (!$alltowildcard) { if ($mapping_method eq "hostname") { $zabbix_host = $hostname; } elsif ($mapping_method eq "ip") { $zabbix_host = $ipaddress; } elsif ($mapping_method eq "regexp") { $hostname =~ $mapping_option; $zabbix_host = $1; } elsif ($mapping_method eq "regexp_ip") { $ipaddress =~ $mapping_option; $zabbix_host = $1; } elsif ($mapping_method =~ /^mapfile/) { # Load mapping file if (! -r $mapping_option) { print STDERR "Mapping file ($mapping_option) is not readable. Quitting.\n"; exit 1; } open (MAP, "<$mapping_option"); $map = join("\n",<MAP>); close(MAP); if ($mapping_method eq "mapfile") { $map =~ /^($hostname:[^$]*)\n/gi; $zabbix_host = $1; } elsif ($mapping_method eq "mapfile_ip") { $map =~ /($ipaddress:[^$]*)$/gi; $zabbix_host = $1; } } } else { $zabbix_host = $wildcard_host; } print LOG "[". localtime(time)."] zabbix_host= $zabbix_host\n"; $ipaddress =~ /.*\[([^]]*)\].*/; $ipaddress = $1; $command = $zabbix_sender." --zabbix-server ".$zabbix_server." --port ".$zabbix_port; while(<STDIN>) { ($oid, $value) = /([^\s]+)\s+(.*)/; print LOG "[". localtime(time)."] OID: $oid\n"; if ($onlyinteresting) { # Filter out uninteresting trap informations if (($oid !~ /sysuptimeinstance/i) && ($oid !~ /snmpv2-smi/i) && ($oid !~ /snmptrapoid/i) && ($oid !~ /snmptrapcommunity/i) ) { next; } } $str = "$oid: $value"; $str =~ s/"/\\"/gi; } print LOG "[". localtime(time)."] str= $str\n"; print LOG "[". localtime(time)."] command= $command\n"; while(1) { if ($zabbix_host eq $wildcard_host) { $str = "($hostname, $ipaddress) ".$str; } $mycommand = $command." --host $zabbix_host --key $item --value \"$str\""; $return = `$mycommand`; $return =~ /.*failed: ([0-9]*);.*/gi; if ($1 > 0) { if ($zabbix_host ne $wildcard_host) { print STDERR "Failed to send item to host. Sending it to wildcard host instead.\n"; print LOG "[". localtime(time)."] ERROR: Failed to send item to host ($zabbix_host). Sending it to wildcard host instead.\n ; $zabbix_host = $wildcard_host; } else { print STDERR "Failed to send item $str using command $mycommand\n"; print LOG "[". localtime(time)."] ERROR: Failed to send item $str using command $mycommand\n"; print LOG "[". localtime(time)."] Exiting ...\n"; close LOG; exit 1; } } else { print LOG "[". localtime(time)."] Sendind using command $mycommand was OK :!\n"; print LOG "[". localtime(time)."] Exiting ...\n"; close LOG; exit 0; } }
Comment