Monitoring a DisplayString variable, solution

Magnus Svavarsson (magnus@hum.auc.dk)
Mon, 2 Sep 1996 20:59:42 +0200 (MET DST)

Hi again

I probably should not have sent the previous mail about monitoring a
DisplayString variable. Of course I could not wait for an answer, so I
started looking at it myself.

The specific problem was, that I wanted to monitor the display of several
HP LaserJet 4M+ printers. I can now do this with the normal "Monitor
Variable" menu. I now accept OCTET STRING as a valid type. The graph,
which I at first wanted to remove, does help in seeing the status over
time. The display strings have numerical codes as the first two chars,
and I use those for the graph. (On one occation the first two chars are
"PK"--I change that to the number 10).

If anyone is interrested in this "hack", or would like to do some similar
local changes, the patch follows.

Hope this can help someone. It will certainly help me to solve "The
printer does not work!" problems where the printer is out of paper ;-)

Magnus

PS: I have not done any tcl programming before, so please do not flame me
if the code has some flaws. But the changes are very small.

*** snmp_monitor.tcl.-960902-18:26 Mon Aug 19 17:15:26 1996
--- snmp_monitor.tcl Mon Sep 2 20:41:49 1996
***************
*** 121,126 ****
--- 121,131 ----
set val 0
switch -glob $syntax {
Gauge -
+ "OCTET STRING" {
+ set val [lindex $value 0]
+ # This value is set so I can see "INSERT A4" as 10.
+ if {$val == "PK"} { set val {10} }
+ }
INTEGER {
set val $value
}
***************
*** 134,140 ****
}
}
ined -noupdate values $id $val
! ined -noupdate attribute $id $cx(descr,$id) "$cx(descr,$id) $val"
set cx(value,$id) $value
set cx(time,$id) $now
set txt "[ined -noupdate name $id] $cx(descr,$id)"
--- 139,149 ----
}
}
ined -noupdate values $id $val
! if {$syntax != "OCTET STRING"} {
! ined -noupdate attribute $id $cx(descr,$id) "$cx(descr,$id) $val"
! } else {
! ined -noupdate attribute $id $cx(descr,$id) "$value"
! }
set cx(value,$id) $value
set cx(time,$id) $now
set txt "[ined -noupdate name $id] $cx(descr,$id)"
***************
*** 210,217 ****
proc MonitorVariable {list varname} {
ForeachIpNode id ip host $list {
set s [SnmpOpen $id $ip]
! set syntaxList "Gauge Counter Counter32 Counter64 INTEGER"
set vars ""

set err [catch {$s get $varname} vbl]
if {$err || [lindex [lindex $vbl 0] 1] == "noSuchInstance"} {
--- 219,227 ----
proc MonitorVariable {list varname} {
ForeachIpNode id ip host $list {
set s [SnmpOpen $id $ip]
! set syntaxList "Gauge Counter Counter32 Counter64 INTEGER {OCTET STRING}"
set vars ""
+

set err [catch {$s get $varname} vbl]
if {$err || [lindex [lindex $vbl 0] 1] == "noSuchInstance"} {
***************
*** 218,224 ****
if {[catch {
$s walk vbl $varname {
set syntax [lindex [lindex $vbl 0] 1]
! if {[lsearch $syntaxList $syntax] >= 0} {
lappend vars [lindex [lindex $vbl 0] 0]
}
}
--- 228,234 ----
if {[catch {
$s walk vbl $varname {
set syntax [lindex [lindex $vbl 0] 1]
! if {[lsearch $syntaxList "$syntax"] >= 0} {
lappend vars [lindex [lindex $vbl 0] 0]
}
}