Scotty script written

Damien WETZEL (frs0139@trt-philips.fr)
Fri, 2 Aug 96 11:20:21 +0200

Hi evereybody,
starting from the SNMP_ShowTable of the scotty 2.01 package,
i ve written a procedure (ShowTable) which print MIB TABLE in a printable format,
i.e the rows do not exceed the width of 90 chars and you can choose
which index you want to print.
for example, if you call :

ShowTable $s ifTable [list 1..5 7..9 ] you ll get this output :
the 3rd argument is the list of indexes you want, you can put ranges

##TABLE ifTable (mcx2) :[Fri Aug 2 11:05:38 1996]:
ifIndex ifDescr ifType ifMtu ifSpeed
1 Port_Nb_:_0, PPP line ppp 1600 19200
2 Port_Nb_:_1, PPP line ppp 1600 19200
3 Port_Nb_:_2, Not configured line other 0 0
4 Port_Nb_:_3, Ethernet line ethernet-csmacd 1500 10000000

ifAdminStatus ifOperStatus ifLastChange
up down 0d 0:00:00.00
up down 0d 0:00:00.00
down down 0d 0:00:00.00
up up 0d 0:00:53.14

##FIN LECTURE DE LA TABLE ifTable

here goes the script to try it ,enjoy it .
****

# SNMP_ShowTable --
#
# Show a complete MIB table. First determine which rows are supported
# by an agent and then walk through the table. The formating code is
# ugly and should be replaced by a better version.
#
# Arguments:
# s - The SNMP session to use.
# table - The object identifier of an snmp table.

proc ShowTable {s table {which ""}} {
set nom $table
if {[mib syntax $table] != "SEQUENCE OF"} return

puts "\#\#TABLE $nom (mcx2) :\[[getdate]\]:"

# Check if we can walk the rows simultaneously. We start a walk and
# if we get a result, we will be happy. Otherwise, we will start a
# very silly walk to collect the table element by element.

set rows ""
foreach var [mib suc [mib suc $table]] {
if {[mib access $var] != "not-accessible"} {
lappend rows $var
}
}

catch {
$s walk vbl $rows {
set table $rows
break
}
}
#lets put in lis the ordered index list wanted for the table
#and adjust the new value of $table
if {$which != ""} {
set lis ""
foreach val $which {
if {[regsub "\\.\\." $val " " ch]} {
set ch [split $ch];set i [lindex $ch 0];#set j [lindex $ch 1]
for {} {$i <= [lindex $ch 1]} {incr i} {
if {[lsearch -exact $lis $i] == -1 } {lappend lis $i}}
} else { if {[lsearch -exact $lis $val] == -1 } {lappend lis $val}}
}
set lis [lsort -integer $lis]
set realone ""
foreach ind $lis {
lappend realone [lindex $table [incr ind -1]]
}
set table $realone;unset realone

}

# Now walk through the table and fill the array named value,
# indexed by row name : instance identifier, e.g.
# value(ifType:1) "le0"
# value(ifType:2) "le1"
# The lists xorder and yorder contain the order of the row
# names (xorder) and the instance identifier (yorder).

set xorder ""
set yorder ""
if [catch {
$s walk vbl $table {
foreach vb $vbl {
set oid [lindex $vb 0]
set syn [lindex $vb 1]
set val [lindex $vb 2]

set lname [split [mib name $oid] .]
set pfx [lindex $lname 0]
set idx [join [lrange $lname 1 end] .]

if {[lsearch $xorder $pfx] < 0} {
lappend xorder $pfx
}
if {[lsearch $yorder $idx] < 0} {
lappend yorder $idx
}
set value($pfx:$idx) $val
}
}
} msg] {
puts $msg
return
}

if {![info exists xorder] || ![info exists yorder]} {
return
}

# Calculate the max. length of all values for every row.


foreach pfx $xorder {
set xindex($pfx) [string length $pfx]
foreach n [array names value $pfx:*] {
set len [string length $value($n)]
if {$len > $xindex($pfx)} {
set xindex($pfx) $len
}
}
}
# Try to display the table as a table. This is still no good solution...

while {[array names xindex] != ""} {
set foo ""
set total 0;set nb 0
set fmt ""
set txt ""
foreach pfx $xorder {
incr total $xindex($pfx)
incr total 2
if { $total > 90 } {break}
incr nb
}
set pass 0
foreach pfx $xorder {
incr pass
incr total $xindex($pfx)
incr total 2
set fmt " %$xindex($pfx)s"
append txt [format $fmt $pfx]
lappend foo $pfx
if {$pass == $nb} {break}
}
puts $txt
foreach idx $yorder {
set txt ""
foreach pfx $foo {
set fmt " %$xindex($pfx)s"
# note, large table may be inconsistend
if [catch {format $fmt $value($pfx:$idx)} xxx] {
set xxx [format $fmt "?"]
}
append txt $xxx
}
puts $txt
}
foreach pfx $foo {
unset xindex($pfx)
}
set xorder [lrange $xorder $nb end]
puts "\n"
}
puts "\#\#FIN LECTURE DE LA TABLE $nom"

}

if {[catch {snmp session -alias mcx2} s]} {
puts stderr $s
exit
}

ShowTable $s ifTable [list 1..5 7..9 ]
exit
***

-- 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
DAMIEN WETZEL  (Networks Engineer)           ("`-/")_.-'"``-._
PHILIPS PCE   BPI 51                         . . `; -._    )-;-,_`)
16,avenue Descartes                         (v_,)'  _  )`-.\  ``-'
92352 Le Plessis-Robinson (France)          _.- _..-_/ / ((.'
voice:+33(1)41287674 fax:+33(1)41287588   ((,.-'   ((,/            
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~