diff options
author | Ton Voon <tonvoon@users.sourceforge.net> | 2005-12-15 17:06:55 +0000 |
---|---|---|
committer | Ton Voon <tonvoon@users.sourceforge.net> | 2005-12-15 17:06:55 +0000 |
commit | 71ce143ab1cac10b974084a21653b71bee68fe55 (patch) | |
tree | 2d7f757c122e6caef0297173ee55d8a2048dc1cf /plugins/check_mysql.c | |
parent | e03d87d8aef6701e7245b98800e67b64319bf7b2 (diff) | |
download | monitoring-plugins-71ce143ab1cac10b974084a21653b71bee68fe55.tar.gz |
Display errors with slave queries correctly. Added extra tests for slaves
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@1299 f882894a-f735-0410-b71e-b25c423dba1c
Diffstat (limited to 'plugins/check_mysql.c')
-rw-r--r-- | plugins/check_mysql.c | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/plugins/check_mysql.c b/plugins/check_mysql.c index 3194eced..45f86a9c 100644 --- a/plugins/check_mysql.c +++ b/plugins/check_mysql.c @@ -53,6 +53,7 @@ main (int argc, char **argv) /* should be status */ char *result = NULL; + char *error = NULL; char slaveresult[SLAVERESULTSIZE]; setlocale (LC_ALL, ""); @@ -99,21 +100,30 @@ main (int argc, char **argv) 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) { |