summaryrefslogtreecommitdiffstats
path: root/plugins/check_mysql.c
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/check_mysql.c')
-rw-r--r--plugins/check_mysql.c16
1 files changed, 13 insertions, 3 deletions
diff --git a/plugins/check_mysql.c b/plugins/check_mysql.c
index 3194ece..45f86a9 100644
--- a/plugins/check_mysql.c
+++ b/plugins/check_mysql.c
@@ -53,6 +53,7 @@ main (int argc, char **argv)
53 /* should be status */ 53 /* should be status */
54 54
55 char *result = NULL; 55 char *result = NULL;
56 char *error = NULL;
56 char slaveresult[SLAVERESULTSIZE]; 57 char slaveresult[SLAVERESULTSIZE];
57 58
58 setlocale (LC_ALL, ""); 59 setlocale (LC_ALL, "");
@@ -99,21 +100,30 @@ main (int argc, char **argv)
99 if(check_slave) { 100 if(check_slave) {
100 /* check the slave status */ 101 /* check the slave status */
101 if (mysql_query (&mysql, "show slave status") != 0) { 102 if (mysql_query (&mysql, "show slave status") != 0) {
103 error = strdup(mysql_error(&mysql));
102 mysql_close (&mysql); 104 mysql_close (&mysql);
103 die (STATE_CRITICAL, _("slave query error: %s\n"), mysql_error (&mysql)); 105 die (STATE_CRITICAL, _("slave query error: %s\n"), error);
104 } 106 }
105 107
106 /* store the result */ 108 /* store the result */
107 if ( (res = mysql_store_result (&mysql)) == NULL) { 109 if ( (res = mysql_store_result (&mysql)) == NULL) {
110 error = strdup(mysql_error(&mysql));
108 mysql_close (&mysql); 111 mysql_close (&mysql);
109 die (STATE_CRITICAL, _("slave store_result error: %s\n"), mysql_error (&mysql)); 112 die (STATE_CRITICAL, _("slave store_result error: %s\n"), error);
113 }
114
115 /* Check there is some data */
116 if (mysql_num_rows(res) == 0) {
117 mysql_close(&mysql);
118 die (STATE_WARNING, "%s\n", _("No slaves defined"));
110 } 119 }
111 120
112 /* fetch the first row */ 121 /* fetch the first row */
113 if ( (row = mysql_fetch_row (res)) == NULL) { 122 if ( (row = mysql_fetch_row (res)) == NULL) {
123 error = strdup(mysql_error(&mysql));
114 mysql_free_result (res); 124 mysql_free_result (res);
115 mysql_close (&mysql); 125 mysql_close (&mysql);
116 die (STATE_CRITICAL, _("slave fetch row error: %s\n"), mysql_error (&mysql)); 126 die (STATE_CRITICAL, _("slave fetch row error: %s\n"), error);
117 } 127 }
118 128
119 if (mysql_field_count (&mysql) == 12) { 129 if (mysql_field_count (&mysql) == 12) {