diff options
Diffstat (limited to 'plugins/check_pgsql.c')
| -rw-r--r-- | plugins/check_pgsql.c | 289 |
1 files changed, 202 insertions, 87 deletions
diff --git a/plugins/check_pgsql.c b/plugins/check_pgsql.c index 793a686f..bbabd062 100644 --- a/plugins/check_pgsql.c +++ b/plugins/check_pgsql.c | |||
| @@ -28,27 +28,29 @@ | |||
| 28 | * | 28 | * |
| 29 | *****************************************************************************/ | 29 | *****************************************************************************/ |
| 30 | 30 | ||
| 31 | #include "output.h" | ||
| 32 | #include "perfdata.h" | ||
| 31 | #include "states.h" | 33 | #include "states.h" |
| 32 | const char *progname = "check_pgsql"; | ||
| 33 | const char *copyright = "1999-2024"; | ||
| 34 | const char *email = "devel@monitoring-plugins.org"; | ||
| 35 | |||
| 36 | #include "common.h" | 34 | #include "common.h" |
| 37 | #include "utils.h" | 35 | #include "utils.h" |
| 38 | #include "utils_cmd.h" | 36 | #include "utils_cmd.h" |
| 39 | #include "check_pgsql.d/config.h" | 37 | #include "check_pgsql.d/config.h" |
| 40 | #include "thresholds.h" | 38 | #include "thresholds.h" |
| 41 | |||
| 42 | #include "netutils.h" | 39 | #include "netutils.h" |
| 43 | #include <libpq-fe.h> | 40 | #include <libpq-fe.h> |
| 44 | #include <pg_config_manual.h> | 41 | #include <pg_config_manual.h> |
| 45 | 42 | ||
| 43 | const char *progname = "check_pgsql"; | ||
| 44 | const char *copyright = "1999-2024"; | ||
| 45 | const char *email = "devel@monitoring-plugins.org"; | ||
| 46 | |||
| 46 | #define DEFAULT_HOST "127.0.0.1" | 47 | #define DEFAULT_HOST "127.0.0.1" |
| 47 | 48 | ||
| 48 | /* return the PSQL server version as a 3-tuple */ | 49 | /* return the PSQL server version as a 3-tuple */ |
| 49 | #define PSQL_SERVER_VERSION3(server_version) \ | 50 | #define PSQL_SERVER_VERSION3(server_version) \ |
| 50 | (server_version) / 10000, (server_version) / 100 - (int)((server_version) / 10000) * 100, \ | 51 | ((server_version) / 10000), \ |
| 51 | (server_version) - (int)((server_version) / 100) * 100 | 52 | (((server_version) / 100) - (int)(((server_version) / 10000) * 100)), \ |
| 53 | (server_version) - (int)(((server_version) / 100) * 100) | ||
| 52 | /* return true if the given host is a UNIX domain socket */ | 54 | /* return true if the given host is a UNIX domain socket */ |
| 53 | #define PSQL_IS_UNIX_DOMAIN_SOCKET(host) ((NULL == (host)) || ('\0' == *(host)) || ('/' == *(host))) | 55 | #define PSQL_IS_UNIX_DOMAIN_SOCKET(host) ((NULL == (host)) || ('\0' == *(host)) || ('/' == *(host))) |
| 54 | /* return a 3-tuple identifying a host/port independent of the socket type */ | 56 | /* return a 3-tuple identifying a host/port independent of the socket type */ |
| @@ -64,15 +66,25 @@ static check_pgsql_config_wrapper process_arguments(int /*argc*/, char ** /*argv | |||
| 64 | 66 | ||
| 65 | static void print_help(void); | 67 | static void print_help(void); |
| 66 | static bool is_pg_logname(char * /*username*/); | 68 | static bool is_pg_logname(char * /*username*/); |
| 67 | static mp_state_enum do_query(PGconn * /*conn*/, char * /*query*/, const char /*pgqueryname*/[], | 69 | |
| 68 | thresholds * /*qthresholds*/, char * /*query_warning*/, | 70 | typedef enum { |
| 69 | char * /*query_critical*/); | 71 | QUERY_OK, |
| 72 | ERROR_WITH_QUERY, // critical | ||
| 73 | NO_ROWS_RETURNED, // warning | ||
| 74 | NO_COLUMNS_RETURNED, // warning | ||
| 75 | NO_DATA_RETURNED, // critica/ | ||
| 76 | RESULT_IS_NOT_NUMERIC // critical | ||
| 77 | } do_query_errorcode; | ||
| 78 | |||
| 79 | typedef struct { | ||
| 80 | do_query_errorcode error_code; | ||
| 81 | double numerical_result; | ||
| 82 | } do_query_wrapper; | ||
| 83 | static do_query_wrapper do_query(PGconn * /*conn*/, char * /*query*/); | ||
| 70 | void print_usage(void); | 84 | void print_usage(void); |
| 71 | 85 | ||
| 72 | static int verbose = 0; | 86 | static int verbose = 0; |
| 73 | 87 | ||
| 74 | #define OPTID_QUERYNAME -1000 | ||
| 75 | |||
| 76 | /****************************************************************************** | 88 | /****************************************************************************** |
| 77 | 89 | ||
| 78 | The (pseudo?)literate programming XML is contained within \@\@\- <XML> \-\@\@ | 90 | The (pseudo?)literate programming XML is contained within \@\@\- <XML> \-\@\@ |
| @@ -199,21 +211,41 @@ int main(int argc, char **argv) { | |||
| 199 | if (verbose) { | 211 | if (verbose) { |
| 200 | printf("Verifying connection\n"); | 212 | printf("Verifying connection\n"); |
| 201 | } | 213 | } |
| 214 | |||
| 215 | mp_check overall = mp_check_init(); | ||
| 216 | |||
| 217 | mp_subcheck sc_connection = mp_subcheck_init(); | ||
| 218 | |||
| 202 | if (PQstatus(conn) == CONNECTION_BAD) { | 219 | if (PQstatus(conn) == CONNECTION_BAD) { |
| 203 | printf(_("CRITICAL - no connection to '%s' (%s).\n"), config.dbName, PQerrorMessage(conn)); | 220 | sc_connection = mp_set_subcheck_state(sc_connection, STATE_CRITICAL); |
| 221 | xasprintf(&sc_connection.output, "no connection to '%s' (%s)", config.dbName, | ||
| 222 | PQerrorMessage(conn)); | ||
| 204 | PQfinish(conn); | 223 | PQfinish(conn); |
| 205 | return STATE_CRITICAL; | 224 | mp_add_subcheck_to_check(&overall, sc_connection); |
| 206 | } | 225 | mp_exit(overall); |
| 207 | |||
| 208 | mp_state_enum status = STATE_UNKNOWN; | ||
| 209 | if (elapsed_time > config.tcrit) { | ||
| 210 | status = STATE_CRITICAL; | ||
| 211 | } else if (elapsed_time > config.twarn) { | ||
| 212 | status = STATE_WARNING; | ||
| 213 | } else { | 226 | } else { |
| 214 | status = STATE_OK; | 227 | sc_connection = mp_set_subcheck_state(sc_connection, STATE_OK); |
| 228 | xasprintf(&sc_connection.output, "connected to '%s'", config.dbName); | ||
| 229 | mp_add_subcheck_to_check(&overall, sc_connection); | ||
| 215 | } | 230 | } |
| 216 | 231 | ||
| 232 | mp_subcheck sc_connection_time = mp_subcheck_init(); | ||
| 233 | sc_connection_time = mp_set_subcheck_default_state(sc_connection_time, STATE_UNKNOWN); | ||
| 234 | |||
| 235 | xasprintf(&sc_connection_time.output, "connection time: %.10g", elapsed_time); | ||
| 236 | |||
| 237 | mp_perfdata pd_connection_time = perfdata_init(); | ||
| 238 | pd_connection_time.label = "time"; | ||
| 239 | pd_connection_time.uom = "s"; | ||
| 240 | pd_connection_time = mp_set_pd_value(pd_connection_time, elapsed_time); | ||
| 241 | pd_connection_time = mp_pd_set_thresholds(pd_connection_time, config.time_thresholds); | ||
| 242 | |||
| 243 | mp_add_perfdata_to_subcheck(&sc_connection_time, pd_connection_time); | ||
| 244 | sc_connection_time = | ||
| 245 | mp_set_subcheck_state(sc_connection_time, mp_get_pd_status(pd_connection_time)); | ||
| 246 | |||
| 247 | mp_add_subcheck_to_check(&overall, sc_connection_time); | ||
| 248 | |||
| 217 | if (verbose) { | 249 | if (verbose) { |
| 218 | char *server_host = PQhost(conn); | 250 | char *server_host = PQhost(conn); |
| 219 | int server_version = PQserverVersion(conn); | 251 | int server_version = PQserverVersion(conn); |
| @@ -225,25 +257,86 @@ int main(int argc, char **argv) { | |||
| 225 | PSQL_SERVER_VERSION3(server_version), PQprotocolVersion(conn), PQbackendPID(conn)); | 257 | PSQL_SERVER_VERSION3(server_version), PQprotocolVersion(conn), PQbackendPID(conn)); |
| 226 | } | 258 | } |
| 227 | 259 | ||
| 228 | printf(_(" %s - database %s (%f sec.)|%s\n"), state_text(status), config.dbName, elapsed_time, | ||
| 229 | fperfdata("time", elapsed_time, "s", (config.twarn > 0.0), config.twarn, | ||
| 230 | (config.tcrit > 0.0), config.tcrit, true, 0, false, 0)); | ||
| 231 | |||
| 232 | mp_state_enum query_status = STATE_UNKNOWN; | ||
| 233 | if (config.pgquery) { | 260 | if (config.pgquery) { |
| 234 | query_status = do_query(conn, config.pgquery, config.pgqueryname, config.qthresholds, | 261 | mp_subcheck sc_query = mp_subcheck_init(); |
| 235 | config.query_warning, config.query_critical); | 262 | sc_query = mp_set_subcheck_default_state(sc_query, STATE_UNKNOWN); |
| 263 | if (config.pgqueryname) { | ||
| 264 | xasprintf(&sc_query.output, "query '%s'", config.pgqueryname); | ||
| 265 | } else { | ||
| 266 | xasprintf(&sc_query.output, "query '%s'", config.pgquery); | ||
| 267 | } | ||
| 268 | |||
| 269 | do_query_wrapper query_result = do_query(conn, config.pgquery); | ||
| 270 | |||
| 271 | switch (query_result.error_code) { | ||
| 272 | case QUERY_OK: { | ||
| 273 | // Query was succesful and there is a numerical result | ||
| 274 | sc_query = mp_set_subcheck_state(sc_query, STATE_OK); | ||
| 275 | xasprintf(&sc_query.output, "%s succeeded", sc_query.output); | ||
| 276 | |||
| 277 | mp_perfdata pd_query = perfdata_init(); | ||
| 278 | pd_query = mp_set_pd_value(pd_query, query_result.numerical_result); | ||
| 279 | pd_query = mp_pd_set_thresholds(pd_query, config.qthresholds); | ||
| 280 | pd_query.label = "query"; | ||
| 281 | |||
| 282 | mp_subcheck sc_query_compare = mp_subcheck_init(); | ||
| 283 | mp_state_enum query_compare_state = mp_get_pd_status(pd_query); | ||
| 284 | |||
| 285 | sc_query_compare = mp_set_subcheck_state(sc_query_compare, query_compare_state); | ||
| 286 | mp_add_perfdata_to_subcheck(&sc_query_compare, pd_query); | ||
| 287 | |||
| 288 | if (query_compare_state == STATE_OK) { | ||
| 289 | xasprintf(&sc_query_compare.output, "query result '%f' is withing thresholds", | ||
| 290 | query_result.numerical_result); | ||
| 291 | } else { | ||
| 292 | xasprintf(&sc_query_compare.output, "query result '%f' is violating thresholds", | ||
| 293 | query_result.numerical_result); | ||
| 294 | } | ||
| 295 | mp_add_subcheck_to_check(&overall, sc_query_compare); | ||
| 296 | |||
| 297 | } break; | ||
| 298 | case ERROR_WITH_QUERY: | ||
| 299 | xasprintf(&sc_query.output, "%s - Error with query: %s", sc_query.output, | ||
| 300 | PQerrorMessage(conn)); | ||
| 301 | sc_query = mp_set_subcheck_state(sc_query, STATE_CRITICAL); | ||
| 302 | break; | ||
| 303 | case NO_ROWS_RETURNED: | ||
| 304 | xasprintf(&sc_query.output, "%s - no rows were returned by the query", sc_query.output); | ||
| 305 | sc_query = mp_set_subcheck_state(sc_query, STATE_WARNING); | ||
| 306 | break; | ||
| 307 | case NO_COLUMNS_RETURNED: | ||
| 308 | xasprintf(&sc_query.output, "%s - no columns were returned by the query", | ||
| 309 | sc_query.output); | ||
| 310 | sc_query = mp_set_subcheck_state(sc_query, STATE_WARNING); | ||
| 311 | break; | ||
| 312 | case NO_DATA_RETURNED: | ||
| 313 | xasprintf(&sc_query.output, "%s - no data was returned by the query", sc_query.output); | ||
| 314 | sc_query = mp_set_subcheck_state(sc_query, STATE_WARNING); | ||
| 315 | break; | ||
| 316 | case RESULT_IS_NOT_NUMERIC: | ||
| 317 | xasprintf(&sc_query.output, "%s - result of the query is not numeric", sc_query.output); | ||
| 318 | sc_query = mp_set_subcheck_state(sc_query, STATE_CRITICAL); | ||
| 319 | break; | ||
| 320 | }; | ||
| 321 | |||
| 322 | mp_add_subcheck_to_check(&overall, sc_query); | ||
| 236 | } | 323 | } |
| 237 | 324 | ||
| 238 | if (verbose) { | 325 | if (verbose) { |
| 239 | printf("Closing connection\n"); | 326 | printf("Closing connection\n"); |
| 240 | } | 327 | } |
| 241 | PQfinish(conn); | 328 | PQfinish(conn); |
| 242 | return (config.pgquery && query_status > status) ? query_status : status; | 329 | |
| 330 | mp_exit(overall); | ||
| 243 | } | 331 | } |
| 244 | 332 | ||
| 245 | /* process command-line arguments */ | 333 | /* process command-line arguments */ |
| 246 | check_pgsql_config_wrapper process_arguments(int argc, char **argv) { | 334 | static check_pgsql_config_wrapper process_arguments(int argc, char **argv) { |
| 335 | |||
| 336 | enum { | ||
| 337 | OPTID_QUERYNAME = CHAR_MAX + 1, | ||
| 338 | }; | ||
| 339 | |||
| 247 | static struct option longopts[] = {{"help", no_argument, 0, 'h'}, | 340 | static struct option longopts[] = {{"help", no_argument, 0, 'h'}, |
| 248 | {"version", no_argument, 0, 'V'}, | 341 | {"version", no_argument, 0, 'V'}, |
| 249 | {"timeout", required_argument, 0, 't'}, | 342 | {"timeout", required_argument, 0, 't'}, |
| @@ -293,26 +386,40 @@ check_pgsql_config_wrapper process_arguments(int argc, char **argv) { | |||
| 293 | timeout_interval = atoi(optarg); | 386 | timeout_interval = atoi(optarg); |
| 294 | } | 387 | } |
| 295 | break; | 388 | break; |
| 296 | case 'c': /* critical time threshold */ | 389 | case 'c': /* critical time threshold */ { |
| 297 | if (!is_nonnegative(optarg)) { | 390 | mp_range_parsed tmp = mp_parse_range_string(optarg); |
| 298 | usage2(_("Critical threshold must be a positive integer"), optarg); | 391 | if (tmp.error != MP_PARSING_SUCCES) { |
| 299 | } else { | 392 | die(STATE_UNKNOWN, "failed to parse critical time threshold"); |
| 300 | result.config.tcrit = strtod(optarg, NULL); | ||
| 301 | } | 393 | } |
| 302 | break; | 394 | result.config.time_thresholds = |
| 303 | case 'w': /* warning time threshold */ | 395 | mp_thresholds_set_crit(result.config.time_thresholds, tmp.range); |
| 304 | if (!is_nonnegative(optarg)) { | 396 | } break; |
| 305 | usage2(_("Warning threshold must be a positive integer"), optarg); | 397 | case 'w': /* warning time threshold */ { |
| 306 | } else { | 398 | mp_range_parsed tmp = mp_parse_range_string(optarg); |
| 307 | result.config.twarn = strtod(optarg, NULL); | 399 | if (tmp.error != MP_PARSING_SUCCES) { |
| 400 | die(STATE_UNKNOWN, "failed to parse warning time threshold"); | ||
| 308 | } | 401 | } |
| 309 | break; | 402 | result.config.time_thresholds = |
| 310 | case 'C': /* critical query threshold */ | 403 | mp_thresholds_set_warn(result.config.time_thresholds, tmp.range); |
| 311 | result.config.query_critical = optarg; | 404 | } break; |
| 312 | break; | 405 | case 'C': /* critical query threshold */ { |
| 313 | case 'W': /* warning query threshold */ | 406 | mp_range_parsed tmp = mp_parse_range_string(optarg); |
| 314 | result.config.query_warning = optarg; | 407 | if (tmp.error != MP_PARSING_SUCCES) { |
| 315 | break; | 408 | die(STATE_UNKNOWN, "failed to parse critical query threshold"); |
| 409 | } | ||
| 410 | |||
| 411 | result.config.qthresholds = | ||
| 412 | mp_thresholds_set_crit(result.config.qthresholds, tmp.range); | ||
| 413 | |||
| 414 | } break; | ||
| 415 | case 'W': /* warning query threshold */ { | ||
| 416 | mp_range_parsed tmp = mp_parse_range_string(optarg); | ||
| 417 | if (tmp.error != MP_PARSING_SUCCES) { | ||
| 418 | die(STATE_UNKNOWN, "failed to parse warning query threshold"); | ||
| 419 | } | ||
| 420 | result.config.qthresholds = | ||
| 421 | mp_thresholds_set_warn(result.config.qthresholds, tmp.range); | ||
| 422 | } break; | ||
| 316 | case 'H': /* host */ | 423 | case 'H': /* host */ |
| 317 | if ((*optarg != '/') && (!is_host(optarg))) { | 424 | if ((*optarg != '/') && (!is_host(optarg))) { |
| 318 | usage2(_("Invalid hostname/address"), optarg); | 425 | usage2(_("Invalid hostname/address"), optarg); |
| @@ -363,9 +470,6 @@ check_pgsql_config_wrapper process_arguments(int argc, char **argv) { | |||
| 363 | } | 470 | } |
| 364 | } | 471 | } |
| 365 | 472 | ||
| 366 | set_thresholds(&result.config.qthresholds, result.config.query_warning, | ||
| 367 | result.config.query_critical); | ||
| 368 | |||
| 369 | return result; | 473 | return result; |
| 370 | } | 474 | } |
| 371 | 475 | ||
| @@ -393,7 +497,7 @@ should be added.</para> | |||
| 393 | -@@ | 497 | -@@ |
| 394 | ******************************************************************************/ | 498 | ******************************************************************************/ |
| 395 | 499 | ||
| 396 | bool is_pg_logname(char *username) { | 500 | static bool is_pg_logname(char *username) { |
| 397 | if (strlen(username) > NAMEDATALEN - 1) { | 501 | if (strlen(username) > NAMEDATALEN - 1) { |
| 398 | return (false); | 502 | return (false); |
| 399 | } | 503 | } |
| @@ -447,9 +551,9 @@ void print_help(void) { | |||
| 447 | printf(" %s\n", "--queryname=STRING"); | 551 | printf(" %s\n", "--queryname=STRING"); |
| 448 | printf(" %s\n", _("A name for the query, this string is used instead of the query")); | 552 | printf(" %s\n", _("A name for the query, this string is used instead of the query")); |
| 449 | printf(" %s\n", _("in the long output of the plugin")); | 553 | printf(" %s\n", _("in the long output of the plugin")); |
| 450 | printf(" %s\n", "-W, --query-warning=RANGE"); | 554 | printf(" %s\n", "-W, --query_warning=RANGE"); |
| 451 | printf(" %s\n", _("SQL query value to result in warning status (double)")); | 555 | printf(" %s\n", _("SQL query value to result in warning status (double)")); |
| 452 | printf(" %s\n", "-C, --query-critical=RANGE"); | 556 | printf(" %s\n", "-C, --query_critical=RANGE"); |
| 453 | printf(" %s\n", _("SQL query value to result in critical status (double)")); | 557 | printf(" %s\n", _("SQL query value to result in critical status (double)")); |
| 454 | 558 | ||
| 455 | printf(UT_VERBOSE); | 559 | printf(UT_VERBOSE); |
| @@ -509,33 +613,44 @@ void print_usage(void) { | |||
| 509 | "[-q <query>] [-C <critical query range>] [-W <warning query range>]\n"); | 613 | "[-q <query>] [-C <critical query range>] [-W <warning query range>]\n"); |
| 510 | } | 614 | } |
| 511 | 615 | ||
| 512 | mp_state_enum do_query(PGconn *conn, char *query, const char pgqueryname[], thresholds *qthresholds, | 616 | static do_query_wrapper do_query(PGconn *conn, char *query) { |
| 513 | char *query_warning, char *query_critical) { | ||
| 514 | if (verbose) { | 617 | if (verbose) { |
| 515 | printf("Executing SQL query \"%s\".\n", query); | 618 | printf("Executing SQL query \"%s\".\n", query); |
| 516 | } | 619 | } |
| 517 | PGresult *res = PQexec(conn, query); | 620 | PGresult *res = PQexec(conn, query); |
| 518 | 621 | ||
| 622 | do_query_wrapper result = { | ||
| 623 | .error_code = QUERY_OK, | ||
| 624 | }; | ||
| 625 | |||
| 519 | if (PGRES_TUPLES_OK != PQresultStatus(res)) { | 626 | if (PGRES_TUPLES_OK != PQresultStatus(res)) { |
| 520 | printf(_("QUERY %s - %s: %s.\n"), _("CRITICAL"), _("Error with query"), | 627 | // TODO |
| 521 | PQerrorMessage(conn)); | 628 | // printf(_("QUERY %s - %s: %s.\n"), _("CRITICAL"), _("Error with query"), |
| 522 | return STATE_CRITICAL; | 629 | // PQerrorMessage(conn)); |
| 630 | result.error_code = ERROR_WITH_QUERY; | ||
| 631 | return result; | ||
| 523 | } | 632 | } |
| 524 | 633 | ||
| 525 | if (PQntuples(res) < 1) { | 634 | if (PQntuples(res) < 1) { |
| 526 | printf("QUERY %s - %s.\n", _("WARNING"), _("No rows returned")); | 635 | // TODO |
| 527 | return STATE_WARNING; | 636 | // printf("QUERY %s - %s.\n", _("WARNING"), _("No rows returned")); |
| 637 | result.error_code = NO_ROWS_RETURNED; | ||
| 638 | return result; | ||
| 528 | } | 639 | } |
| 529 | 640 | ||
| 530 | if (PQnfields(res) < 1) { | 641 | if (PQnfields(res) < 1) { |
| 531 | printf("QUERY %s - %s.\n", _("WARNING"), _("No columns returned")); | 642 | // TODO |
| 532 | return STATE_WARNING; | 643 | // printf("QUERY %s - %s.\n", _("WARNING"), _("No columns returned")); |
| 644 | result.error_code = NO_COLUMNS_RETURNED; | ||
| 645 | return result; | ||
| 533 | } | 646 | } |
| 534 | 647 | ||
| 535 | char *val_str = PQgetvalue(res, 0, 0); | 648 | char *val_str = PQgetvalue(res, 0, 0); |
| 536 | if (!val_str) { | 649 | if (!val_str) { |
| 537 | printf("QUERY %s - %s.\n", _("CRITICAL"), _("No data returned")); | 650 | // TODO |
| 538 | return STATE_CRITICAL; | 651 | // printf("QUERY %s - %s.\n", _("CRITICAL"), _("No data returned")); |
| 652 | result.error_code = NO_DATA_RETURNED; | ||
| 653 | return result; | ||
| 539 | } | 654 | } |
| 540 | 655 | ||
| 541 | char *endptr = NULL; | 656 | char *endptr = NULL; |
| @@ -545,8 +660,10 @@ mp_state_enum do_query(PGconn *conn, char *query, const char pgqueryname[], thre | |||
| 545 | } | 660 | } |
| 546 | 661 | ||
| 547 | if (endptr == val_str) { | 662 | if (endptr == val_str) { |
| 548 | printf("QUERY %s - %s: %s\n", _("CRITICAL"), _("Is not a numeric"), val_str); | 663 | // TODO |
| 549 | return STATE_CRITICAL; | 664 | // printf("QUERY %s - %s: %s\n", _("CRITICAL"), _("Is not a numeric"), val_str); |
| 665 | result.error_code = RESULT_IS_NOT_NUMERIC; | ||
| 666 | return result; | ||
| 550 | } | 667 | } |
| 551 | 668 | ||
| 552 | if ((endptr != NULL) && (*endptr != '\0')) { | 669 | if ((endptr != NULL) && (*endptr != '\0')) { |
| @@ -555,24 +672,22 @@ mp_state_enum do_query(PGconn *conn, char *query, const char pgqueryname[], thre | |||
| 555 | } | 672 | } |
| 556 | } | 673 | } |
| 557 | 674 | ||
| 558 | mp_state_enum my_status = get_status(value, qthresholds); | 675 | result.numerical_result = value; |
| 559 | printf("QUERY %s - ", (my_status == STATE_OK) ? _("OK") | ||
| 560 | : (my_status == STATE_WARNING) ? _("WARNING") | ||
| 561 | : (my_status == STATE_CRITICAL) ? _("CRITICAL") | ||
| 562 | : _("UNKNOWN")); | ||
| 563 | if (pgqueryname) { | ||
| 564 | printf(_("%s returned %f"), pgqueryname, value); | ||
| 565 | } else { | ||
| 566 | printf(_("'%s' returned %f"), query, value); | ||
| 567 | } | ||
| 568 | 676 | ||
| 569 | printf("|query=%f;%s;%s;;\n", value, query_warning ? query_warning : "", | 677 | // if (pgqueryname) { |
| 570 | query_critical ? query_critical : ""); | 678 | // printf(_("%s returned %f"), pgqueryname, value); |
| 571 | if (PQnfields(res) > 1) { | 679 | // } else { |
| 572 | char *extra_info = PQgetvalue(res, 0, 1); | 680 | // printf(_("'%s' returned %f"), query, value); |
| 573 | if (extra_info != NULL) { | 681 | // } |
| 574 | printf("Extra Info: %s\n", extra_info); | 682 | |
| 575 | } | 683 | // printf("|query=%f;%s;%s;;\n", value, query_warning ? query_warning : "", |
| 576 | } | 684 | // query_critical ? query_critical : ""); |
| 577 | return my_status; | 685 | // if (PQnfields(res) > 1) { |
| 686 | // char *extra_info = PQgetvalue(res, 0, 1); | ||
| 687 | // if (extra_info != NULL) { | ||
| 688 | // printf("Extra Info: %s\n", extra_info); | ||
| 689 | // } | ||
| 690 | // } | ||
| 691 | |||
| 692 | return result; | ||
| 578 | } | 693 | } |
