]> git.etc.gen.nz Git - spong.git/commitdiff
MySQL monitoring by Miles Lott <milos@insync.net>
authorJan Willamowius <jan@willamowius.de>
Tue, 13 Sep 2005 13:57:58 +0000 (13:57 +0000)
committerJan Willamowius <jan@willamowius.de>
Tue, 13 Sep 2005 13:57:58 +0000 (13:57 +0000)
src/lib/Spong/Network/plugins/check_mysql [new file with mode: 0755]

diff --git a/src/lib/Spong/Network/plugins/check_mysql b/src/lib/Spong/Network/plugins/check_mysql
new file mode 100755 (executable)
index 0000000..1ef60a7
--- /dev/null
@@ -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 <milos@insync.net>
+
+$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 (<MYSQL>) {
+               $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;
+