diff options
Diffstat (limited to 'web/attachments/119444-nagios-plugins-1.4_mysql41-slave-fix.patch')
| -rw-r--r-- | web/attachments/119444-nagios-plugins-1.4_mysql41-slave-fix.patch | 127 |
1 files changed, 127 insertions, 0 deletions
diff --git a/web/attachments/119444-nagios-plugins-1.4_mysql41-slave-fix.patch b/web/attachments/119444-nagios-plugins-1.4_mysql41-slave-fix.patch new file mode 100644 index 0000000..fb4f11e --- /dev/null +++ b/web/attachments/119444-nagios-plugins-1.4_mysql41-slave-fix.patch | |||
| @@ -0,0 +1,127 @@ | |||
| 1 | diff -rNu nagios-plugins-1.4/plugins/check_mysql.c nagios-plugins-1.4_mysql41-slave-fix/plugins/check_mysql.c | ||
| 2 | --- nagios-plugins-1.4/plugins/check_mysql.c Sun Dec 26 00:17:44 2004 | ||
| 3 | +++ nagios-plugins-1.4_mysql41-slave-fix/plugins/check_mysql.c Thu Feb 10 13:27:13 2005 | ||
| 4 | @@ -12,6 +12,11 @@ | ||
| 5 | * Description: | ||
| 6 | * | ||
| 7 | * This plugin is for testing a mysql server. | ||
| 8 | +* | ||
| 9 | +****************************************************************************** | ||
| 10 | +* Modified by wouter@widexs.nl: | ||
| 11 | +* - Changed static column numbers in the slave-check, to dynamic, | ||
| 12 | +* so newer MySQL versions (eg. 4.1.x) are supported as well (09-02-2005) | ||
| 13 | ******************************************************************************/ | ||
| 14 | |||
| 15 | const char *progname = "check_mysql"; | ||
| 16 | @@ -49,12 +54,19 @@ | ||
| 17 | MYSQL mysql; | ||
| 18 | MYSQL_RES *res; | ||
| 19 | MYSQL_ROW row; | ||
| 20 | + MYSQL_FIELD *field; | ||
| 21 | |||
| 22 | /* should be status */ | ||
| 23 | |||
| 24 | char *result = NULL; | ||
| 25 | char slaveresult[SLAVERESULTSIZE]; | ||
| 26 | |||
| 27 | + int local_mysql_server_version = 0; | ||
| 28 | + int local_mysql_client_version = 0; | ||
| 29 | + int col_slave_err = 0; | ||
| 30 | + int col_slave_run = 0; | ||
| 31 | + int col_slave_sql_run = 0; | ||
| 32 | + | ||
| 33 | setlocale (LC_ALL, ""); | ||
| 34 | bindtextdomain (PACKAGE, LOCALEDIR); | ||
| 35 | textdomain (PACKAGE); | ||
| 36 | @@ -107,6 +119,21 @@ | ||
| 37 | die (STATE_CRITICAL, _("slave store_result error: %s\n"), mysql_error (&mysql)); | ||
| 38 | } | ||
| 39 | |||
| 40 | + /* Get client & server version */ | ||
| 41 | + local_mysql_client_version = mysql_get_client_version(); | ||
| 42 | + local_mysql_server_version = (local_mysql_client_version >= 40000 ? mysql_get_server_version(&mysql) : local_mysql_get_server_version()); | ||
| 43 | + | ||
| 44 | + /* Fetch column names */ | ||
| 45 | + while((field = mysql_fetch_field(res))) | ||
| 46 | + { | ||
| 47 | + if(strcmp (field->name, (local_mysql_server_version >= 40000 ? "Slave_IO_Running" : "Slave_Running")) == 0) { | ||
| 48 | + col_slave_run = (mysql_field_tell(res) -1); | ||
| 49 | + } | ||
| 50 | + if(strcmp (field->name, "Slave_SQL_Running") == 0) { | ||
| 51 | + col_slave_sql_run = (mysql_field_tell(res) -1); | ||
| 52 | + } | ||
| 53 | + } | ||
| 54 | + | ||
| 55 | /* fetch the first row */ | ||
| 56 | if ( (row = mysql_fetch_row (res)) == NULL) { | ||
| 57 | mysql_free_result (res); | ||
| 58 | @@ -114,27 +141,38 @@ | ||
| 59 | die (STATE_CRITICAL, _("slave fetch row error: %s\n"), mysql_error (&mysql)); | ||
| 60 | } | ||
| 61 | |||
| 62 | - if (mysql_field_count (&mysql) == 12) { | ||
| 63 | - /* mysql 3.23.x */ | ||
| 64 | - snprintf (slaveresult, SLAVERESULTSIZE, _("Slave running: %s"), row[6]); | ||
| 65 | - if (strcmp (row[6], "Yes") != 0) { | ||
| 66 | - mysql_free_result (res); | ||
| 67 | - mysql_close (&mysql); | ||
| 68 | - die (STATE_CRITICAL, "%s\n", slaveresult); | ||
| 69 | + if (local_mysql_server_version >= 40000) { | ||
| 70 | + /* mysql 4.x.x */ | ||
| 71 | + if ((col_slave_run > 0) && (col_slave_sql_run > 0)) { | ||
| 72 | + snprintf (slaveresult, SLAVERESULTSIZE, "Slave IO: %s Slave SQL: %s", row[col_slave_run], row[col_slave_sql_run]); | ||
| 73 | + if (strcmp (row[col_slave_run], "Yes") != 0 || strcmp (row[col_slave_sql_run], "Yes") != 0) { | ||
| 74 | + col_slave_err = 1; | ||
| 75 | + } | ||
| 76 | + } else { | ||
| 77 | + snprintf (slaveresult, SLAVERESULTSIZE, "Required Slave columns not found"); | ||
| 78 | + col_slave_err = 1; | ||
| 79 | } | ||
| 80 | - | ||
| 81 | } else { | ||
| 82 | - /* mysql 4.x.x */ | ||
| 83 | - snprintf (slaveresult, SLAVERESULTSIZE, "Slave IO: %s Slave SQL: %s", row[9], row[10]); | ||
| 84 | - if (strcmp (row[9], "Yes") != 0 || strcmp (row[10], "Yes") != 0) { | ||
| 85 | - mysql_free_result (res); | ||
| 86 | - mysql_close (&mysql); | ||
| 87 | - die (STATE_CRITICAL, "%s\n", slaveresult); | ||
| 88 | + /* mysql 3.23.x */ | ||
| 89 | + if (col_slave_run > 0) { | ||
| 90 | + snprintf (slaveresult, SLAVERESULTSIZE, _("Slave running: %s"), row[col_slave_run]); | ||
| 91 | + if (strcmp (row[col_slave_run], "Yes") != 0) { | ||
| 92 | + col_slave_err = 1; | ||
| 93 | + } | ||
| 94 | + } else { | ||
| 95 | + snprintf (slaveresult, SLAVERESULTSIZE, "Required Slave column not found"); | ||
| 96 | + col_slave_err = 1; | ||
| 97 | } | ||
| 98 | } | ||
| 99 | |||
| 100 | /* free the result */ | ||
| 101 | mysql_free_result (res); | ||
| 102 | + | ||
| 103 | + /* Check for trouble */ | ||
| 104 | + if(col_slave_err > 0) { | ||
| 105 | + mysql_close (&mysql); | ||
| 106 | + die (STATE_CRITICAL, "%s\n", slaveresult); | ||
| 107 | + } | ||
| 108 | } | ||
| 109 | |||
| 110 | /* close the connection */ | ||
| 111 | @@ -150,6 +188,16 @@ | ||
| 112 | return STATE_OK; | ||
| 113 | } | ||
| 114 | |||
| 115 | +/* Get version number for server */ | ||
| 116 | +local_mysql_get_server_version(MYSQL *mysql) | ||
| 117 | +{ | ||
| 118 | + uint major, minor, version; | ||
| 119 | + char *pos= mysql->server_version, *end_pos; | ||
| 120 | + major= (uint) strtoul(pos, &end_pos, 10); pos=end_pos+1; | ||
| 121 | + minor= (uint) strtoul(pos, &end_pos, 10); pos=end_pos+1; | ||
| 122 | + version= (uint) strtoul(pos, &end_pos, 10); | ||
| 123 | + return (ulong) major*10000L+(ulong) (minor*100+version); | ||
| 124 | +} | ||
| 125 | |||
| 126 | /* process command-line arguments */ | ||
| 127 | int | ||
