From: Jan Willamowius Date: Tue, 27 Sep 2005 16:16:53 +0000 (+0000) Subject: updated MySQL plugin by Andrew Ruthven X-Git-Tag: spong-2_8_0-beta1~2 X-Git-Url: http://git.etc.gen.nz/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=653df378e2d13e632e825f7a1b6b0f0276842e05;p=spong.git updated MySQL plugin by Andrew Ruthven --- diff --git a/src/lib/Spong/Network/plugins/check_mysql b/src/lib/Spong/Network/plugins/check_mysql index 1ef60a7..cb59dc1 100755 --- a/src/lib/Spong/Network/plugins/check_mysql +++ b/src/lib/Spong/Network/plugins/check_mysql @@ -1,44 +1,119 @@ +=head1 NAME + +B - spong-network module to check MySQL servers + +=head1 DESCRIPTION + +This is a plugin module for the Spong L program. The +B module checks the status of MySQL servers by querying +them using the mysqladmin command. + +It not only alerts you to a problem if it can't connect, but it also +returns some potentially interesting numbers. These numbers can be +graphed using L. + +=cut + # 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( $dbuser ) = $HOSTS{$host}{'mysql'}{'dbuser'} + || $HOSTS_DEFAULTS{'mysql'}{'dbuser'}; + my( $dbpass ) = $HOSTS{$host}{'mysql'}{'dbpass'} + || $HOSTS_DEFAULTS{'mysql'}{'dbpass'}; + my( $color, $summary, $message ) = ( "green", "MySQL Ok", "" ); - 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 ); + open (MYSQL,"$MYSQLADMIN $host 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; +__END__ + +=head2 Output Returned + +=over 4 + +=item Status + +If there is nothing degraded or failed on the MySQL server then 'green' +status is returned. Otherwise 'yellow' is returned if we don't have access +or 'red' is returned if the connection fails. + +This could be extended in the future to check and see if a minimum number +of tables are present. + +=item Summary Field + +If there are no problems, 'MySQL Ok' is returned. Otherwise the summary field +will have a short description of what the problem or anamoly is. + +=item Detail Message Field + +If the MySQL process is contactable, then the detail message will have +some interesting numbers from the MySQL server. + +=back + +=head2 Configuration + +It is necessary to add the following to L: + +$MYSQLADMIN = "/usr/bin/mysqladmin -h"; + +Where C is replaced with the path that leads to C. + +It is possible to set configuration details both for as a a default and +then for specific hosts. An example is given in L. + +=back + +=head1 EXAMPLES + + %HOSTS_DEFAULTS = ( + 'mysql' => { + 'dbuser' => 'spong', + 'dbpass' => 'default-password' + } + ) + + %HOSTS = ( + 'mysql.server.com' => { + 'services' => 'mysql', + 'mysql' => { + 'dbpass' => 'host-specific-password' + } + } + +=head1 SEE ALSO + +L, L, +L, +L + +=head1 RESTRICTIONS + +B uses mysqladmin, hence it is necessary to have some basic +client utilities installed from MySQL. + +=head1 AUTHOR + +Miles Lott + +Support for %HOSTS and %HOSTS_DEFAULTS and POD documentation added by +Andrew Ruthven - 2002/06/13. +