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.c51
1 files changed, 49 insertions, 2 deletions
diff --git a/plugins/check_mysql.c b/plugins/check_mysql.c
index 6a7daf11..1b7403f7 100644
--- a/plugins/check_mysql.c
+++ b/plugins/check_mysql.c
@@ -211,8 +211,55 @@ main (int argc, char **argv)
211 } 211 }
212 212
213 if(check_slave) { 213 if(check_slave) {
214 /* check the slave status */ 214 // Detect which version we are, on older version
215 if (mysql_query (&mysql, "show slave status") != 0) { 215 // "show slave status" should work, on newer ones
216 // "show replica status"
217 // But first we have to find out whether this is
218 // MySQL or MariaDB since the version numbering scheme
219 // is different
220 bool use_deprecated_slave_status = false;
221 const char *server_version = mysql_get_server_info(&mysql);
222 unsigned long server_verion_int = mysql_get_server_version(&mysql);
223 unsigned long major_version = server_verion_int / 10000;
224 unsigned long minor_version = (server_verion_int % 10000) / 100;
225 unsigned long patch_version = (server_verion_int % 100);
226 if (verbose) {
227 printf("Found MariaDB: %s, main version: %lu, minor version: %lu, patch version: %lu\n", server_version, major_version,
228 minor_version, patch_version);
229 }
230
231 if (strstr(server_version, "MariaDB") != NULL) {
232 // Looks like MariaDB, new commands should be available after 10.5.1
233 if (major_version < 10) {
234 use_deprecated_slave_status = true;
235 } else if (major_version == 10) {
236 if (minor_version < 5) {
237 use_deprecated_slave_status = true;
238 } else if (minor_version == 5 && patch_version < 1) {
239 use_deprecated_slave_status = true;
240 }
241 }
242 } else if (strstr(server_version, "MySQL") != NULL) {
243 // Looks like MySQL
244 if (major_version < 8) {
245 use_deprecated_slave_status = true;
246 } else if (major_version == 10 && minor_version < 4) {
247 use_deprecated_slave_status = true;
248 }
249 } else {
250 printf("Not a known sever implementation: %s\n", server_version);
251 exit(STATE_UNKNOWN);
252 }
253
254 char *replica_query = NULL;
255 if (use_deprecated_slave_status) {
256 replica_query = "show slave status";
257 } else {
258 replica_query = "show replica status";
259 }
260
261 /* check the replica status */
262 if (mysql_query(&mysql, replica_query) != 0) {
216 error = strdup(mysql_error(&mysql)); 263 error = strdup(mysql_error(&mysql));
217 mysql_close (&mysql); 264 mysql_close (&mysql);
218 die (STATE_CRITICAL, _("slave query error: %s\n"), error); 265 die (STATE_CRITICAL, _("slave query error: %s\n"), error);