summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--plugins/check_dbi.c29
1 files changed, 25 insertions, 4 deletions
diff --git a/plugins/check_dbi.c b/plugins/check_dbi.c
index 39898cfa..1edc2e44 100644
--- a/plugins/check_dbi.c
+++ b/plugins/check_dbi.c
@@ -54,6 +54,7 @@ const char *email = "nagiosplug-devel@lists.sourceforge.net";
54 54
55typedef enum { 55typedef enum {
56 METRIC_CONN_TIME, 56 METRIC_CONN_TIME,
57 METRIC_SERVER_VERSION,
57 METRIC_QUERY_RESULT, 58 METRIC_QUERY_RESULT,
58 METRIC_QUERY_TIME, 59 METRIC_QUERY_TIME,
59} np_dbi_metric_t; 60} np_dbi_metric_t;
@@ -109,6 +110,8 @@ main (int argc, char **argv)
109 dbi_driver driver; 110 dbi_driver driver;
110 dbi_conn conn; 111 dbi_conn conn;
111 112
113 unsigned int server_version;
114
112 struct timeval start_timeval, end_timeval; 115 struct timeval start_timeval, end_timeval;
113 double conn_time = 0.0; 116 double conn_time = 0.0;
114 double query_time = 0.0; 117 double query_time = 0.0;
@@ -219,8 +222,15 @@ main (int argc, char **argv)
219 gettimeofday (&end_timeval, NULL); 222 gettimeofday (&end_timeval, NULL);
220 conn_time = timediff (start_timeval, end_timeval); 223 conn_time = timediff (start_timeval, end_timeval);
221 224
225 server_version = dbi_conn_get_engine_version (conn);
222 if (verbose) 226 if (verbose)
223 printf("Time elapsed: %f\n", conn_time); 227 printf ("Connected to server version %u\n", server_version);
228
229 if (metric == METRIC_SERVER_VERSION)
230 status = get_status (server_version, dbi_thresholds);
231
232 if (verbose)
233 printf ("Time elapsed: %f\n", conn_time);
224 234
225 if (metric == METRIC_CONN_TIME) 235 if (metric == METRIC_CONN_TIME)
226 status = get_status (conn_time, dbi_thresholds); 236 status = get_status (conn_time, dbi_thresholds);
@@ -306,9 +316,12 @@ main (int argc, char **argv)
306 printf (", '%s' returned %f in %fs", np_dbi_query, query_val, query_time); 316 printf (", '%s' returned %f in %fs", np_dbi_query, query_val, query_time);
307 } 317 }
308 318
309 printf (" | conntime=%fs;%s;%s;0;", conn_time, 319 printf (" | conntime=%fs;%s;%s;0; server_version=%u;%s;%s;0;", conn_time,
310 ((metric == METRIC_CONN_TIME) && warning_range) ? warning_range : "", 320 ((metric == METRIC_CONN_TIME) && warning_range) ? warning_range : "",
311 ((metric == METRIC_CONN_TIME) && critical_range) ? critical_range : ""); 321 ((metric == METRIC_CONN_TIME) && critical_range) ? critical_range : "",
322 server_version,
323 ((metric == METRIC_SERVER_VERSION) && warning_range) ? warning_range : "",
324 ((metric == METRIC_SERVER_VERSION) && critical_range) ? critical_range : "");
312 if (np_dbi_query) { 325 if (np_dbi_query) {
313 if (! isnan (query_val)) /* this is also true when -e is used */ 326 if (! isnan (query_val)) /* this is also true when -e is used */
314 printf (" query=%f;%s;%s;;", query_val, 327 printf (" query=%f;%s;%s;;", query_val,
@@ -397,6 +410,8 @@ process_arguments (int argc, char **argv)
397 case 'm': 410 case 'm':
398 if (! strcasecmp (optarg, "CONN_TIME")) 411 if (! strcasecmp (optarg, "CONN_TIME"))
399 metric = METRIC_CONN_TIME; 412 metric = METRIC_CONN_TIME;
413 else if (! strcasecmp (optarg, "SERVER_VERSION"))
414 metric = METRIC_SERVER_VERSION;
400 else if (! strcasecmp (optarg, "QUERY_RESULT")) 415 else if (! strcasecmp (optarg, "QUERY_RESULT"))
401 metric = METRIC_QUERY_RESULT; 416 metric = METRIC_QUERY_RESULT;
402 else if (! strcasecmp (optarg, "QUERY_TIME")) 417 else if (! strcasecmp (optarg, "QUERY_TIME"))
@@ -478,6 +493,7 @@ validate_arguments ()
478 usage ("Must specify a query to execute (metric == QUERY_RESULT)"); 493 usage ("Must specify a query to execute (metric == QUERY_RESULT)");
479 494
480 if ((metric != METRIC_CONN_TIME) 495 if ((metric != METRIC_CONN_TIME)
496 && (metric != METRIC_SERVER_VERSION)
481 && (metric != METRIC_QUERY_RESULT) 497 && (metric != METRIC_QUERY_RESULT)
482 && (metric != METRIC_QUERY_TIME)) 498 && (metric != METRIC_QUERY_TIME))
483 usage ("Invalid metric specified"); 499 usage ("Invalid metric specified");
@@ -577,7 +593,12 @@ print_help (void)
577 printf (" check_dbi -d firebird -o username=user -o password=secret -o dbname=foo \\\n"); 593 printf (" check_dbi -d firebird -o username=user -o password=secret -o dbname=foo \\\n");
578 printf (" -m CONN_TIME -w 0.5 -c 2\n"); 594 printf (" -m CONN_TIME -w 0.5 -c 2\n");
579 printf (" Warning if connecting to the database takes more than half of a second;\n"); 595 printf (" Warning if connecting to the database takes more than half of a second;\n");
580 printf (" critical if it takes more than 2 seconds.\n"); 596 printf (" critical if it takes more than 2 seconds.\n\n");
597
598 printf (" check_dbi -d pgsql -u username=user -m SERVER_VERSION \\\n");
599 printf (" -w 090000:090099 -c 090000:090199\n");
600 printf (" Warn if the PostgreSQL server version is not 9.0.x; critical if the version\n");
601 printf (" is less than 9.x or higher than 9.1.x.\n");
581 602
582 printf (UT_SUPPORT); 603 printf (UT_SUPPORT);
583} 604}