summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--plugins/check_mysql_query.c14
-rw-r--r--plugins/check_mysql_query.d/config.h3
2 files changed, 16 insertions, 1 deletions
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) {
183 mp_add_perfdata_to_subcheck(&sc_value, pd_query_result); 183 mp_add_perfdata_to_subcheck(&sc_value, pd_query_result);
184 184
185 sc_value = mp_set_subcheck_state(sc_value, mp_get_pd_status(pd_query_result)); 185 sc_value = mp_set_subcheck_state(sc_value, mp_get_pd_status(pd_query_result));
186 xasprintf(&sc_value.output, "'%s' returned '%f'", config.sql_query, value); 186 if (config.queryname != NULL) {
187 xasprintf(&sc_value.output, "query '%s' returned '%f'", config.queryname, value);
188 } else {
189 xasprintf(&sc_value.output, "query '%s' returned '%f'", config.sql_query, value);
190 }
187 191
188 mp_add_subcheck_to_check(&overall, sc_value); 192 mp_add_subcheck_to_check(&overall, sc_value);
189 193
@@ -194,6 +198,7 @@ int main(int argc, char **argv) {
194check_mysql_query_config_wrapper process_arguments(int argc, char **argv) { 198check_mysql_query_config_wrapper process_arguments(int argc, char **argv) {
195 enum { 199 enum {
196 output_format_index = CHAR_MAX + 1, 200 output_format_index = CHAR_MAX + 1,
201 queryname_index,
197 }; 202 };
198 203
199 static struct option longopts[] = {{"hostname", required_argument, 0, 'H'}, 204 static struct option longopts[] = {{"hostname", required_argument, 0, 'H'},
@@ -211,6 +216,7 @@ check_mysql_query_config_wrapper process_arguments(int argc, char **argv) {
211 {"warning", required_argument, 0, 'w'}, 216 {"warning", required_argument, 0, 'w'},
212 {"critical", required_argument, 0, 'c'}, 217 {"critical", required_argument, 0, 'c'},
213 {"output-format", required_argument, 0, output_format_index}, 218 {"output-format", required_argument, 0, output_format_index},
219 {"queryname", required_argument, 0, queryname_index},
214 {0, 0, 0, 0}}; 220 {0, 0, 0, 0}};
215 221
216 check_mysql_query_config_wrapper result = { 222 check_mysql_query_config_wrapper result = {
@@ -305,6 +311,9 @@ check_mysql_query_config_wrapper process_arguments(int argc, char **argv) {
305 result.config.output_format = parser.output_format; 311 result.config.output_format = parser.output_format;
306 break; 312 break;
307 } 313 }
314 case queryname_index: {
315 result.config.queryname = optarg;
316 }
308 } 317 }
309 } 318 }
310 319
@@ -350,6 +359,9 @@ void print_help(void) {
350 printf(UT_EXTRA_OPTS); 359 printf(UT_EXTRA_OPTS);
351 printf(" -q, --query=STRING\n"); 360 printf(" -q, --query=STRING\n");
352 printf(" %s\n", _("SQL query to run. Only first column in first row will be read")); 361 printf(" %s\n", _("SQL query to run. Only first column in first row will be read"));
362 printf(" --queryname\n");
363 printf(" %s\n", _("A name for the query, this string is used instead of the query"));
364
353 printf(UT_WARN_CRIT_RANGE); 365 printf(UT_WARN_CRIT_RANGE);
354 printf(UT_HOST_PORT, 'P', myport); 366 printf(UT_HOST_PORT, 'P', myport);
355 printf(" %s\n", "-s, --socket=STRING"); 367 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 {
16 unsigned int db_port; 16 unsigned int db_port;
17 17
18 char *sql_query; 18 char *sql_query;
19 char *queryname;
19 mp_thresholds thresholds; 20 mp_thresholds thresholds;
20 21
21 bool output_format_is_set; 22 bool output_format_is_set;
@@ -28,12 +29,14 @@ check_mysql_query_config check_mysql_query_config_init() {
28 .db_socket = NULL, 29 .db_socket = NULL,
29 .db = NULL, 30 .db = NULL,
30 .db_user = NULL, 31 .db_user = NULL,
32
31 .db_pass = NULL, 33 .db_pass = NULL,
32 .opt_file = NULL, 34 .opt_file = NULL,
33 .opt_group = NULL, 35 .opt_group = NULL,
34 .db_port = MYSQL_PORT, 36 .db_port = MYSQL_PORT,
35 37
36 .sql_query = NULL, 38 .sql_query = NULL,
39 .queryname = NULL,
37 .thresholds = mp_thresholds_init(), 40 .thresholds = mp_thresholds_init(),
38 41
39 .output_format_is_set = false, 42 .output_format_is_set = false,