summaryrefslogtreecommitdiffstats
path: root/web/attachments/97188-check_mysql.check_slave.patch
diff options
context:
space:
mode:
Diffstat (limited to 'web/attachments/97188-check_mysql.check_slave.patch')
-rw-r--r--web/attachments/97188-check_mysql.check_slave.patch138
1 files changed, 138 insertions, 0 deletions
diff --git a/web/attachments/97188-check_mysql.check_slave.patch b/web/attachments/97188-check_mysql.check_slave.patch
new file mode 100644
index 0000000..6607fdc
--- /dev/null
+++ b/web/attachments/97188-check_mysql.check_slave.patch
@@ -0,0 +1,138 @@
1diff -Naur nagios-plugins-1.4.0alpha1.orig/plugins/check_mysql.c nagios-plugins-1.4.0alpha1/plugins/check_mysql.c
2--- nagios-plugins-1.4.0alpha1.orig/plugins/check_mysql.c 2003-08-21 23:22:38.000000000 -0700
3+++ nagios-plugins-1.4.0alpha1/plugins/check_mysql.c 2004-07-30 11:15:56.000000000 -0700
4@@ -19,6 +19,8 @@
5 const char *copyright = "1999-2002";
6 const char *email = "nagiosplug-devel@lists.sourceforge.net";
7
8+#define SLAVERESULTSIZE 40
9+
10 #include "common.h"
11 #include "utils.h"
12 #include "netutils.h"
13@@ -30,6 +32,7 @@
14 char *db_pass = NULL;
15 char *db = NULL;
16 unsigned int db_port = MYSQL_PORT;
17+int check_slave = 0;
18
19 int process_arguments (int, char **);
20 int validate_arguments (void);
21@@ -41,7 +44,10 @@
22 {
23
24 MYSQL mysql;
25+ MYSQL_RES *res;
26+ MYSQL_ROW row;
27 char *result = NULL;
28+ char slaveresult[SLAVERESULTSIZE];
29
30 setlocale (LC_ALL, "");
31 bindtextdomain (PACKAGE, LOCALEDIR);
32@@ -82,11 +88,58 @@
33 die (STATE_CRITICAL, "%s\n", mysql_error (&mysql));
34 }
35
36+ if(check_slave) {
37+ /* check the slave status */
38+ if (mysql_query (&mysql, "show slave status") != 0) {
39+ mysql_close (&mysql);
40+ die (STATE_CRITICAL, "slave query error: %s\n", mysql_error (&mysql));
41+ }
42+
43+ /* store the result */
44+ if ( (res = mysql_store_result (&mysql)) == NULL) {
45+ mysql_close (&mysql);
46+ die (STATE_CRITICAL, "slave store_result error: %s\n", mysql_error (&mysql));
47+ }
48+
49+ /* fetch the first row */
50+ if ( (row = mysql_fetch_row (res)) == NULL) {
51+ mysql_free_result (res);
52+ mysql_close (&mysql);
53+ die (STATE_CRITICAL, "slave fetch row error: %s\n", mysql_error (&mysql));
54+ }
55+
56+ if (mysql_field_count (&mysql) == 12) {
57+ /* mysql 3.23.x */
58+ snprintf (slaveresult, SLAVERESULTSIZE, "Slave running: %s", row[6]);
59+ if (strcmp (row[6], "Yes") != 0) {
60+ mysql_free_result (res);
61+ mysql_close (&mysql);
62+ die (STATE_CRITICAL, "%s\n", slaveresult);
63+ }
64+
65+ } else {
66+ /* mysql 4.x.x */
67+ snprintf (slaveresult, SLAVERESULTSIZE, "Slave IO: %s Slave SQL: %s", row[9], row[10]);
68+ if (strcmp (row[9], "Yes") != 0 || strcmp (row[10], "Yes") != 0) {
69+ mysql_free_result (res);
70+ mysql_close (&mysql);
71+ die (STATE_CRITICAL, "%s\n", slaveresult);
72+ }
73+ }
74+
75+ /* free the result */
76+ mysql_free_result (res);
77+ }
78+
79 /* close the connection */
80 mysql_close (&mysql);
81
82 /* print out the result of stats */
83- printf ("%s\n", result);
84+ if (check_slave) {
85+ printf ("%s %s\n", result, slaveresult);
86+ } else {
87+ printf ("%s\n", result);
88+ }
89
90 return STATE_OK;
91 }
92@@ -108,6 +161,7 @@
93 {"username", required_argument, 0, 'u'},
94 {"password", required_argument, 0, 'p'},
95 {"port", required_argument, 0, 'P'},
96+ {"check-slave", no_argument, 0, 'S'},
97 {"verbose", no_argument, 0, 'v'},
98 {"version", no_argument, 0, 'V'},
99 {"help", no_argument, 0, 'h'},
100@@ -118,7 +172,7 @@
101 return ERROR;
102
103 while (1) {
104- c = getopt_long (argc, argv, "hVP:p:u:d:H:", longopts, &option);
105+ c = getopt_long (argc, argv, "hVSP:p:u:d:H:", longopts, &option);
106
107 if (c == -1 || c == EOF)
108 break;
109@@ -144,6 +198,9 @@
110 case 'P': /* critical time threshold */
111 db_port = atoi (optarg);
112 break;
113+ case 'S':
114+ check_slave = 1; /* check-slave */
115+ break;
116 case 'V': /* version */
117 print_revision (progname, revision);
118 exit (STATE_OK);
119@@ -234,7 +291,9 @@
120 -p, --password=STRING\n\
121 Use the indicated password to authenticate the connection\n\
122 ==> IMPORTANT: THIS FORM OF AUTHENTICATION IS NOT SECURE!!! <==\n\
123- Your clear-text password will be visible as a process table entry\n"));
124+ Your clear-text password will be visible as a process table entry\n\
125+ -S, --check-slave\n\
126+ Check if the slave thread is running properly.\n"));
127
128 printf (_("\n\
129 There are no required arguments. By default, the local database with\n\
130@@ -250,7 +309,7 @@
131 print_usage (void)
132 {
133 printf (_("\
134-Usage: %s [-d database] [-H host] [-P port] [-u user] [-p password]\n"),
135+Usage: %s [-d database] [-H host] [-P port] [-u user] [-p password] [-S]\n"),
136 progname);
137 printf (_(UT_HLP_VRS), progname, progname);
138 }