[monitoring-plugins] check_mysql: account for UNTIL condition in ...

GitHub git at monitoring-plugins.org
Tue Sep 8 15:20:14 CEST 2026


    Module: monitoring-plugins
    Branch: master
    Commit: f097a13cc70bb469ea4a4a8b500b48b704a8a00e
    Author: Lorenz Kästle <12514511+RincewindsHat at users.noreply.github.com>
 Committer: GitHub <noreply at github.com>
      Date: Tue Sep  8 15:12:11 2026 +0200
       URL: https://www.monitoring-plugins.org/repositories/monitoring-plugins/commit/?id=f097a13c

check_mysql: account for UNTIL condition in replica logic (#2337)

* Remove unused constant

* check_mysql: account for UNTIL condition in replica logic

When told to check replica functionality check_mysql went
CRITICAL when a replica thread was stopped.
It is however possible that this is intentional when a
replica thread is started with an UNTIL condition and it will
then stop at that position in the binlog.

This patch adds detection for that UNTIL condition to avoid
this false positive scenario.

---

 plugins/check_mysql.c | 31 +++++++++++++++++++++----------
 1 file changed, 21 insertions(+), 10 deletions(-)

diff --git a/plugins/check_mysql.c b/plugins/check_mysql.c
index 882b06db..b09fa4bb 100644
--- a/plugins/check_mysql.c
+++ b/plugins/check_mysql.c
@@ -50,8 +50,6 @@ const char *email = "devel at monitoring-plugins.org";
 
 static int verbose = 0;
 
-#define REPLICA_RESULTSIZE 96
-
 #define LENGTH_METRIC_UNIT 6
 static const char *metric_unit[LENGTH_METRIC_UNIT] = {
 	"Open_files",        "Open_tables",    "Qcache_free_memory", "Qcache_queries_in_cache",
@@ -347,6 +345,8 @@ int main(int argc, char **argv) {
 			int replica_io_field = -1;
 			int replica_sql_field = -1;
 			int seconds_behind_field = -1;
+			int until_condition_field = -1;
+			int last_errno_field = -1;
 			unsigned int num_fields = mysql_num_fields(res);
 			MYSQL_FIELD *fields = mysql_fetch_fields(res);
 			for (int i = 0; i < (int)num_fields; i++) {
@@ -365,10 +365,19 @@ int main(int argc, char **argv) {
 					seconds_behind_field = i;
 					continue;
 				}
+				if (strcasecmp(fields[i].name, "Until_Condition") == 0) {
+					until_condition_field = i;
+					continue;
+				}
+				if (strcasecmp(fields[i].name, "Last_Errno") == 0) {
+					last_errno_field = i;
+					continue;
+				}
 			}
 
 			/* Check if replica status is available */
-			if ((replica_io_field < 0) || (replica_sql_field < 0) || (num_fields == 0)) {
+			if ((replica_io_field < 0) || (replica_sql_field < 0) || (num_fields == 0) ||
+				(last_errno_field != -1)) {
 				mysql_free_result(res);
 				mysql_close(&mysql);
 
@@ -379,15 +388,17 @@ int main(int argc, char **argv) {
 			}
 
 			/* Save replica status in replica_result */
-			mopl_utils_xasprintf(&sc_replica.output,
-					  "Replica IO: %s Replica SQL: %s Seconds Behind Master: %s",
-					  row[replica_io_field], row[replica_sql_field],
-					  seconds_behind_field != -1 ? row[seconds_behind_field] : "Unknown");
+			mopl_utils_xasprintf(
+				&sc_replica.output, "Replica IO: %s Replica SQL: %s Seconds Behind Master: %s",
+				row[replica_io_field], row[replica_sql_field],
+				seconds_behind_field != -1 ? row[seconds_behind_field] : "Unknown");
 
 			/* Raise critical error if SQL THREAD or IO THREAD are stopped, but only if there are no
-			 * mysqldump threads running */
-			if (strcmp(row[replica_io_field], "Yes") != 0 ||
-				strcmp(row[replica_sql_field], "Yes") != 0) {
+			 * mysqldump threads running AND there is no until condition set AND last_errno is not set */
+			if (((strcmp(row[until_condition_field], "None") == 0) &&
+				 ((strcmp(row[replica_io_field], "Yes") != 0) ||
+				  (strcmp(row[replica_sql_field], "Yes") != 0))) ||
+				(strcmp(row[last_errno_field], "0") != 0)) {
 				MYSQL_RES *res_mysqldump;
 				MYSQL_ROW row_mysqldump;
 				unsigned int mysqldump_threads = 0;



More information about the Commits mailing list