diff options
author | Matthias Eble <psychotrahe@gmx.de> | 2009-06-01 20:08:07 (GMT) |
---|---|---|
committer | Matthias Eble <psychotrahe@gmx.de> | 2009-06-01 20:08:07 (GMT) |
commit | 28e1b836b1b06a2a6c664e96ffe96213a96f8ddd (patch) | |
tree | 4865446825a5d27a28b53070f82a022d1dd7d05f | |
parent | 843c652768e4e971dbc558b026b60ccf854d837a (diff) | |
download | monitoring-plugins-28e1b836b1b06a2a6c664e96ffe96213a96f8ddd.tar.gz |
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.
-rw-r--r-- | plugins/check_pgsql.c | 21 |
1 files changed, 20 insertions, 1 deletions
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; | |||
67 | char *pgpasswd = NULL; | 67 | char *pgpasswd = NULL; |
68 | double twarn = (double)DEFAULT_WARN; | 68 | double twarn = (double)DEFAULT_WARN; |
69 | double tcrit = (double)DEFAULT_CRIT; | 69 | double tcrit = (double)DEFAULT_CRIT; |
70 | int verbose = 0; | ||
70 | 71 | ||
71 | PGconn *conn; | 72 | PGconn *conn; |
72 | /*PGresult *res;*/ | 73 | /*PGresult *res;*/ |
@@ -151,6 +152,8 @@ main (int argc, char **argv) | |||
151 | 152 | ||
152 | if (process_arguments (argc, argv) == ERROR) | 153 | if (process_arguments (argc, argv) == ERROR) |
153 | usage4 (_("Could not parse arguments")); | 154 | usage4 (_("Could not parse arguments")); |
155 | if (verbose > 2) | ||
156 | printf("Arguments initialized\n"); | ||
154 | 157 | ||
155 | /* Set signal handling and alarm */ | 158 | /* Set signal handling and alarm */ |
156 | if (signal (SIGALRM, timeout_alarm_handler) == SIG_ERR) { | 159 | if (signal (SIGALRM, timeout_alarm_handler) == SIG_ERR) { |
@@ -158,14 +161,24 @@ main (int argc, char **argv) | |||
158 | } | 161 | } |
159 | alarm (timeout_interval); | 162 | alarm (timeout_interval); |
160 | 163 | ||
164 | if (verbose) | ||
165 | printf("Connecting to database:\n DB: %s\n User: %s\n Host: %s\n Port: %d\n", dbName, | ||
166 | (pguser != NULL) ? pguser : "unspecified", | ||
167 | (pghost != NULL) ? pghost : "unspecified", | ||
168 | (pgport != NULL) ? atoi(pgport) : DEFAULT_PORT); | ||
169 | |||
161 | /* make a connection to the database */ | 170 | /* make a connection to the database */ |
162 | time (&start_time); | 171 | time (&start_time); |
163 | conn = | 172 | conn = |
164 | PQsetdbLogin (pghost, pgport, pgoptions, pgtty, dbName, pguser, pgpasswd); | 173 | PQsetdbLogin (pghost, pgport, pgoptions, pgtty, dbName, pguser, pgpasswd); |
165 | time (&end_time); | 174 | time (&end_time); |
166 | elapsed_time = (int) (end_time - start_time); | 175 | elapsed_time = (int) (end_time - start_time); |
176 | if (verbose) | ||
177 | printf("Time elapsed: %d\n", elapsed_time); | ||
167 | 178 | ||
168 | /* check to see that the backend connection was successfully made */ | 179 | /* check to see that the backend connection was successfully made */ |
180 | if (verbose) | ||
181 | printf("Verifying connection\n"); | ||
169 | if (PQstatus (conn) == CONNECTION_BAD) { | 182 | if (PQstatus (conn) == CONNECTION_BAD) { |
170 | printf (_("CRITICAL - no connection to '%s' (%s).\n"), | 183 | printf (_("CRITICAL - no connection to '%s' (%s).\n"), |
171 | dbName, PQerrorMessage (conn)); | 184 | dbName, PQerrorMessage (conn)); |
@@ -181,6 +194,8 @@ main (int argc, char **argv) | |||
181 | else { | 194 | else { |
182 | status = STATE_OK; | 195 | status = STATE_OK; |
183 | } | 196 | } |
197 | if (verbose) | ||
198 | printf("Closing connection\n"); | ||
184 | PQfinish (conn); | 199 | PQfinish (conn); |
185 | printf (_(" %s - database %s (%d sec.)|%s\n"), | 200 | printf (_(" %s - database %s (%d sec.)|%s\n"), |
186 | state_text(status), dbName, elapsed_time, | 201 | state_text(status), dbName, elapsed_time, |
@@ -210,11 +225,12 @@ process_arguments (int argc, char **argv) | |||
210 | {"authorization", required_argument, 0, 'a'}, | 225 | {"authorization", required_argument, 0, 'a'}, |
211 | {"port", required_argument, 0, 'P'}, | 226 | {"port", required_argument, 0, 'P'}, |
212 | {"database", required_argument, 0, 'd'}, | 227 | {"database", required_argument, 0, 'd'}, |
228 | {"verbose", no_argument, 0, 'v'}, | ||
213 | {0, 0, 0, 0} | 229 | {0, 0, 0, 0} |
214 | }; | 230 | }; |
215 | 231 | ||
216 | while (1) { | 232 | while (1) { |
217 | c = getopt_long (argc, argv, "hVt:c:w:H:P:d:l:p:a:", | 233 | c = getopt_long (argc, argv, "hVt:c:w:H:P:d:l:p:a:v", |
218 | longopts, &option); | 234 | longopts, &option); |
219 | 235 | ||
220 | if (c == EOF) | 236 | if (c == EOF) |
@@ -275,6 +291,9 @@ process_arguments (int argc, char **argv) | |||
275 | case 'a': | 291 | case 'a': |
276 | pgpasswd = optarg; | 292 | pgpasswd = optarg; |
277 | break; | 293 | break; |
294 | case 'v': | ||
295 | verbose++; | ||
296 | break; | ||
278 | } | 297 | } |
279 | } | 298 | } |
280 | 299 | ||