[monitoring-plugins] check_mysql_query: add option to hide query in ...

GitHub git at monitoring-plugins.org
Thu Jun 18 16:50:14 CEST 2026


    Module: monitoring-plugins
    Branch: master
    Commit: c48c426a8e11c878d9c882b90025eaf2c97da2b0
    Author: Lorenz Kästle <12514511+RincewindsHat at users.noreply.github.com>
 Committer: GitHub <noreply at github.com>
      Date: Thu Jun 18 16:47:56 2026 +0200
       URL: https://www.monitoring-plugins.org/repositories/monitoring-plugins/commit/?id=c48c426a

check_mysql_query: add option to hide query in output (#2279)

Co-authored-by: Lorenz Kästle <lorenz.kaestle at netways.de>

---

 plugins/check_mysql_query.c          | 14 +++++++++++++-
 plugins/check_mysql_query.d/config.h |  3 +++
 2 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/plugins/check_mysql_query.c b/plugins/check_mysql_query.c
index ff86e219..8d46eaae 100644
--- a/plugins/check_mysql_query.c
+++ b/plugins/check_mysql_query.c
@@ -183,7 +183,11 @@ int main(int argc, char **argv) {
 	mp_add_perfdata_to_subcheck(&sc_value, pd_query_result);
 
 	sc_value = mp_set_subcheck_state(sc_value, mp_get_pd_status(pd_query_result));
-	xasprintf(&sc_value.output, "'%s' returned '%f'", config.sql_query, value);
+	if (config.queryname != NULL) {
+		xasprintf(&sc_value.output, "query '%s' returned '%f'", config.queryname, value);
+	} else {
+		xasprintf(&sc_value.output, "query '%s' returned '%f'", config.sql_query, value);
+	}
 
 	mp_add_subcheck_to_check(&overall, sc_value);
 
@@ -194,6 +198,7 @@ int main(int argc, char **argv) {
 check_mysql_query_config_wrapper process_arguments(int argc, char **argv) {
 	enum {
 		output_format_index = CHAR_MAX + 1,
+		queryname_index,
 	};
 
 	static struct option longopts[] = {{"hostname", required_argument, 0, 'H'},
@@ -211,6 +216,7 @@ check_mysql_query_config_wrapper process_arguments(int argc, char **argv) {
 									   {"warning", required_argument, 0, 'w'},
 									   {"critical", required_argument, 0, 'c'},
 									   {"output-format", required_argument, 0, output_format_index},
+									   {"queryname", required_argument, 0, queryname_index},
 									   {0, 0, 0, 0}};
 
 	check_mysql_query_config_wrapper result = {
@@ -305,6 +311,9 @@ check_mysql_query_config_wrapper process_arguments(int argc, char **argv) {
 			result.config.output_format = parser.output_format;
 			break;
 		}
+		case queryname_index: {
+			result.config.queryname = optarg;
+		}
 		}
 	}
 
@@ -350,6 +359,9 @@ void print_help(void) {
 	printf(UT_EXTRA_OPTS);
 	printf(" -q, --query=STRING\n");
 	printf("    %s\n", _("SQL query to run. Only first column in first row will be read"));
+	printf("     --queryname\n");
+	printf("    %s\n", _("A name for the query, this string is used instead of the query"));
+
 	printf(UT_WARN_CRIT_RANGE);
 	printf(UT_HOST_PORT, 'P', myport);
 	printf(" %s\n", "-s, --socket=STRING");
diff --git a/plugins/check_mysql_query.d/config.h b/plugins/check_mysql_query.d/config.h
index 32ab455a..99df44ee 100644
--- a/plugins/check_mysql_query.d/config.h
+++ b/plugins/check_mysql_query.d/config.h
@@ -16,6 +16,7 @@ typedef struct {
 	unsigned int db_port;
 
 	char *sql_query;
+	char *queryname;
 	mp_thresholds thresholds;
 
 	bool output_format_is_set;
@@ -28,12 +29,14 @@ check_mysql_query_config check_mysql_query_config_init() {
 		.db_socket = NULL,
 		.db = NULL,
 		.db_user = NULL,
+
 		.db_pass = NULL,
 		.opt_file = NULL,
 		.opt_group = NULL,
 		.db_port = MYSQL_PORT,
 
 		.sql_query = NULL,
+		.queryname = NULL,
 		.thresholds = mp_thresholds_init(),
 
 		.output_format_is_set = false,



More information about the Commits mailing list