#!/bin/sh
# Tcl sees the next lines as an assignment to variable `kludge'.
# For sh, the two shifts cancel the effect of the set, and then we
# run scotty on this script.

set kludge { $*
    shift
    shift
    if test -f ../scotty ; then
      exec ../scotty -nf $0 $*
    else
      exec scotty -nf $0 $*
    fi
}

##
## This functions is called whenever an SNMP trap is received.
##

proc traphandler {ip args} {
    set msg "SNMP trap from $ip:"
    foreach vb $args {
	append msg " [mib name [lindex $vb 0]]=\"[lindex $vb 2]\""
    }
    syslog critical $msg
}

set v1 [snmp session -port 162]
set v2 [snmp session \
	-dstparty "1.3.6.1.6.3.3.1.3.0.0.0.0.1 UDP 0.0.0.0 162 484" \
	-srcparty "1.3.6.1.6.3.3.1.3.0.0.0.0.2 UDP 0.0.0.0 162 484" \
	-context 1.3.6.1.6.3.3.1.4.0.0.0.0.1]

$v1 bind "" trap "traphandler %A %V"
$v2 bind "" trap "traphandler %A %V"
