sujinsr 0 Newbie Poster

I have the nagios with two host. one is localhost(10.10.62.5) and another one is ubuntu(10.10.62.10). i set up nagios monitor on localhost.

host configuration files are below

localhost.cfg:

define host{
    use                     linux-server           
    host_name               localhost
    alias                   localhost
    address                 10.10.62.5
    }

define service{ 
host_name       localhost   
service_description WSN_COUNT   
is_volatile     1   
check_command       check-host-alive    
max_check_attempts  1
normal_check_interval   1
retry_check_interval    1
active_checks_enabled   0   
passive_checks_enabled  1   
check_period        24x7    
notification_interval   31536000    
notification_period 24x7    
notification_options    w,u,c   
notifications_enabled   1
 }

ubuntu.cfg:

define host{
  use    linux-server
  host_name ubuntu
  alias  ubuntu
  address    10.10.62.10
}
define service{ 
host_name    localhost  
service_description WSN_COUNT   
is_volatile  1  
check_command    check-host-alive   
max_check_attempts  1
normal_check_interval   1
retry_check_interval    1
active_checks_enabled   0   
passive_checks_enabled  1   
check_period     24x7   
notification_interval   31536000    
notification_period 24x7    
notification_options    w,u,c   
notifications_enabled   1
}

MIBfile:

NAGIOS-TRAP-TEST-MIB DEFINITIONS ::= BEGIN
IMPORTS enterprises FROM SNMPv2-SMI;

nagiostests OBJECT IDENTIFIER ::= { enterprises 0 }
nagiostraps OBJECT IDENTIFIER ::= { nagiostests 1 }
nagiosnotifs OBJECT IDENTIFIER ::= { nagiostests 2 }

WSNcount NOTIFICATION-TYPE
        OBJECTS { sysLocation }
        STATUS current
        DESCRIPTION "SNMPv2c notification"
        ::= { nagiosnotifs 9 }
END

I used snmptt(net-snmp) to integrate the traps with nagios. configuration files are

snmptt.conf.local:

   EVENT WSNcount .1.3.6.1.4.1.0.2.1 "Status Events" Normal
FORMAT SNMPv2c notification $*
EXEC /usr/local/nagios/libexec/eventhandlers/submit_check_result localhost WSN_COUNT 1 "SNMPv2c notification $*"
SDESC
SNMPv2c notification
Variables:
  1: sysLocation
EDESC

snmptt.conf.local:

EVENT WSNcount .1.3.6.1.4.1.0.2.1 "Status Events" Normal
FORMAT SNMPv2c notification $*
EXEC /usr/local/nagios/libexec/eventhandlers/submit_check_result ubuntu WSN_COUNT 1 "SNMPv2c notification $*"
SDESC
SNMPv2c notification
Variables:
   1: sysLocation
EDESC

When i sending trap from ubuntu(10.10.62.10) machine using following command, trap sending to both hosts in nagios.

    snmptrap -v 2c -c private 10.10.62.5 "" NAGIOS-TRAP-TEST-MIB::RFIDcount SNMPv2-MIB::sysLocation.0 s "snmptest trap"

PLEASE help me with send trap to particular host.. how it is possible...

Dani AI

Generated

Quick diagnosis and one critical fix first: the service in your ubuntu.cfg is tied to localhost (typo) rather than to ubuntu. That single mistake makes Nagios treat the WSN_COUNT service as belonging to the wrong host. Correct that service host_name to match the ubuntu host, restart Nagios, then re-check behavior — this may already resolve the confusion.

Why both traps are being acted on: snmptt executes every EVENT whose OID matches the incoming trap. Having two EVENT blocks with the same OID (one EXEC targeting localhost, one EXEC targeting ubuntu) causes both EXEC lines to run for a single trap. Two safe approaches:

  • Consolidate to one EVENT and route to the correct Nagios host at runtime. Use a small wrapper script that maps the trap sender IP to the Nagios host_name and then calls Nagios to submit the passive result. Example wrapper (place it somewhere like /usr/local/bin/trap_to_nagios.sh, make executable):
#!/bin/sh
sender="$1"
shift
message="$*"

case "$sender" in
  10.10.62.10) host="ubuntu" ;;
  10.10.62.5)  host="localhost" ;;
  *) host="$sender" ;;
esac

cmd=$(command -v submit_check_result || echo /usr/local/nagios/libexec/eventhandlers/submit_check_result)
exec "$cmd" "$host" "WSN_COUNT" 1 "$message"

In the snmptt EXEC line call that wrapper, passing the trap sender and varbind text (e.g., EXEC /usr/local/bin/trap_to_nagios.sh $rhost "$*").

  • Or, instead of IP mapping, match on a varbind (sysLocation or another variable) inside snmptt and only EXEC when it matches the expected value — that keeps everything driven by trap contents rather than source IP.

Other notes: ensure the Nagios host_name in your mapping matches exactly the host_name used by Nagios; make the wrapper executable and owned by the snmptt user; restart snmptt/snmptrapd and Nagios after changes; be careful to quote variables to avoid shell injection. See the snmptt and snmptrapd docs for variable names and handler usage: SNMPTT project page and Net-SNMP snmptrapd manual.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.