summaryrefslogtreecommitdiffstats
path: root/web/attachments/416883-check_mysql.patch
blob: 9643a980968b5f1856faba57100b5122c915217d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
--- a/nagios-plugins-1.4.15/plugins/check_mysql.c       2010-07-27 22:47:16.000000000 +0200
+++ b/nagios-plugins-1.4.15/plugins/check_mysql.c       2011-06-30 11:12:09.000000000 +0200
@@ -34,7 +34,7 @@
 const char *copyright = "1999-2007";
 const char *email = "nagiosplug-devel@lists.sourceforge.net";
 
-#define SLAVERESULTSIZE 70
+#define SLAVERESULTSIZE 120
 
 #include "common.h"
 #include "utils.h"
@@ -158,7 +158,7 @@
 
                } else {
                        /* mysql 4.x.x */
-                       int slave_io_field = -1 , slave_sql_field = -1, seconds_behind_field = -1, i, num_fields;
+                       int slave_io_field = -1 , slave_sql_field = -1, seconds_behind_field = -1, until_cond_field = -1, last_errno_field = -1, i, num_fields;
                        MYSQL_FIELD* fields;
 
                        num_fields = mysql_num_fields(res);
@@ -176,16 +176,25 @@
                                        seconds_behind_field = i;
                                        continue;
                                }
+                               if (strcmp(fields[i].name, "Until_Condition") == 0) {
+                                       until_cond_field = i;
+                                       continue;
+                               }
+                               if (strcmp(fields[i].name, "Last_Errno") == 0) {
+                                       last_errno_field = i;
+                                       continue;
+                               }
                        }
 
-                       if ((slave_io_field < 0) || (slave_sql_field < 0) || (num_fields == 0)) {
+                       if ((slave_io_field < 0) || (slave_sql_field < 0) || (last_errno_field < 0) || (num_fields == 0)) {
                                mysql_free_result (res);
                                mysql_close (&mysql);
                                die (STATE_CRITICAL, "Slave status unavailable\n");
                        }
 
-                       snprintf (slaveresult, SLAVERESULTSIZE, "Slave IO: %s Slave SQL: %s Seconds Behind Master: %s", row[slave_io_field], row[slave_sql_field], seconds_behind_field!=-1?row[seconds_behind_field]:"Unknown");
-                       if (strcmp (row[slave_io_field], "Yes") != 0 || strcmp (row[slave_sql_field], "Yes") != 0) {
+                       snprintf (slaveresult, SLAVERESULTSIZE, "Slave IO: %s Slave SQL: %s Seconds Behind Master: %s Until Condition: %s Last Errno: %s", row[slave_io_field], row[slave_sql_field], seconds_behind_field!=-1?row[seconds_behind_field]:"Unknown", row[until_cond_field], last_errno_field!=-1?row[last_errno_field]:"No Error");
+
+                       if ((strcmp(row[until_cond_field], "None") == 0 && (strcmp (row[slave_io_field], "Yes") != 0 || strcmp (row[slave_sql_field], "Yes") != 0) ) || (strcmp(row[last_errno_field], "0") != 0)) {
                                mysql_free_result (res);
                                mysql_close (&mysql);
                                die (STATE_CRITICAL, "%s\n", slaveresult);
@@ -197,9 +206,19 @@
                                } else {
                                        printf ("seconds_behind_field(index %d)=%s\n", seconds_behind_field, row[seconds_behind_field]);
                                }
+                               if (until_cond_field == -1) {
+                                        printf("until_cond_field not found\n");
+                                } else {
+                                        printf ("until_cond_field(index %d)=%s\n", until_cond_field, row[until_cond_field]);
+                                }
+                                if (last_errno_field == -1) {
+                                        printf("last_errno_field not found\n");
+                                } else {
+                                        printf("last_errno_field(index %d)=%s\n", last_errno_field, row[last_errno_field]);
+                                }
                        }
 
-                       if ((seconds_behind_field != -1) && (strcmp (row[seconds_behind_field], "NULL") != 0)) {
+                       if ((seconds_behind_field != -1) && (row[seconds_behind_field] != NULL && (strcmp (row[seconds_behind_field], "NULL") != 0)) && (strcmp(row[until_cond_field], "None") == 0)) {
                                double value = atof(row[seconds_behind_field]);
                                int status;