Re: [tkined] TimeTicks format

From: philippe mounier (mounier@enac.fr)
Date: Tue Jul 03 2001 - 13:53:24 MET DST


Hi,

I'm OK with George Ross.....
But when you use this value for display , it's not very nice....

For example when you receive trap ...

Stefan Finzel (finzel@osn.de) send me code for a procedure to convert format

here is code :

proc duration {dur {div 1} {overflow pow(2,32)}} {
#--------------------------------------------------------------------------
# get duration string (days %H:%M:%S) from 1/${div} seconds count;
# try to handle overflows too
#To get the sysUpTime (measured in 1/100 s) in a more readable form use
#duration [lindex [snmp0 get sysUpTime.0] 2] 100
#--------------------------------------------------------------------------
set offset 0
if {[llength ${overflow}] &&(${dur} < 0) &&(1 < ${div})} {
# frink-1.3.x: avoid formating by eval
set offset [eval expr "${overflow} / ${div}"]
}
set dur [expr {round(${dur} / ${div} + ${offset})}]
foreach {val div} {secs 60 mins 60 hours 24} {
# FRINK: nocheck
set [set val] [expr {${dur} % ${div}}]
set dur [expr {${dur} / ${div}}]
}
return [format {%dd %02d:%02d:%02d} ${dur} ${hours} ${mins} ${secs}]
}

For example I use it in file snmp_monitor.tcl

##
## Receive SNMP traps and do something useful. The later must is left
## as an exercise for the reader. :-)
##

proc TrapSinkProc {s src vbl} {
     writeln "[clock format [clock seconds]] [$s cget -version] trap from
\[$src\]:"
     foreach vb $vbl {
++ if {[mib syntax [lindex $vb 1]] == "TimeTicks"} {
++ writeln " [mib name [lindex $vb 0]] = [duration [lindex
$vb 2] 100 ]"
++ } else {
                 writeln " [mib name [lindex $vb 0]] = [lindex $vb 2]"
++ }
     }
     writeln
               ........[snip] ....

Philippe

>>>>> philippe mounier writes:

philippe> I use scotty3.0.0. Is it possible to convert TimeTicks
philippe> value in format like version 2.1.10 ?

philippe> scotty2.1.10 snmp0 get sysUpTime.0 {1.3.6.1.2.1.1.3.0
philippe> TimeTicks {19d 19:23:44.23}}

philippe> scotty3.0.0 snmp get sysUpTime.0 {1.3.6.1.2.1.1.3.0
philippe> TimeTicks {1700245214}}

The format used in 2.1.10, although it reads nicely for humans, was
considered a bug, as it makes it hard to use the value in programs.
It is the job of the application which uses the Tnm extension to
render values appropriately. The 3.0.0 version only does the
formatting that is specified in MIBs and nothing else.

There were requests in the past to have a mechanism which allows
people to write formatting/scanning hooks in Tcl. But nobody ever
submitted patches for it that could go into the distribution.

/js

--
!! 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:27 MET