Re: Event notification via a pager or writing to a file.

Stephen L. Johnson (sjohnson@godzilla.monsters.org)
Wed, 09 Apr 1997 22:37:58 -0500

This is a multipart MIME message.

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

Your wish is my command. I've added e-mail notification and logging to a file
to tkined 1.4.5. I posted patch to the mailing-list a couple of weeks ago,
but I've attached the message with the patch at the end.

For pager notification, I would suggest a program called sendpage. I'm are
using it at work on our paging server, and everyone is quite pleased with it.
I don't remember exactly where I found it but you can pick it up on my FTP
server at:

ftp://godzilla.monsters.org/pub/sendpage7a.tar.Z

(While I'm at it, I'll put the patch file there also.) Sendpage runs as a
background daemon like sendmail. It's command line parameters are very similar
to sendmail; and as such, it integrates quite nicely with sendmail as a mailer
type. The only difficult thing for setup is your modem's error codes in the
sendpage.h file.

Stephen L. Johnson
sjohnson@monsters.org

------------ Start Inserted Message -------------------------------------------
-
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.

--==_Exmh_-20435286280
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_-20435286280--

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