#!/local/bin/tclnm

# We use this to reset a slot in an synoptics 3000 concentrator

#.1.3.6.1.4.1.45.1.3.1.8.1.5
#.iso.org.dod.internet.private.enterprises.synoptics.products.series3000 \
#       .s3000Chassis.s3CommonBoardTable.s3CommonBoardEntry.s3CommonBoardReset
# type =  Enum
# desc =  "This indicates the reset state of the board.  Writing with
#          the value reset (2) will reset the board."

set OID .1.3.6.1.4.1.45.1.3.1.8.1.5

if {$argc != 4} {
    puts stderr "Usage:\n\t[lindex $argv 0] hostname slot community" 
    exit 2
}

set host [lindex $argv 1]
set slot [lindex $argv 2]
set comm [lindex $argv 3]

set s0 [snmp open $host]

snmp default $s0 community $comm
snmp default $s0 mib ""

if {[catch {snmp get $s0 -v "$OID.$slot" a} b] } {
    puts stderr "Can't reset slot $slot of $host, reson given:\n\t$b"
    puts stderr "Probably not an Synoptics 3000 device, wrong slot or wrong community."
    exit 1
}

if {$b} {
    puts stderr "Can't reset slot $slot of $host, no response."
    exit 1
}

if {$a != 1} {
    puts stderr "Can't reset slot $slot of $host, status was: $a"
    exit 1
}

if {[catch {snmp set $s0 -v "$OID.$slot Integer 2" a} b]} {
    puts stderr "Couldn't reset slot $slot of $host, reason given:\n\t$b"
    puts stderr "Probably wrong community."
}
if {$a != 2} {
    puts stderr "Couldn't reset slot $slot of $host, status returned: $a"
    exit 1
}
puts stdout "Reset of slot $slot of $host successfull"
exit 0
