Raritan Computer SX48 用户手册

下载
页码 172
A
PPENDIX 
H:
 
TCL
 
P
ROGRAMMING 
G
UIDE 
 139 
 
 
Generating a User Event 
TCL scripts are a powerful tool for performing true device management, in the form of customer-defined 
monitoring and notification of events. A sample script is shown below: 
 
#This script performs the monitoring of HTTP servers. 
proc pstat {procname port_num} { 
 
set psef [concat "ps -ef | grep " $procname | grep -v "grep" | wc -l] 
 
ampexec "stty -echo\r" 5 "#" $port_num 
 
set output [ampexec "$psef\r" 10 "#" $port_num] 
 
ampexec "stty echo\r" 5 "#" $port_num 
 
return [lindex $output 0] 

 
# add subscription to an event here. 
ampaddsubscription event.user.httpProcess  “xyz@xyz.com”  
 
# Run through 4 different servers to find out if HTTP service is running 
# on each one of them and trigger an event appropriately. 
for {set port_num 0} {$port_num < 4} {incr port_num +1} { 
ampclear $port_num 
amplock  $port_num 
 
set output [pstat httpd $port_num] 
ampunlock $port_num 
 
if {$output > 0} { 
     puts "HTTP_SERVER_OK $port_num" 
     amptriggerevent event.user.httpProcess “HTTP service is up and running on 
$port_num” 
} else { 
     puts " HTTP_SERVER_ERROR $port_num" 
     amptriggerevent event.user.httpProcess “HTTP service down on $port_num” 
 
In the Notification tab of the unit, the user can subscribe to either of the following: 
event.user or event.user.httpProcess to get this message: “HTTP service is up and running on 1”. To 
subscribe to user-defined events (defined in the TCL script), the event name must be specified.   
Note: This Event Name must match EXACTLY with the event name the user generated using the TCL 
script. 
event.user will send out an notification whenever this event is triggered. event.user.httpProcess will 
be sent out only when this specific event occurs. The entry must be entered in the notification tab exactly as 
it appears in the script.