[Nagiosplug-checkins] nagiosplug/plugins check_mysql.c,1.27,1.28
Ton Voon
tonvoon at users.sourceforge.net
Thu Dec 15 09:08:02 CET 2005
Update of /cvsroot/nagiosplug/nagiosplug/plugins
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23109/plugins
Modified Files:
check_mysql.c
Log Message:
Display errors with slave queries correctly. Added extra tests for slaves
Index: check_mysql.c
===================================================================
RCS file: /cvsroot/nagiosplug/nagiosplug/plugins/check_mysql.c,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -d -r1.27 -r1.28
--- check_mysql.c 13 Oct 2005 09:55:31 -0000 1.27
+++ check_mysql.c 15 Dec 2005 17:06:54 -0000 1.28
@@ -53,6 +53,7 @@
/* should be status */
char *result = NULL;
+ char *error = NULL;
char slaveresult[SLAVERESULTSIZE];
setlocale (LC_ALL, "");
@@ -99,21 +100,30 @@
if(check_slave) {
/* check the slave status */
if (mysql_query (&mysql, "show slave status") != 0) {
+ error = strdup(mysql_error(&mysql));
mysql_close (&mysql);
- die (STATE_CRITICAL, _("slave query error: %s\n"), mysql_error (&mysql));
+ die (STATE_CRITICAL, _("slave query error: %s\n"), error);
}
/* store the result */
if ( (res = mysql_store_result (&mysql)) == NULL) {
+ error = strdup(mysql_error(&mysql));
mysql_close (&mysql);
- die (STATE_CRITICAL, _("slave store_result error: %s\n"), mysql_error (&mysql));
+ die (STATE_CRITICAL, _("slave store_result error: %s\n"), error);
+ }
+
+ /* Check there is some data */
+ if (mysql_num_rows(res) == 0) {
+ mysql_close(&mysql);
+ die (STATE_WARNING, "%s\n", _("No slaves defined"));
}
/* fetch the first row */
if ( (row = mysql_fetch_row (res)) == NULL) {
+ error = strdup(mysql_error(&mysql));
mysql_free_result (res);
mysql_close (&mysql);
- die (STATE_CRITICAL, _("slave fetch row error: %s\n"), mysql_error (&mysql));
+ die (STATE_CRITICAL, _("slave fetch row error: %s\n"), error);
}
if (mysql_field_count (&mysql) == 12) {
More information about the Commits
mailing list