From 3929c5ac37a5b6c6ae0430c40438da087da07e1a Mon Sep 17 00:00:00 2001 From: Gerardo Malazdrewicz <36243997+GerMalaz@users.noreply.github.com> Date: Sun, 31 Oct 2021 09:37:55 -0300 Subject: check_mysql.c: Detect running mysqldump When checking a slave, if the IO Thread or the SQL Thread are stopped, check for running mysqldump threads, return STATE_OK if there is any. Requires PROCESS privilege to work (else the mysqldump thread(s) would not be detected). Enlarged SLAVERESULTSIZE to fit "Mysqldump: in progress" at the end of the string. Got a NULL pointer in row[seconds_behind_field] instead of the "NULL" string when a mysqldump is running [mysql 5.7.34 + libmariadb3 10.3.31], so added a check for that. --- plugins/check_mysql.c | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) (limited to 'plugins/check_mysql.c') diff --git a/plugins/check_mysql.c b/plugins/check_mysql.c index 0cba50e6..5b9a4fec 100644 --- a/plugins/check_mysql.c +++ b/plugins/check_mysql.c @@ -34,7 +34,7 @@ const char *progname = "check_mysql"; const char *copyright = "1999-2011"; const char *email = "devel@monitoring-plugins.org"; -#define SLAVERESULTSIZE 70 +#define SLAVERESULTSIZE 96 #include "common.h" #include "utils.h" @@ -89,6 +89,8 @@ static const char *metric_counter[LENGTH_METRIC_COUNTER] = { "Uptime" }; +#define MYSQLDUMP_THREADS_QUERY "SELECT COUNT(1) mysqldumpThreads FROM information_schema.processlist WHERE info LIKE 'SELECT /*!40001 SQL_NO_CACHE */%'" + thresholds *my_threshold = NULL; int process_arguments (int, char **); @@ -275,11 +277,29 @@ main (int argc, char **argv) /* Save slave status in slaveresult */ 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"); - /* Raise critical error if SQL THREAD or IO THREAD are stopped */ + /* Raise critical error if SQL THREAD or IO THREAD are stopped, but only if there are no mysqldump threads running */ if (strcmp (row[slave_io_field], "Yes") != 0 || strcmp (row[slave_sql_field], "Yes") != 0) { - mysql_free_result (res); - mysql_close (&mysql); - die (STATE_CRITICAL, "%s\n", slaveresult); + MYSQL_RES *res_mysqldump; + MYSQL_ROW row_mysqldump; + unsigned int mysqldump_threads = 0; + + if (mysql_query (&mysql, MYSQLDUMP_THREADS_QUERY) == 0) { + /* store the result */ + if ( (res_mysqldump = mysql_store_result (&mysql)) != NULL) { + if (mysql_num_rows(res_mysqldump) == 1) { + if ( (row_mysqldump = mysql_fetch_row (res_mysqldump)) != NULL) { + mysqldump_threads = atoi(row_mysqldump[0]); + } + } + /* free the result */ + mysql_free_result (res_mysqldump); + } + } + if (mysqldump_threads == 0) { + die (STATE_CRITICAL, "%s\n", slaveresult); + } else { + strlcat (slaveresult, " Mysqldump: in progress", SLAVERESULTSIZE); + } } if (verbose >=3) { @@ -291,7 +311,7 @@ main (int argc, char **argv) } /* Check Seconds Behind against threshold */ - 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)) { double value = atof(row[seconds_behind_field]); int status; -- cgit v1.2.3-74-g34f1 From d10ee31d89c2c599ee4c502e82d632aef8554020 Mon Sep 17 00:00:00 2001 From: Lorenz Kästle Date: Fri, 28 Apr 2023 16:51:39 +0200 Subject: Typo in check_mysql --- plugins/check_mysql.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'plugins/check_mysql.c') diff --git a/plugins/check_mysql.c b/plugins/check_mysql.c index 0cba50e6..6cfa70ed 100644 --- a/plugins/check_mysql.c +++ b/plugins/check_mysql.c @@ -551,7 +551,7 @@ print_help (void) printf (" %s\n", _("Exit with CRITICAL status if slave server is more then INTEGER seconds")); printf (" %s\n", _("behind master")); printf (" %s\n", "-l, --ssl"); - printf (" %s\n", _("Use ssl encryptation")); + printf (" %s\n", _("Use ssl encryption")); printf (" %s\n", "-C, --ca-cert=STRING"); printf (" %s\n", _("Path to CA signing the cert")); printf (" %s\n", "-a, --cert=STRING"); -- cgit v1.2.3-74-g34f1 From 10863265324a9a9fdf8ce771271af15b7e2f5a4a Mon Sep 17 00:00:00 2001 From: Platon Pronko Date: Fri, 19 May 2023 15:05:02 +0800 Subject: check_mysql: handle ER_ACCESS_DENIED_NO_PASSWORD_ERROR if ignore_auth=1 In some situations MySQL might return ER_ACCESS_DENIED_NO_PASSWORD_ERROR instead of ER_ACCESS_DENIED_ERROR. Semantically these errors are the same. --- plugins/check_mysql.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'plugins/check_mysql.c') diff --git a/plugins/check_mysql.c b/plugins/check_mysql.c index 6cfa70ed..91e150fb 100644 --- a/plugins/check_mysql.c +++ b/plugins/check_mysql.c @@ -138,7 +138,10 @@ main (int argc, char **argv) mysql_ssl_set(&mysql,key,cert,ca_cert,ca_dir,ciphers); /* establish a connection to the server and error checking */ if (!mysql_real_connect(&mysql,db_host,db_user,db_pass,db,db_port,db_socket,0)) { - if (ignore_auth && mysql_errno (&mysql) == ER_ACCESS_DENIED_ERROR) + /* Depending on internally-selected auth plugin MySQL might return */ + /* ER_ACCESS_DENIED_NO_PASSWORD_ERROR or ER_ACCESS_DENIED_ERROR. */ + /* Semantically these errors are the same. */ + if (ignore_auth && (mysql_errno (&mysql) == ER_ACCESS_DENIED_ERROR || mysql_errno (&mysql) == ER_ACCESS_DENIED_NO_PASSWORD_ERROR)) { printf("MySQL OK - Version: %s (protocol %d)\n", mysql_get_server_info(&mysql), -- cgit v1.2.3-74-g34f1 From c405dbafccd27259bd860ea408b32f2594e1a384 Mon Sep 17 00:00:00 2001 From: RincewindsHat <12514511+RincewindsHat@users.noreply.github.com> Date: Mon, 18 Sep 2023 19:18:35 +0200 Subject: Add mysql_close to avoid spamming the server logs --- plugins/check_mysql.c | 1 + 1 file changed, 1 insertion(+) (limited to 'plugins/check_mysql.c') diff --git a/plugins/check_mysql.c b/plugins/check_mysql.c index 5b9a4fec..8dc554f1 100644 --- a/plugins/check_mysql.c +++ b/plugins/check_mysql.c @@ -294,6 +294,7 @@ main (int argc, char **argv) /* free the result */ mysql_free_result (res_mysqldump); } + mysql_close (&mysql); } if (mysqldump_threads == 0) { die (STATE_CRITICAL, "%s\n", slaveresult); -- cgit v1.2.3-74-g34f1 From ce355c80cf6054bfa5e1dcf81f9e2183ef963ee1 Mon Sep 17 00:00:00 2001 From: RincewindsHat <12514511+RincewindsHat@users.noreply.github.com> Date: Mon, 18 Sep 2023 22:58:34 +0200 Subject: Initialize slaveresult to 0 and use strncat instead of bsd strlcat --- plugins/check_mysql.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'plugins/check_mysql.c') diff --git a/plugins/check_mysql.c b/plugins/check_mysql.c index 8dc554f1..9b7d13f3 100644 --- a/plugins/check_mysql.c +++ b/plugins/check_mysql.c @@ -110,7 +110,7 @@ main (int argc, char **argv) char *result = NULL; char *error = NULL; - char slaveresult[SLAVERESULTSIZE]; + char slaveresult[SLAVERESULTSIZE] = { 0 }; char* perf; perf = strdup (""); @@ -299,7 +299,7 @@ main (int argc, char **argv) if (mysqldump_threads == 0) { die (STATE_CRITICAL, "%s\n", slaveresult); } else { - strlcat (slaveresult, " Mysqldump: in progress", SLAVERESULTSIZE); + strncat(slaveresult, " Mysqldump: in progress", SLAVERESULTSIZE-1); } } -- cgit v1.2.3-74-g34f1