#!/usr/local/bin/perl -w
#
sqlconn.monitor
# Monitor sqlnet connection
#
# Arguments are: names of databases (as understood by listener)
#
# Available under the same terms as perl itself if distributed alone.
#
#
use Local::Env; # local environment variable setting
use DBI;
$dbuser = $ENV{ORACLE_USERID}; # from Local::Env or set it explicitly
foreach $dbname (@ARGV) {
unless (
eval {
$dbh = DBI->connect("dbi:Oracle:$dbname", $dbuser, '',
{ RaiseError => 1, AutoCommit => 1 })
}
)
{
push @failures, "$dbname connect";
push @longerr, "$dbname: $DBI::errstr";
$retval++;
next
}
unless ( $sth = $dbh->prepare("select sysdate from sys.dual") )
{
push @failures, "$dbname prepare";
push @longerr, "$dbname: $dbh->errstr";
$retval++;
next
}
unless ( $sth->execute() )
{
push @failures, "$dbname execute";
push @longerr, "$dbname: $dbh->errstr";
$retval++;
next
}
unless ( $sth->finish() )
{
push @failures, "$dbname finish";
push @longerr, "$dbname: $dbh->errstr";
$retval++;
next
}
unless ( $dbh->disconnect )
{
push @failures, "$dbname disconnect";
push @longerr, "$dbname: $dbh->errstr";
$retval++;
next
}
}
if (@failures) {
print join (", ", @failures), "\n";
print join ("\n", @longerr), "\n";
}
exit $retval;
#################
以上pl加上mon设置可以实现mon监控oracle脚本,当oracle停止的时候重起?不懂perl阿...:sad
mon.cf 与此perl程序有关东西
hostgroup ora_dbs 192.168.11.18
watch ora_dbs
service sqlconnect
interval 15m
monitor sqlconn.monitor
period wd {Mon-Fri} hr {9am-5pm}
alert mail.alert
duncanl@demon.net
alertevery 1h
period wd {Sat-Sun}
alert mail.alert
duncanl@demon.net
[
本帖最后由 luweinet 于 2007-7-19 00:23 编辑 ]