From 7de186f46f790532dd30cb660d0e7701ab6565a0 Mon Sep 17 00:00:00 2001 From: Jan Willamowius Date: Tue, 13 Sep 2005 13:57:58 +0000 Subject: [PATCH] MySQL monitoring by Miles Lott --- src/lib/Spong/Network/plugins/check_mysql | 44 +++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100755 src/lib/Spong/Network/plugins/check_mysql diff --git a/src/lib/Spong/Network/plugins/check_mysql b/src/lib/Spong/Network/plugins/check_mysql new file mode 100755 index 0000000..1ef60a7 --- /dev/null +++ b/src/lib/Spong/Network/plugins/check_mysql @@ -0,0 +1,44 @@ +# Register the routine with the plugin registry +$PLUGINS{'mysql'} = \&check_mysql; + +# This will check the status of MySQL on a system. It uses +# the mysqladmin command to query the server. +# +# Place this file in $SPONGHOME/lib/Spong/Network/plugins and add +# +# $MYSQLADMIN = "/usr/bin/mysqladmin -h"; +# $DBUSER = "user"; +# $DBPASS = "password"; +# +# to spong.conf. +# +# Miles Lott + +$DBPORT = ""; + +sub check_mysql { + + my( $host ) = @_; + my( $color, $summary, $message ) = ( "green", "Server OK", "" ); + + if (defined($HOSTS{$host}{'mysql_port'}) ) { + $DBPORT = "-P " . $HOSTS{$host}{'mysql_port'}; + } + + open (MYSQL,"$MYSQLADMIN $host $DBPORT status -u$DBUSER -p$DBPASS 2>&1 |") || warn "Could not exec $MYSQLADMIN for status info."; + while () { + $message .= $_; + if (/Can\'t connect/) { + $color = "red"; $summary = "Server is unreachable."; + } + if (/Access denied/) { + $color = "yellow"; $summary = "Server is up, but access is denied."; + } + } + + &debug( "mysql - $host - $color, $summary" ); + return( $color, $summary, $message ); +} + +1; + -- 2.30.2