Some tkined1.4.5 patches for Monitor Jobs

Stephen L. Johnson (sjohnson@godzilla.monsters.org)
Wed, 12 Mar 1997 01:50:13 -0600

This is a multipart MIME message.

--==_Exmh_-21255390470
Content-Type: text/plain; charset=us-ascii

We have been using scotty at work for quite a while. We've been using it for
diagnosing WAN problems, monitoring the network in general, monitoring UNIX
systems via rstatd and SNMP, and gathering network utilization statistics. And
along the way I've added some functionality that I've felt that has been
missing from the tkined application TCL scripts. These are just minor things,
but they are thigs that we use alot.

All of these patches are for the scotty ver 2.1.5 (tkined 1.4.5). This first
patch is for the library.tcl script in the .../tkined.1.4.5/apps/ directory.
It add two new Monitor Job actions 'mail' and 'log'.

The 'mail' action will send an e-mail message with the Subject and Message of
the text written to the 'write' and 'syslog' actions. I've added the 'Mail
To' entry field to the Modify Montior Job requester. These will the addresses
for the e-mail 'To:' first. The routine will also look for a 'Monitor:MailTo"
attribute. You can add a 'Monitor.MailTo' line to the tkined.defaults for a
generic default.

The 'log' action is similar to the 'syslog' action but the action text is
added to a specified log file. I've added the 'Log File' entry field to the
Modify Monitor Job requester. Put name of the file to log the entries into.
The routine look for a 'Monitor:LogFile' attribute. And you can add
'Monitor.LogFile' to the tkined defaults for a genric default.

I've tested the Log file loging with 5 monitoring jobs logging to the same
file with intervals of 1 second without any problems. But you might run into
some contention problems with multiple jobs logging to the same file. If any
one has any suggestions on how to handle it better, please let me know.

The rest of the patches will be coming one I've had a chance to clean up my
code. The next will be an Interface Selection Requestor for the 'Interface
Load' option on the SNMP-Monitor menu. It's been quite handle when dealiing
with routers that have 12 or more interfaces.

Stephen L. Johnson
sjohnson@monsters.org

--==_Exmh_-21255390470
Content-Type: application/octet-stream ; name="library.tcl.diff"
Content-Description: library.tcl.diff
Content-Disposition: attachment; filename="library.tcl.diff"

--- library.tcl-old Wed Mar 12 00:41:42 1997
+++ library.tcl Wed Mar 12 00:47:34 1997
@@ -417,6 +417,12 @@
if {![info exists threshold(action,$jobid)]} {
set threshold(action,$jobid) "flash"
}
+ if {![info exists threshold(mailto,$jobid)]} {
+ set threshold(mailto,$jobid) ""
+ }
+ if {![info exists threshold(logfile,$jobid)]} {
+ set threshold(logfile,$jobid) ""
+ }

# Get the details about the selected job.

@@ -452,6 +458,8 @@
set rising $threshold(rising,$jobid)
set falling $threshold(falling,$jobid)
set action $threshold(action,$jobid)
+ set mailto $threshold(mailto,$jobid)
+ set logfile $threshold(logfile,$jobid)

set res [ined request "Modify $jobid ([lindex $jobcmd 0] $hosts)" \
[list [list "Intervaltime \[s\]:" $jobitv entry 10] \
@@ -459,7 +467,9 @@
[list "Falling Threshold:" $falling entry 10] \
[list "Rising Threshold:" $rising entry 10] \
[list "Threshold action:" \
- $action check syslog flash write] ] \
+ $action check syslog flash write mail log] \
+ [list "Mail To \[mail\]:" $mailto entry 10] \
+ [list "Log File Name \[log\]:" $logfile entry 10] ] \
[list modify "kill job" cancel] ]

if {[lindex $res 0] == "cancel"} return
@@ -474,10 +484,14 @@
set falling [lindex $res 3]
set rising [lindex $res 4]
set action [lindex $res 5]
+ set mailto [lindex $res 6]
+ set logfile [lindex $res 7]

set threshold(rising,$jobid) $rising
set threshold(falling,$jobid) $falling
set threshold(action,$jobid) $action
+ set threshold(mailto,$jobid) $mailto
+ set threshold(logfile,$jobid) $logfile

if {$jobstat == "active"} { $jobid configure -status waiting }
if {$jobstat == "suspend"} { $jobid configure -status suspended }
@@ -507,6 +521,8 @@
catch {ined attribute $id Monitor:RisingThreshold $rising}
catch {ined attribute $id Monitor:FallingThreshold $falling}
catch {ined attribute $id Monitor:ThresholdAction $action}
+ catch {ined attribute $id Monitor:MailTo $mailto}
+ catch {ined attribute $id Monitor:LogFile $logfile}
}
}

@@ -591,8 +607,90 @@
writeln $msg
writeln
}
+ if {[lsearch $action mail] <= 0} {
+ MoJoMail $id $msg
+ }
+ if {[lsearch $action log] <= 0} {
+ MoJoLog $id $msg
+ }
+}
+
+##
+## Send an e-mail messages for a Threshold action
+##
+
+proc MoJoMail { id msg } {
+ global default
+
+ if {[catch {split $env(PATH) :} path]} {
+ set path "/usr/bin /bin /usr/ucb /usr/local/bin"
+ }
+
+ set mprog ""
+ foreach mailer "Mail mail" {
+ foreach dir $path {
+ set fname $dir/$mailer
+ if {[file executable $fname] && [file isfile $fname]} {
+ set mprog $fname
+ break
+ }
+ }
+ if {$mprog != ""} break
+ }
+
+ if {$mprog == ""} {
+ debug "Can not find mail program"
+ return
+ }
+
+ set to [ined attribute $id Monitor:MailTo]
+ if {$to == ""} {
+ if {[info exists default(Monitor.MailTo)]} {
+ set to $default(Monitor.MailTo)
+ }
+ }
+
+ if {$to == ""} {return}
+
+ if {[catch {open "|$mprog -s \"$msg\" $to" w} file]} {
+ debug "Unable to write to $mprog $to"
+ return
+ }
+
+ puts $file $msg
+ close $file
}

+###
+### Write message to a file for MoJoAction log.
+###
+proc MoJoLog { id msg } {
+ global default
+
+ set logfile [ined attribute $id Monitor:LogFile]
+ if {$logfile == ""} {
+ if {[info exists default(Monitor.LogFile)]} {
+ set logfile $default(Monitor.LogFile)
+ }
+ }
+
+ if {$logfile == ""} {
+ return
+ }
+
+ if {![file writable $logfile] && [file isfile $logfile]} {
+ debug "File $logfile is not writable."
+ }
+
+ if {[catch {open $logfile a+} file]} {
+ debug "Unable to open file $logfile."
+ return
+ }
+
+ puts $file $msg
+ close $file
+}
+
##
## Set the default parameters for monitoring jobs.
##
@@ -613,7 +711,6 @@

if {$interval<1} { set interval 1 }
}
-

##
## =========================================================================

--==_Exmh_-21255390470--

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