summaryrefslogtreecommitdiffstats
path: root/plugins/check_mysql.c
diff options
context:
space:
mode:
authorMatthew Kent <mattkent@users.sourceforge.net>2004-11-21 05:24:57 (GMT)
committerMatthew Kent <mattkent@users.sourceforge.net>2004-11-21 05:24:57 (GMT)
commit12d424489ebbeb8b79a97efa5d97174776ec2511 (patch)
tree3d37e4984d44bf49ed470a3f7e5432464f52d44a /plugins/check_mysql.c
parent08b92b8b8f1529b32c661ca583cc99cd347cbe6e (diff)
downloadmonitoring-plugins-12d424489ebbeb8b79a97efa5d97174776ec2511.tar.gz
Patch from Nathan Shafer to add replication slave check (1006777)
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@920 f882894a-f735-0410-b71e-b25c423dba1c
Diffstat (limited to 'plugins/check_mysql.c')
-rw-r--r--plugins/check_mysql.c67
1 files changed, 63 insertions, 4 deletions
diff --git a/plugins/check_mysql.c b/plugins/check_mysql.c
index d62bfc8..2c90e6d 100644
--- a/plugins/check_mysql.c
+++ b/plugins/check_mysql.c
@@ -19,6 +19,8 @@ const char *revision = "$Revision$";
19const char *copyright = "1999-2002"; 19const char *copyright = "1999-2002";
20const char *email = "nagiosplug-devel@lists.sourceforge.net"; 20const char *email = "nagiosplug-devel@lists.sourceforge.net";
21 21
22#define SLAVERESULTSIZE 40
23
22#include "common.h" 24#include "common.h"
23#include "utils.h" 25#include "utils.h"
24#include "netutils.h" 26#include "netutils.h"
@@ -30,6 +32,7 @@ char *db_host = NULL;
30char *db_pass = NULL; 32char *db_pass = NULL;
31char *db = NULL; 33char *db = NULL;
32unsigned int db_port = MYSQL_PORT; 34unsigned int db_port = MYSQL_PORT;
35int check_slave = 0;
33 36
34int process_arguments (int, char **); 37int process_arguments (int, char **);
35int validate_arguments (void); 38int validate_arguments (void);
@@ -41,7 +44,10 @@ main (int argc, char **argv)
41{ 44{
42 45
43 MYSQL mysql; 46 MYSQL mysql;
47 MYSQL_RES *res;
48 MYSQL_ROW row;
44 char *result = NULL; 49 char *result = NULL;
50 char slaveresult[SLAVERESULTSIZE];
45 51
46 setlocale (LC_ALL, ""); 52 setlocale (LC_ALL, "");
47 bindtextdomain (PACKAGE, LOCALEDIR); 53 bindtextdomain (PACKAGE, LOCALEDIR);
@@ -82,11 +88,58 @@ main (int argc, char **argv)
82 die (STATE_CRITICAL, "%s\n", mysql_error (&mysql)); 88 die (STATE_CRITICAL, "%s\n", mysql_error (&mysql));
83 } 89 }
84 90
91 if(check_slave) {
92 /* check the slave status */
93 if (mysql_query (&mysql, "show slave status") != 0) {
94 mysql_close (&mysql);
95 die (STATE_CRITICAL, "slave query error: %s\n", mysql_error (&mysql));
96 }
97
98 /* store the result */
99 if ( (res = mysql_store_result (&mysql)) == NULL) {
100 mysql_close (&mysql);
101 die (STATE_CRITICAL, "slave store_result error: %s\n", mysql_error (&mysql));
102 }
103
104 /* fetch the first row */
105 if ( (row = mysql_fetch_row (res)) == NULL) {
106 mysql_free_result (res);
107 mysql_close (&mysql);
108 die (STATE_CRITICAL, "slave fetch row error: %s\n", mysql_error (&mysql));
109 }
110
111 if (mysql_field_count (&mysql) == 12) {
112 /* mysql 3.23.x */
113 snprintf (slaveresult, SLAVERESULTSIZE, "Slave running: %s", row[6]);
114 if (strcmp (row[6], "Yes") != 0) {
115 mysql_free_result (res);
116 mysql_close (&mysql);
117 die (STATE_CRITICAL, "%s\n", slaveresult);
118 }
119
120 } else {
121 /* mysql 4.x.x */
122 snprintf (slaveresult, SLAVERESULTSIZE, "Slave IO: %s Slave SQL: %s", row[9], row[10]);
123 if (strcmp (row[9], "Yes") != 0 || strcmp (row[10], "Yes") != 0) {
124 mysql_free_result (res);
125 mysql_close (&mysql);
126 die (STATE_CRITICAL, "%s\n", slaveresult);
127 }
128 }
129
130 /* free the result */
131 mysql_free_result (res);
132 }
133
85 /* close the connection */ 134 /* close the connection */
86 mysql_close (&mysql); 135 mysql_close (&mysql);
87 136
88 /* print out the result of stats */ 137 /* print out the result of stats */
89 printf ("%s\n", result); 138 if (check_slave) {
139 printf ("%s %s\n", result, slaveresult);
140 } else {
141 printf ("%s\n", result);
142 }
90 143
91 return STATE_OK; 144 return STATE_OK;
92} 145}
@@ -108,6 +161,7 @@ process_arguments (int argc, char **argv)
108 {"username", required_argument, 0, 'u'}, 161 {"username", required_argument, 0, 'u'},
109 {"password", required_argument, 0, 'p'}, 162 {"password", required_argument, 0, 'p'},
110 {"port", required_argument, 0, 'P'}, 163 {"port", required_argument, 0, 'P'},
164 {"check-slave", no_argument, 0, 'S'},
111 {"verbose", no_argument, 0, 'v'}, 165 {"verbose", no_argument, 0, 'v'},
112 {"version", no_argument, 0, 'V'}, 166 {"version", no_argument, 0, 'V'},
113 {"help", no_argument, 0, 'h'}, 167 {"help", no_argument, 0, 'h'},
@@ -118,7 +172,7 @@ process_arguments (int argc, char **argv)
118 return ERROR; 172 return ERROR;
119 173
120 while (1) { 174 while (1) {
121 c = getopt_long (argc, argv, "hVP:p:u:d:H:", longopts, &option); 175 c = getopt_long (argc, argv, "hVSP:p:u:d:H:", longopts, &option);
122 176
123 if (c == -1 || c == EOF) 177 if (c == -1 || c == EOF)
124 break; 178 break;
@@ -144,6 +198,9 @@ process_arguments (int argc, char **argv)
144 case 'P': /* critical time threshold */ 198 case 'P': /* critical time threshold */
145 db_port = atoi (optarg); 199 db_port = atoi (optarg);
146 break; 200 break;
201 case 'S':
202 check_slave = 1; /* check-slave */
203 break;
147 case 'V': /* version */ 204 case 'V': /* version */
148 print_revision (progname, revision); 205 print_revision (progname, revision);
149 exit (STATE_OK); 206 exit (STATE_OK);
@@ -234,7 +291,9 @@ print_help (void)
234 -p, --password=STRING\n\ 291 -p, --password=STRING\n\
235 Use the indicated password to authenticate the connection\n\ 292 Use the indicated password to authenticate the connection\n\
236 ==> IMPORTANT: THIS FORM OF AUTHENTICATION IS NOT SECURE!!! <==\n\ 293 ==> IMPORTANT: THIS FORM OF AUTHENTICATION IS NOT SECURE!!! <==\n\
237 Your clear-text password will be visible as a process table entry\n")); 294 Your clear-text password will be visible as a process table entry\n\
295 -S, --check-slave\n\
296 Check if the slave thread is running properly.\n"));
238 297
239 printf (_("\n\ 298 printf (_("\n\
240There are no required arguments. By default, the local database with\n\ 299There are no required arguments. By default, the local database with\n\
@@ -250,7 +309,7 @@ void
250print_usage (void) 309print_usage (void)
251{ 310{
252 printf (_("\ 311 printf (_("\
253Usage: %s [-d database] [-H host] [-P port] [-u user] [-p password]\n"), 312Usage: %s [-d database] [-H host] [-P port] [-u user] [-p password] [-S]\n"),
254 progname); 313 progname);
255 printf (_(UT_HLP_VRS), progname, progname); 314 printf (_(UT_HLP_VRS), progname, progname);
256} 315}