[Nagiosplug-checkins] CVS: nagiosplug/plugins check_mysql.c,1.12,1.13
Matthew Kent
mattkent at users.sourceforge.net
Sat Nov 20 21:30:43 CET 2004
Update of /cvsroot/nagiosplug/nagiosplug/plugins
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20117
Modified Files:
check_mysql.c
Log Message:
Patch from Nathan Shafer to add replication slave check (1006777)
Index: check_mysql.c
===================================================================
RCS file: /cvsroot/nagiosplug/nagiosplug/plugins/check_mysql.c,v
retrieving revision 1.12
retrieving revision 1.13
diff -C2 -r1.12 -r1.13
*** check_mysql.c 22 Aug 2003 06:22:38 -0000 1.12
--- check_mysql.c 21 Nov 2004 05:24:57 -0000 1.13
***************
*** 20,23 ****
--- 20,25 ----
const char *email = "nagiosplug-devel at lists.sourceforge.net";
+ #define SLAVERESULTSIZE 40
+
#include "common.h"
#include "utils.h"
***************
*** 31,34 ****
--- 33,37 ----
char *db = NULL;
unsigned int db_port = MYSQL_PORT;
+ int check_slave = 0;
int process_arguments (int, char **);
***************
*** 42,46 ****
--- 45,52 ----
MYSQL mysql;
+ MYSQL_RES *res;
+ MYSQL_ROW row;
char *result = NULL;
+ char slaveresult[SLAVERESULTSIZE];
setlocale (LC_ALL, "");
***************
*** 83,91 ****
}
/* close the connection */
mysql_close (&mysql);
/* print out the result of stats */
! printf ("%s\n", result);
return STATE_OK;
--- 89,144 ----
}
+ if(check_slave) {
+ /* check the slave status */
+ if (mysql_query (&mysql, "show slave status") != 0) {
+ mysql_close (&mysql);
+ die (STATE_CRITICAL, "slave query error: %s\n", mysql_error (&mysql));
+ }
+
+ /* store the result */
+ if ( (res = mysql_store_result (&mysql)) == NULL) {
+ mysql_close (&mysql);
+ die (STATE_CRITICAL, "slave store_result error: %s\n", mysql_error (&mysql));
+ }
+
+ /* fetch the first row */
+ if ( (row = mysql_fetch_row (res)) == NULL) {
+ mysql_free_result (res);
+ mysql_close (&mysql);
+ die (STATE_CRITICAL, "slave fetch row error: %s\n", mysql_error (&mysql));
+ }
+
+ if (mysql_field_count (&mysql) == 12) {
+ /* mysql 3.23.x */
+ snprintf (slaveresult, SLAVERESULTSIZE, "Slave running: %s", row[6]);
+ if (strcmp (row[6], "Yes") != 0) {
+ mysql_free_result (res);
+ mysql_close (&mysql);
+ die (STATE_CRITICAL, "%s\n", slaveresult);
+ }
+
+ } else {
+ /* mysql 4.x.x */
+ snprintf (slaveresult, SLAVERESULTSIZE, "Slave IO: %s Slave SQL: %s", row[9], row[10]);
+ if (strcmp (row[9], "Yes") != 0 || strcmp (row[10], "Yes") != 0) {
+ mysql_free_result (res);
+ mysql_close (&mysql);
+ die (STATE_CRITICAL, "%s\n", slaveresult);
+ }
+ }
+
+ /* free the result */
+ mysql_free_result (res);
+ }
+
/* close the connection */
mysql_close (&mysql);
/* print out the result of stats */
! if (check_slave) {
! printf ("%s %s\n", result, slaveresult);
! } else {
! printf ("%s\n", result);
! }
return STATE_OK;
***************
*** 109,112 ****
--- 162,166 ----
{"password", required_argument, 0, 'p'},
{"port", required_argument, 0, 'P'},
+ {"check-slave", no_argument, 0, 'S'},
{"verbose", no_argument, 0, 'v'},
{"version", no_argument, 0, 'V'},
***************
*** 119,123 ****
while (1) {
! c = getopt_long (argc, argv, "hVP:p:u:d:H:", longopts, &option);
if (c == -1 || c == EOF)
--- 173,177 ----
while (1) {
! c = getopt_long (argc, argv, "hVSP:p:u:d:H:", longopts, &option);
if (c == -1 || c == EOF)
***************
*** 145,148 ****
--- 199,205 ----
db_port = atoi (optarg);
break;
+ case 'S':
+ check_slave = 1; /* check-slave */
+ break;
case 'V': /* version */
print_revision (progname, revision);
***************
*** 235,239 ****
Use the indicated password to authenticate the connection\n\
==> IMPORTANT: THIS FORM OF AUTHENTICATION IS NOT SECURE!!! <==\n\
! Your clear-text password will be visible as a process table entry\n"));
printf (_("\n\
--- 292,298 ----
Use the indicated password to authenticate the connection\n\
==> IMPORTANT: THIS FORM OF AUTHENTICATION IS NOT SECURE!!! <==\n\
! Your clear-text password will be visible as a process table entry\n\
! -S, --check-slave\n\
! Check if the slave thread is running properly.\n"));
printf (_("\n\
***************
*** 251,255 ****
{
printf (_("\
! Usage: %s [-d database] [-H host] [-P port] [-u user] [-p password]\n"),
progname);
printf (_(UT_HLP_VRS), progname, progname);
--- 310,314 ----
{
printf (_("\
! Usage: %s [-d database] [-H host] [-P port] [-u user] [-p password] [-S]\n"),
progname);
printf (_(UT_HLP_VRS), progname, progname);
More information about the Commits
mailing list