summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordatamuc <data@consol.de>2022-01-25 09:57:02 (GMT)
committerGitHub <noreply@github.com>2022-01-25 09:57:02 (GMT)
commite2397167c7e5c7a02b68de45de946f63706e7d12 (patch)
treeed0a0addc229083d132a2c7e4a9b0a96a72d5aaa
parent49bf8b3e61264d9783b07bc1299492c448e3a0eb (diff)
downloadmonitoring-plugins-e239716.tar.gz
add --queryname parameter to check_pgsql (#1741)
This is used in the long output instead of the actual query. So instead of OK - 'select stuff from various, tables where some_stuff is null and other_stuff is not null' returned 42 one can use --queryname=check_greatest_basket and it will print OK - check_greatest_basket returned 42 That's nicer for alerting purposes, at least in our use case.
-rw-r--r--plugins/check_pgsql.c17
1 files changed, 16 insertions, 1 deletions
diff --git a/plugins/check_pgsql.c b/plugins/check_pgsql.c
index b8fc5f1..c893386 100644
--- a/plugins/check_pgsql.c
+++ b/plugins/check_pgsql.c
@@ -85,6 +85,8 @@ char *pgparams = NULL;
85double twarn = (double)DEFAULT_WARN; 85double twarn = (double)DEFAULT_WARN;
86double tcrit = (double)DEFAULT_CRIT; 86double tcrit = (double)DEFAULT_CRIT;
87char *pgquery = NULL; 87char *pgquery = NULL;
88#define OPTID_QUERYNAME -1000
89char *pgqueryname = NULL;
88char *query_warning = NULL; 90char *query_warning = NULL;
89char *query_critical = NULL; 91char *query_critical = NULL;
90thresholds *qthresholds = NULL; 92thresholds *qthresholds = NULL;
@@ -285,6 +287,7 @@ process_arguments (int argc, char **argv)
285 {"database", required_argument, 0, 'd'}, 287 {"database", required_argument, 0, 'd'},
286 {"option", required_argument, 0, 'o'}, 288 {"option", required_argument, 0, 'o'},
287 {"query", required_argument, 0, 'q'}, 289 {"query", required_argument, 0, 'q'},
290 {"queryname", required_argument, 0, OPTID_QUERYNAME},
288 {"query_critical", required_argument, 0, 'C'}, 291 {"query_critical", required_argument, 0, 'C'},
289 {"query_warning", required_argument, 0, 'W'}, 292 {"query_warning", required_argument, 0, 'W'},
290 {"verbose", no_argument, 0, 'v'}, 293 {"verbose", no_argument, 0, 'v'},
@@ -368,6 +371,9 @@ process_arguments (int argc, char **argv)
368 case 'q': 371 case 'q':
369 pgquery = optarg; 372 pgquery = optarg;
370 break; 373 break;
374 case OPTID_QUERYNAME:
375 pgqueryname = optarg;
376 break;
371 case 'v': 377 case 'v':
372 verbose++; 378 verbose++;
373 break; 379 break;
@@ -529,6 +535,9 @@ print_help (void)
529 535
530 printf (" %s\n", "-q, --query=STRING"); 536 printf (" %s\n", "-q, --query=STRING");
531 printf (" %s\n", _("SQL query to run. Only first column in first row will be read")); 537 printf (" %s\n", _("SQL query to run. Only first column in first row will be read"));
538 printf (" %s\n", "--queryname=STRING");
539 printf (" %s\n", _("A name for the query, this string is used instead of the query"));
540 printf (" %s\n", _("in the long output of the plugin"));
532 printf (" %s\n", "-W, --query-warning=RANGE"); 541 printf (" %s\n", "-W, --query-warning=RANGE");
533 printf (" %s\n", _("SQL query value to result in warning status (double)")); 542 printf (" %s\n", _("SQL query value to result in warning status (double)"));
534 printf (" %s\n", "-C, --query-critical=RANGE"); 543 printf (" %s\n", "-C, --query-critical=RANGE");
@@ -642,7 +651,13 @@ do_query (PGconn *conn, char *query)
642 : (my_status == STATE_CRITICAL) 651 : (my_status == STATE_CRITICAL)
643 ? _("CRITICAL") 652 ? _("CRITICAL")
644 : _("UNKNOWN")); 653 : _("UNKNOWN"));
645 printf (_("'%s' returned %f"), query, value); 654 if(pgqueryname) {
655 printf (_("%s returned %f"), pgqueryname, value);
656 }
657 else {
658 printf (_("'%s' returned %f"), query, value);
659 }
660
646 printf ("|query=%f;%s;%s;;\n", value, 661 printf ("|query=%f;%s;%s;;\n", value,
647 query_warning ? query_warning : "", 662 query_warning ? query_warning : "",
648 query_critical ? query_critical : ""); 663 query_critical ? query_critical : "");