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') 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 a00c412e7ba1474b32f478daf039d2bdf71f072a Mon Sep 17 00:00:00 2001 From: RincewindsHat <12514511+RincewindsHat@users.noreply.github.com> Date: Sun, 12 Mar 2023 14:59:23 +0100 Subject: Fixes for -Wnonnull-compare --- lib/utils_cmd.c | 4 ---- plugins/runcmd.c | 4 ---- 2 files changed, 8 deletions(-) (limited to 'plugins') diff --git a/lib/utils_cmd.c b/lib/utils_cmd.c index 8b8e5708..34fb3909 100644 --- a/lib/utils_cmd.c +++ b/lib/utils_cmd.c @@ -118,10 +118,6 @@ _cmd_open (char *const *argv, int *pfd, int *pfderr) int i = 0; - /* if no command was passed, return with no error */ - if (argv == NULL) - return -1; - if (!_cmd_pids) CMD_INIT; diff --git a/plugins/runcmd.c b/plugins/runcmd.c index 1bd2ca1f..ff1987fd 100644 --- a/plugins/runcmd.c +++ b/plugins/runcmd.c @@ -114,10 +114,6 @@ np_runcmd_open(const char *cmdstring, int *pfd, int *pfderr) env[0] = strdup("LC_ALL=C"); env[1] = '\0'; - /* if no command was passed, return with no error */ - if (cmdstring == NULL) - return -1; - /* make copy of command string so strtok() doesn't silently modify it */ /* (the calling program may want to access it later) */ cmdlen = strlen(cmdstring); -- cgit v1.2.3-74-g34f1 From 6d341c40ab4d84d5eabfd672de1ffa3c7ecd07be Mon Sep 17 00:00:00 2001 From: RincewindsHat <12514511+RincewindsHat@users.noreply.github.com> Date: Sun, 12 Mar 2023 14:04:25 +0100 Subject: Fixes for Waddress * check_snmp: Fix string comparison --- plugins/check_snmp.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'plugins') diff --git a/plugins/check_snmp.c b/plugins/check_snmp.c index c425df3c..425bb7b2 100644 --- a/plugins/check_snmp.c +++ b/plugins/check_snmp.c @@ -422,7 +422,8 @@ main (int argc, char **argv) } else if (strstr (response, "INTEGER: ")) { show = multiply (strstr (response, "INTEGER: ") + 9); - if (fmtstr != "") { + + if (strcmp(fmtstr, "") != 0) { conv = fmtstr; } } @@ -596,8 +597,9 @@ main (int argc, char **argv) len = sizeof(perfstr)-strlen(perfstr)-1; strncat(perfstr, show, len>ptr-show ? ptr-show : len); - if (type) + if (strcmp(type, "") != 0) { strncat(perfstr, type, sizeof(perfstr)-strlen(perfstr)-1); + } if (warning_thresholds) { strncat(perfstr, ";", sizeof(perfstr)-strlen(perfstr)-1); @@ -1185,7 +1187,7 @@ multiply (char *str) if(verbose>2) printf(" multiply extracted double: %f\n", val); val *= multiplier; - if (fmtstr != "") { + if (strcmp(fmtstr, "") != 0) { conv = fmtstr; } if (val == (int)val) { -- cgit v1.2.3-74-g34f1 From 068c124f361d4c615aed79f6fe607f39040b2e31 Mon Sep 17 00:00:00 2001 From: Lorenz Kästle Date: Tue, 11 Jul 2023 16:39:29 +0200 Subject: Detect if fmtstr was set in edge cases --- plugins/check_snmp.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'plugins') diff --git a/plugins/check_snmp.c b/plugins/check_snmp.c index 425bb7b2..135bbc7c 100644 --- a/plugins/check_snmp.c +++ b/plugins/check_snmp.c @@ -158,6 +158,7 @@ int perf_labels = 1; char* ip_version = ""; double multiplier = 1.0; char *fmtstr = ""; +bool fmtstr_set = false; char buffer[DEFAULT_BUFFER_SIZE]; static char *fix_snmp_range(char *th) @@ -423,7 +424,7 @@ main (int argc, char **argv) else if (strstr (response, "INTEGER: ")) { show = multiply (strstr (response, "INTEGER: ") + 9); - if (strcmp(fmtstr, "") != 0) { + if (fmtstr_set) { conv = fmtstr; } } @@ -973,6 +974,7 @@ process_arguments (int argc, char **argv) case 'f': if (multiplier != 1.0) { fmtstr=optarg; + fmtstr_set = true; } break; } @@ -1187,7 +1189,7 @@ multiply (char *str) if(verbose>2) printf(" multiply extracted double: %f\n", val); val *= multiplier; - if (strcmp(fmtstr, "") != 0) { + if (fmtstr_set) { conv = fmtstr; } if (val == (int)val) { -- cgit v1.2.3-74-g34f1 From a6802bd5f50a5c12ed5bafa4fe9ee14fede7c1e1 Mon Sep 17 00:00:00 2001 From: Thoralf Rickert-Wendt <30341294+trickert76@users.noreply.github.com> Date: Tue, 8 Aug 2023 10:22:53 +0200 Subject: Fix issue #1872 --- plugins/check_http.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'plugins') diff --git a/plugins/check_http.c b/plugins/check_http.c index 1288c415..718c8ee7 100644 --- a/plugins/check_http.c +++ b/plugins/check_http.c @@ -1279,7 +1279,7 @@ check_http (void) regmatch_t chre_pmatch[1]; // We actually do not care about this, since we only want to know IF it was found - if (regexec(&chunked_header_regex, header, 1, chre_pmatch, 0) == 0) { + if (!no_body && regexec(&chunked_header_regex, header, 1, chre_pmatch, 0) == 0) { if (verbose) { printf("Found chunked content\n"); } -- cgit v1.2.3-74-g34f1 From 53ea2304aa8364f74e76f82430b67833fccf402f Mon Sep 17 00:00:00 2001 From: RincewindsHat <12514511+RincewindsHat@users.noreply.github.com> Date: Tue, 12 Sep 2023 00:50:55 +0200 Subject: check_disk: Remove some dead variables --- plugins/check_disk.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'plugins') diff --git a/plugins/check_disk.c b/plugins/check_disk.c index 39dc6cd2..05e55022 100644 --- a/plugins/check_disk.c +++ b/plugins/check_disk.c @@ -131,9 +131,6 @@ bool stat_path (struct parameter_list *p); void get_stats (struct parameter_list *p, struct fs_usage *fsp); void get_path_stats (struct parameter_list *p, struct fs_usage *fsp); -double w_dfp = -1.0; -double c_dfp = -1.0; -char *path; char *exclude_device; char *units; uintmax_t mult = 1024 * 1024; @@ -889,7 +886,7 @@ process_arguments (int argc, char **argv) if (crit_usedspace_percent == NULL && argc > c && is_intnonneg (argv[c])) crit_usedspace_percent = argv[c++]; - if (argc > c && path == NULL) { + if (argc > c) { se = np_add_parameter(&path_select_list, strdup(argv[c++])); path_selected = TRUE; set_all_thresholds(se); -- 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') 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') 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