[Mon-commit] mon/mon.d msql-mysql.monitor,1.1.1.1,1.1.1.1.4.1
Brought to you by:
trockij
|
From: Jim T. <tr...@us...> - 2007-05-08 11:22:35
|
Update of /cvsroot/mon/mon/mon.d
In directory sc8-pr-cvs16:/tmp/cvs-serv24403/mon.d
Modified Files:
Tag: mon-1-2-branch
msql-mysql.monitor
Log Message:
added hard timeout patch to msql-mysql.monitor by Arkadiusz Miskiewicz
Index: msql-mysql.monitor
===================================================================
RCS file: /cvsroot/mon/mon/mon.d/msql-mysql.monitor,v
retrieving revision 1.1.1.1
retrieving revision 1.1.1.1.4.1
diff -C2 -d -r1.1.1.1 -r1.1.1.1.4.1
*** msql-mysql.monitor 9 Jun 2004 05:18:04 -0000 1.1.1.1
--- msql-mysql.monitor 8 May 2007 11:22:29 -0000 1.1.1.1.4.1
***************
*** 54,62 ****
use DBI;
use Getopt::Long;
my @details=();
my @failures=();
! GetOptions( \%options, "mode=s", "port=i", "username=s", "password=s", "database=s" );
# uncomment these two lines and provide suitable information if you don't
--- 54,70 ----
use DBI;
use Getopt::Long;
+ use POSIX ':signal_h';
my @details=();
my @failures=();
! my $mask = POSIX::SigSet->new( SIGALRM );
! my $action = POSIX::SigAction->new(
! sub { die "connect timeout" }, # the handler code ref
! $mask,
! # not using (perl 5.8.2 and later) 'safe' switch or sa_flags
! );
!
! GetOptions( \%options, "mode=s", "port=i", "username=s", "password=s", "database=s", "timeout=i" );
# uncomment these two lines and provide suitable information if you don't
***************
*** 65,68 ****
--- 73,78 ----
#$options{password} ||= "password";
+ $options{timeout} = 60 if ! $options{timeout};
+
if( $0 =~ m/\/msql\.monitor$/ || $options{mode} =~ m/msql/i ) {
$mode = "mSQL";
***************
*** 77,82 ****
for $host( @ARGV ) {
! my( $dbh ) = DBI->connect( "DBI:$mode:$options{database}:$host:$options{port}", $options{username}, $options{password}, { PrintError => 0 } );
! if( ! $dbh ) {
push( @failures, $host);
push( @details, "$host: Could not connect to $mode server on $options{port}: " . $DBI::errstr . "\n");
--- 87,105 ----
for $host( @ARGV ) {
! my $dbh = 0;
! my $oldaction = POSIX::SigAction->new();
! sigaction( 'ALRM', $action, $oldaction );
! eval {
! alarm $options{timeout};
! $dbh = DBI->connect( "DBI:$mode:$options{database}:$host:$options{port}", $options{username}, $options{password}, { PrintError => 0 } );
! alarm 0;
! };
! alarm 0;
! sigaction( 'ALRM', $oldaction );
! if ($@) {
! push( @failures, $host);
! push( @details, "$host: Could not connect to $mode server on $options{port}: $@\n");
! next;
! } elsif( ! $dbh ) {
push( @failures, $host);
push( @details, "$host: Could not connect to $mode server on $options{port}: " . $DBI::errstr . "\n");
|