diff options
| author | datamuc <data@consol.de> | 2022-01-25 10:57:02 +0100 | 
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-01-25 10:57:02 +0100 | 
| commit | e2397167c7e5c7a02b68de45de946f63706e7d12 (patch) | |
| tree | ed0a0addc229083d132a2c7e4a9b0a96a72d5aaa | |
| parent | 49bf8b3e61264d9783b07bc1299492c448e3a0eb (diff) | |
| download | monitoring-plugins-e2397167c7e5c7a02b68de45de946f63706e7d12.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.c | 17 | 
1 files changed, 16 insertions, 1 deletions
| diff --git a/plugins/check_pgsql.c b/plugins/check_pgsql.c index b8fc5f1d..c893386c 100644 --- a/plugins/check_pgsql.c +++ b/plugins/check_pgsql.c | |||
| @@ -85,6 +85,8 @@ char *pgparams = NULL; | |||
| 85 | double twarn = (double)DEFAULT_WARN; | 85 | double twarn = (double)DEFAULT_WARN; | 
| 86 | double tcrit = (double)DEFAULT_CRIT; | 86 | double tcrit = (double)DEFAULT_CRIT; | 
| 87 | char *pgquery = NULL; | 87 | char *pgquery = NULL; | 
| 88 | #define OPTID_QUERYNAME -1000 | ||
| 89 | char *pgqueryname = NULL; | ||
| 88 | char *query_warning = NULL; | 90 | char *query_warning = NULL; | 
| 89 | char *query_critical = NULL; | 91 | char *query_critical = NULL; | 
| 90 | thresholds *qthresholds = NULL; | 92 | thresholds *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 : ""); | 
