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