Вернуться

Листинг 2.

# NAME:
#
#  CheckOMSAgent.tcl : Script to test if Agent on remote host is running
#
# ARGUMENTS:
#   for remote host there Agent to be checked is running
#   seconds to sleep between checks
#   mail address
#
#  ex.: host.domain.com 30 mymail@address.com
#
# Prerequisits:
#  It is suppposed to be run under UNIX (mailx)
#
# Changes Log:
#  06-01-99 A Balbekov Original Creation
#

set argc [llength $argv]
if {$argc == 1} {set argv [lindex $argv 0]}
if {$argc != 3} {error "Usage: testAgent.tcl   "}

set dns_name [lindex $argv 0]
set sleep_time [lindex $argv 1]
set smtp_addr [lindex $argv 2]

set down 1
set up 0
set prev_status $up

set my_address [lindex [orainfo] 2]
orajobstat $my_address "Job started: [oratime]"

#
# Main idefinite loop - break is done by OEM console's remove job command
#
while { 1 == 1 } {
	catch {orainfo (ADDRESS=(PROTOCOL=tcp)(HOST=$dns_name)(PORT=1748))} out
	if { [lsearch -regexp $out Failed] > 0} {
		if { $prev_status == $up } {
			set mail_success [catch {exec echo "$dns_name: Agent is down: Timestamp [oratime]" | mailx -s "$dns_name: Agent is down" $smtp_addr} out]
				if { $mail_success == 0 } {
					set mail_success "Successfull"
				} else {
					set mail_success "UnSuccessfull"
				}
			orajobstat $my_address "$dns_name: Agent is down: Timestamp [oratime] Notification: $mail_success"
			set prev_status $down
		} else {
		 	orajobstat $my_address $out
		}
	} else {
		if { $prev_status == $down } {
			set mail_success [catch {exec echo "$dns_name: Agent is up: Timestamp [oratime]" | mailx -s "$dns_name: Agent is up" $smtp_addr} out]
				if { $mail_success == 0 } {
					set mail_success "Successfull"
				} else {
					set mail_success "UnSuccessfull"
				}
			orajobstat $my_address "$dns_name: Agent is up: Timestamp [oratime] Notification: $mail_success"
			set prev_status $up
		}
	}
	orasleep $sleep_time
}



Вернуться