Re: [tkined] display question

From: Max Kalika (max@the-triumvirate.net)
Date: Fri Mar 16 2001 - 17:56:01 MET


Quoting Juergen Schoenwaelder <schoenw@ibr.cs.tu-bs.de>:

> Someone has to implement it first.

Well, I took a crack at it. It can probably be done a million times better,
but not knowing any TCL I was at a slight disadvantage. In any case, the diff
is below if anyone cares. It is against lib/tkined1.5.0/apps/snmp_monitor.tcl

--mk23

[root@host apps]# diff -U0 snmp_monitor.tcl.orig snmp_monitor.tcl
--- snmp_monitor.tcl.orig Thu Sep 14 06:06:15 2000
+++ snmp_monitor.tcl Fri Mar 16 09:52:03 2001
@@ -3 +3 @@
-exec tclsh8.3 "$0" "$@"
+exec tclsh8.3 "$0" "$@"
@@ -47,0 +48,6 @@
+proc CreateText {id x y} {
+ global default
+ set id [CloneNode $id [ined create TEXT {}] $x $y]
+ return $id
+}
+
@@ -204,0 +211,73 @@
+proc ShowTextVariable { ids } {
+ global cx
+
+ foreach id $ids {
+ if {$id != ""} {
+ if {[catch {$cx(snmp,$id) get [list $cx(uptime,$id) $cx
(name,$id)]} vbl]} {
+ set name [ined -noupdate name $id]
+ writeln "Unable to restart monitor job on $name.\nSNMP get
failed: $vbl\n"
+ $s destroy
+ ined delete $id
+ continue
+ }
+ if {[snmp type $vbl 1] == "TimeTicks"} {
+ set cx(value,$id) [expr [lindex [lindex $vbl 1] 2] / 6000]
+ } else {
+ set cx(value,$id) [lindex [lindex $vbl 1] 2]
+ }
+ ined -noupdate text $id "$cx(prefix,$id): $cx(value,$id)"
+ }
+ }
+}
+
+proc start_snmp_text_monitor { ip uptime args } {
+ global cx interval
+
+ set ids ""
+ set re_args ""
+
+ while {$args != ""} {
+ set id [lindex $args 0]
+ set var [lindex $args 1]
+ set prefix [lindex $args 2]
+
+ if {$id != ""} {
+ set s [SnmpOpen $id $ip]
+ if {[catch {$s get [list $uptime $var]} vbl]} {
+ set name [ined -noupdate name $id]
+ writeln "Unable to restart monitor job on $name.\nSNMP get
failed: $vbl\n"
+ $s destroy
+ set args [lrange $args 3 end]
+ ined delete $id
+ continue
+ }
+ set cx(time,$id) [lindex [lindex $vbl 0] 2]
+ if {[snmp type $vbl 0] == "TimeTicks"} {
+ set cx(value,$id) [expr [lindex [lindex $vbl 1] 2] / 6000]
+ } else {
+ set cx(value,$id) [lindex [lindex $vbl 1] 2]
+ }
+ set cx(snmp,$id) $s
+ set cx(name,$id) $var
+ set cx(addr,$id) $ip
+ set cx(uptime,$id) $uptime
+ set cx(prefix,$id) $prefix
+ set cx(descr,$id) [mib name [mib oid $var]]
+ set cx(label,$id) [mib label [mib oid $var]]
+ lappend ids $id
+
+ ined -noupdate attribute $id $cx(descr,$id) $cx(descr,$id)
+ ined -noupdate text $id "$cx(prefix,$id): $cx(value,$id)"
+ }
+
+ set args [lrange $args 3 end]
+ append re_args " \$$id $var {$prefix}"
+ }
+
+ if {$ids != ""} {
+ set jid [job create -command [list ShowTextVariable $ids] \
+ -interval [expr $interval * 1000]]
+ save "restart start_snmp_text_monitor $interval $jid $ip $uptime
$re_args"
+ }
+}
+
@@ -307,4 +385,0 @@
- if {[mib syntax $var] != "TimeTicks"} {
- ined acknowledge "Time base variable not of type TimeTicks."
- return
- }
@@ -326,0 +402,101 @@
+proc MonitorTextVariable {list uptime varname prefix} {
+ ForeachIpNode id ip host $list {
+ set s [SnmpOpen $id $ip]
+
+ set err [catch {$s get $uptime} vbl]
+ if {$err || [snmp type $vbl 0] == "noSuchInstance"} {
+ ined acknowledge "Time base problem on $ip: $vbl"
+ $s destroy
+ return ""
+ }
+
+ set candidates {}
+ set err [catch {$s get $varname} vbl]
+ if {! $err && [snmp type $vbl 0] != "noSuchInstance"} {
+ lappend candidates $vbl
+ } else {
+ if {[catch {
+ $s walk vbl $varname {
+ lappend candidates $vbl
+ }
+ } msg]} {
+ ined acknowledge "Monitor Variable $varname on $ip: $msg"
+ $s destroy
+ return ""
+ }
+ }
+
+ set vars {}
+ foreach vbl $candidates {
+ set oid [snmp oid $vbl 0]
+ set type [snmp type $vbl 0]
+ set enums [mib enums [mib type $oid]]
+ if {[string length $enums]} {
+ writeln "$host: [mib name $oid] with enumeration ignored"
+ continue
+ }
+ lappend vars $oid
+ }
+
+ if {$vars == ""} {
+ ined acknowledge \
+ "$varname is either not available or of wrong type."
+ continue
+ }
+
+ set args $ip
+ lappend args $uptime
+ set i 0
+ foreach var $vars {
+ set nid [CreateText $id [expr 30+$i] [expr 30+$i]]
+ ined -noupdate attribute $nid "SNMP:Config" [$s configure]
+ lappend args $nid
+ lappend args $var
+ lappend args $prefix
+ incr i
+ }
+ $s destroy
+
+ eval start_snmp_text_monitor $args
+ }
+}
+
+proc "Monitor Text Variable" { list } {
+
+ static varname uptime prefix
+
+ if {![info exists varname]} {
+ set varname IP-MIB!ipForwDatagrams
+ }
+ if {![info exists uptime]} {
+ set uptime SNMPv2-MIB!sysUpTime.0
+ }
+
+ set res [ined request "Fill in the SNMP variables to be monitored:" \
+ [list [list "Variables:" $varname] \
+ [list "Time base:" $uptime] \
+ [list "Text label:" {}]] \
+ [list start cancel] ]
+ if {[lindex $res 0] == "cancel"} return
+
+ set var [lindex $res 2]
+ if {[catch {mib oid $var}]} {
+ ined acknowledge "Unknown SNMP variable \"$var\"."
+ return
+ }
+ set uptime $var
+
+ set varname ""
+ foreach var [lindex $res 1] {
+ if {[catch {mib oid $var}]} {
+ ined acknowledge "Unknown SNMP variable \"$var\"."
+ continue
+ }
+ lappend varname $var
+ }
+
+ foreach var $varname {
+ MonitorTextVariable $list $uptime $var [lindex $res 3]
+ }
+}
+
@@ -996 +1172 @@
- "Monitor Variable" "" \
+ "Monitor Variable" "Monitor Text Variable" "" \

--
!! 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.



This archive was generated by hypermail 2b29 : Thu Jan 03 2002 - 14:56:26 MET