From: Matthias Eble Date: Mon, 1 Jun 2009 20:08:07 +0000 (+0200) Subject: Added verbose output to check_pgsql (#2799281 - Jun Kuriyama) X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=28e1b836b1b06a2a6c664e96ffe96213a96f8ddd;p=nagiosplug.git Added verbose output to check_pgsql (#2799281 - Jun Kuriyama) check_pgsql displayed the -v flag in help output, but didn't accept the verbosity argument. Added -v and basic verbose output. --- diff --git a/plugins/check_pgsql.c b/plugins/check_pgsql.c index abe721b..925751b 100644 --- a/plugins/check_pgsql.c +++ b/plugins/check_pgsql.c @@ -67,6 +67,7 @@ char *pguser = NULL; char *pgpasswd = NULL; double twarn = (double)DEFAULT_WARN; double tcrit = (double)DEFAULT_CRIT; +int verbose = 0; PGconn *conn; /*PGresult *res;*/ @@ -151,6 +152,8 @@ main (int argc, char **argv) if (process_arguments (argc, argv) == ERROR) usage4 (_("Could not parse arguments")); + if (verbose > 2) + printf("Arguments initialized\n"); /* Set signal handling and alarm */ if (signal (SIGALRM, timeout_alarm_handler) == SIG_ERR) { @@ -158,14 +161,24 @@ main (int argc, char **argv) } alarm (timeout_interval); + if (verbose) + printf("Connecting to database:\n DB: %s\n User: %s\n Host: %s\n Port: %d\n", dbName, + (pguser != NULL) ? pguser : "unspecified", + (pghost != NULL) ? pghost : "unspecified", + (pgport != NULL) ? atoi(pgport) : DEFAULT_PORT); + /* make a connection to the database */ time (&start_time); conn = PQsetdbLogin (pghost, pgport, pgoptions, pgtty, dbName, pguser, pgpasswd); time (&end_time); elapsed_time = (int) (end_time - start_time); + if (verbose) + printf("Time elapsed: %d\n", elapsed_time); /* check to see that the backend connection was successfully made */ + if (verbose) + printf("Verifying connection\n"); if (PQstatus (conn) == CONNECTION_BAD) { printf (_("CRITICAL - no connection to '%s' (%s).\n"), dbName, PQerrorMessage (conn)); @@ -181,6 +194,8 @@ main (int argc, char **argv) else { status = STATE_OK; } + if (verbose) + printf("Closing connection\n"); PQfinish (conn); printf (_(" %s - database %s (%d sec.)|%s\n"), state_text(status), dbName, elapsed_time, @@ -210,11 +225,12 @@ process_arguments (int argc, char **argv) {"authorization", required_argument, 0, 'a'}, {"port", required_argument, 0, 'P'}, {"database", required_argument, 0, 'd'}, + {"verbose", no_argument, 0, 'v'}, {0, 0, 0, 0} }; while (1) { - c = getopt_long (argc, argv, "hVt:c:w:H:P:d:l:p:a:", + c = getopt_long (argc, argv, "hVt:c:w:H:P:d:l:p:a:v", longopts, &option); if (c == EOF) @@ -275,6 +291,9 @@ process_arguments (int argc, char **argv) case 'a': pgpasswd = optarg; break; + case 'v': + verbose++; + break; } }