Ascend Archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

(ASCEND) Little Session Watcher (requires Scotty)



Hi,

I thought I'll never write a TCL script again but as need pressures...
The following small script for Scotty effectively displays the
sessionActiveTable continuously on a VT100 style terminal. No bells
or whistles, no session time, if{In,Out}Octets or such (thanks to the
not yet working callActiveTable), simply what's there in the table.
The text contains some literal ESC controls, if they get destroyed
on your mail path reenter them (you know - ^V does it).

Have fun,
Andre.

----------------------- bite edge --------------------------------
#!/usr/local/bin/scotty2.1.5
#
# Show current sessions on an Ascend MAX. Effectively a continuing dump
# of sessionActiveTable but with some optimization for SNMP traffic
# reduction
#
# ---abp 1998010600
#

# The interval to check for changes on the MAX. Causes at least one SNMP GET
# roundtrip every ivSecs

set ivSecs 3
set ivmSecs [expr $ivSecs * 1000]

# This is exploded some times into one string, so we better precompute

set ev "1.3.6.1.4.1.529.12.3.1"

# We could also precompute those and wouldn't even need the Ascend MIBs.
# But the Ascend MIBs are required to interpret output correctly, so we
# don't care

set queryS "$ev.ssnActiveUserName $ev.ssnActiveUserIPAddress $ev.ssnActiveUserSubnetMask $ev.ssnActiveCurrentService"

# Terminal control stuff - hardcoded for now. Dunno of a TCL interface to
# terminfo - and what gives, Ascend Users have VT100 compatible output
# anyway ;)

set clear "\[2J"
set home "\[H"
set cleol "\[K"
set cleos "\[J"
set high "\[7m"
set bold "\[1m"
set norm "\[m"

# Usage - may be called with agent and community as parameters

set agent [lindex $argv 0]
 
if {$agent == ""} {
 set agent max
}

set comm [lindex $argv 1]
 
if {$comm == ""} {
 set comm "public"
}

set header [format "${home}${high}User                 IP               Mask             Service ${bold}%16.16s${norm}${cleol}\n${cleol}" $agent]

# Do something on the screen to pretend a fast system

puts "${clear}${header}"
 
# "Connect"
 
set s [snmp session -address $agent -community $comm -timeout 3 -retries 10]

# Should suffice that the next check indicates something changed
set lastEV 0

# The do-it-actually procedure

proc UpdateStats {s} {

 global ivSecs
 global ivmSecs
 global logVals
 global queryS
 global queryEV
 global lastEV
 global agent
 global header
 global cleos
 global cleol
 global high norm bold clear

 set tStamp [getclock]

# We check whether any event occured and return if not
# The catch boilerplate is to prevent the script from failing if
# SNMP times out for whatever reason. Displays an error instead.

 if {
  [catch {
   set currEV [lindex [lindex [
    $s get "ascend.eventGroup.eventLatestEventIdNumber.0"
   ] 0] 2]
  }]
 } {
  puts "${clear}${header}\n${high}No answer from $agent${norm}"
  return
 }

 if { $currEV == $lastEV } return

# Something happened

 set lastEV $currEV

# Start screen output

 puts $header

# Walk the sessionStatusTable for the relevant values. Format them nicely
# and disturb the screen with it

 if {
  [catch {
   $s walk x $queryS {
    puts [format "${bold}%-20s${norm} %-16s %-16s %-8s${cleol}" [lindex [lindex $x 0] 2] \
          [lindex [lindex $x 1] 2] \
          [lindex [lindex $x 2] 2] \
          [lindex [lindex $x 3] 2] \
         ]
   }
  }]
 } {
  puts "${clear}${header}\n${high}No answer from $agent${norm}"
  return
 }

# Instead of clearing the screen on output start we use clear-to-end-of-line
# and clear-to-end-of-screen to optimize output quality

 puts -nonewline $cleos
 flush stdout
}

# First output

UpdateStats $s

# And now every ivSecs the same...

job create -command {UpdateStats $s} -interval $ivmSecs

-------- bite here --------- bite here --------- bite here -------

-- 

Kanther-Line: PGP SSH IDEA MD5 GOST RIPE-MD160 3DES RSA FEAL32 RC4

+-o-+--------------------------------------------------------+-o-+
| o |               \\\- Brain Inside -///                   | o |
| o |                   ^^^^^^^^^^^^^^                       | o |
| o | Andre' Beck (ABPSoft) beck@ibh-dd.de XLink PoP Dresden | o |
+-o-+--------------------------------------------------------+-o-+
++ Ascend Users Mailing List ++
To unsubscribe:	send unsubscribe to ascend-users-request@bungi.com
To get FAQ'd:	<http://www.nealis.net/ascend/faq>