[tkined] straps problems on FreeBSD-2.2.5

Paul Koch (pak@mns.com.au)
Thu, 23 Apr 1998 12:05:45 +1000 (EST)

I have a small script (attached below) which is used to collect trap
messages. This script is called from a C program called snmptrapd.

Setup:
FreeBSD 2.2.5
Tcl8.0p2
Tk8.0p2
scotty-2.1.8

At startup, snmptrapd forks&execv the snmptrapd.tcl script which starts
the straps daemon. Everything appears to operate correctly. After a day
or so, it would appear that the snmptrapd.tcl script no longer receives
any trap packets from the straps daemon. I know there are traps being
sent because I generate some from a router. If I kill off the snmptrapd
C program, it inturn kills off the snmptrapd.tcl script, but the straps
daemon stays running. Since the straps process is suid to root, my snmptrapd
program can't kill it off because it is running as a normal user.

If I manually kill off straps and restart everything, all traps are received
OK.

Should the straps daemon exit after the last copy of snmptrapd.tcl
exits ? I looked at the code for straps which has comments saying it should.

The following is the snmptrapd.tcl script:
-------------------------------------------------------------------------------

#!/usr/local/netsmart/bin/scotty

global env
cd $env(HOME)

set MIBS_DIR /usr/local/netsmart/lib/mibs

if { [file exists conf/snmptrapd.cfg] } {
set mibs_conf [open conf/snmptrapd.cfg]
} else {
puts stderr "Could not open conf/snmptrapd.cfg"
exit 0
}
while { [gets $mibs_conf mib] != -1 } {
if { [file exists $MIBS_DIR/$mib] } {
mib load $MIBS_DIR/$mib
}
}
close $mibs_conf

proc traphandler {ip args} {
set ip_address [format "%-15s" $ip]
set trap_message ""

foreach vb $args {
set trap_entry [mib name [lindex $vb 0]]
set syntax [lindex $vb 1]

#
# Turn all hex encoded trap messages back to plain text.
#
if { $syntax == "DisplayString" } {
set trap_value [mib format SNMPv2-MIB!sysDescr [lindex $vb 2]]
} elseif { $syntax == "OCTET STRING" } {
set trap_value [mib format SNMPv2-MIB!sysDescr [lindex $vb 2]]
} else {
set trap_value [lindex $vb 2]
}

#
# Strip out stuff which is generally not very interesting.
#
if { $trap_entry == "sysUpTime.0" } {
} elseif { $trap_entry == "snmpTrapEnterprise.0" } {
} elseif { $trap_entry == "snmpTrapOID.0" } {
append trap_message " [mib name $trap_value]"
} else {
append trap_message " $trap_entry=\"$trap_value\""
}
}
if [catch {
puts stdout "$ip_address $trap_message"
flush stdout
} result] {
exit 0
}
}

catch {
set s [snmp session -version SNMPv1]
$s bind "" trap "traphandler %A %V"
}

catch {
set s [snmp session -version SNMPv2C]
$s bind "" trap "traphandler %A %V"
}

catch {
set s [snmp session -version SNMPv2U]
$s bind "" trap "traphandler %A %V"
}

----------------------------------------------------------------------------
Paul Koch
Director, Support and Development NetSMART Network Monitoring Services
Email: pak@mns.com.au Micro Network Services Pty Ltd
Web: http://www.mns.com.au Level 6, 360 Queens St,
Phone: +61 7 3229 4750 Brisbane, Queensland, Australia
Fax: +61 7 3229 4506
----------------------------------------------------------------------------

--
!! This message is brought to you via the `tkined & scotty' mailing list.
!! Please do not reply to this message to unsubscribe. To subscribe or
!! unsubscribe, send a mail message to <tkined-request@ibr.cs.tu-bs.de>.
!! See http://wwwsnmp.cs.utwente.nl/~schoenw/scotty/ for more information.