diff options
| author | Sebastian Harl <sh@teamix.net> | 2011-04-07 17:59:24 +0200 |
|---|---|---|
| committer | Sebastian Harl <sh@teamix.net> | 2012-06-06 14:10:55 +0200 |
| commit | e7dfcd4429b54bd98bac724665d7b5e6e30a7532 (patch) | |
| tree | 05b12268924339a92d203b1584e8f0169f2f8095 /plugins | |
| parent | 07768fa89561a4e55391634942e696a167bc6bbf (diff) | |
| download | monitoring-plugins-e7dfcd4429b54bd98bac724665d7b5e6e30a7532.tar.gz | |
check_dbi: Added threshold ranges for the connection time.
The -W and -C options are used for that. The plugin return value is determined
by the worst check result.
Diffstat (limited to 'plugins')
| -rw-r--r-- | plugins/check_dbi.c | 52 |
1 files changed, 45 insertions, 7 deletions
diff --git a/plugins/check_dbi.c b/plugins/check_dbi.c index 47b239a9..d4ac4e32 100644 --- a/plugins/check_dbi.c +++ b/plugins/check_dbi.c | |||
| @@ -54,6 +54,10 @@ char *warning_range = NULL; | |||
| 54 | char *critical_range = NULL; | 54 | char *critical_range = NULL; |
| 55 | thresholds *query_thresholds = NULL; | 55 | thresholds *query_thresholds = NULL; |
| 56 | 56 | ||
| 57 | char *conntime_warning_range = NULL; | ||
| 58 | char *conntime_critical_range = NULL; | ||
| 59 | thresholds *conntime_thresholds = NULL; | ||
| 60 | |||
| 57 | char *np_dbi_driver = NULL; | 61 | char *np_dbi_driver = NULL; |
| 58 | driver_option_t *np_dbi_options = NULL; | 62 | driver_option_t *np_dbi_options = NULL; |
| 59 | int np_dbi_options_num = 0; | 63 | int np_dbi_options_num = 0; |
| @@ -72,8 +76,11 @@ int do_query (dbi_conn, double *); | |||
| 72 | int | 76 | int |
| 73 | main (int argc, char **argv) | 77 | main (int argc, char **argv) |
| 74 | { | 78 | { |
| 79 | int conntime_status = STATE_UNKNOWN; | ||
| 75 | int status = STATE_UNKNOWN; | 80 | int status = STATE_UNKNOWN; |
| 76 | 81 | ||
| 82 | int exit_status = STATE_UNKNOWN; | ||
| 83 | |||
| 77 | dbi_driver driver; | 84 | dbi_driver driver; |
| 78 | dbi_conn conn; | 85 | dbi_conn conn; |
| 79 | 86 | ||
| @@ -193,6 +200,8 @@ main (int argc, char **argv) | |||
| 193 | if (verbose) | 200 | if (verbose) |
| 194 | printf("Time elapsed: %f\n", elapsed_time); | 201 | printf("Time elapsed: %f\n", elapsed_time); |
| 195 | 202 | ||
| 203 | conntime_status = get_status (elapsed_time, conntime_thresholds); | ||
| 204 | |||
| 196 | /* select a database */ | 205 | /* select a database */ |
| 197 | if (np_dbi_database) { | 206 | if (np_dbi_database) { |
| 198 | if (verbose > 1) | 207 | if (verbose > 1) |
| @@ -217,11 +226,23 @@ main (int argc, char **argv) | |||
| 217 | printf("Closing connection\n"); | 226 | printf("Closing connection\n"); |
| 218 | dbi_conn_close (conn); | 227 | dbi_conn_close (conn); |
| 219 | 228 | ||
| 220 | printf ("%s - connection time: %fs, '%s' returned %f", | 229 | /* 'conntime_status' is worse than 'status' (but not UNKOWN) */ |
| 221 | state_text (status), elapsed_time, np_dbi_query, query_val); | 230 | if (((conntime_status < STATE_UNKNOWN) && (conntime_status > status)) |
| 222 | printf (" | conntime=%fs;;;0 query=%f;%s;%s;0\n", elapsed_time, query_val, | 231 | /* 'status' is UNKNOWN and 'conntime_status' is not OK */ |
| 223 | warning_range ? warning_range : "", critical_range ? critical_range : ""); | 232 | || ((status >= STATE_UNKNOWN) && (conntime_status != STATE_OK))) |
| 224 | return status; | 233 | exit_status = conntime_status; |
| 234 | else | ||
| 235 | exit_status = status; | ||
| 236 | |||
| 237 | printf ("%s - %s: connection time: %fs, %s: '%s' returned %f", | ||
| 238 | state_text (exit_status), | ||
| 239 | state_text (conntime_status), elapsed_time, | ||
| 240 | state_text (status), np_dbi_query, query_val); | ||
| 241 | printf (" | conntime=%fs;%s;%s;0 query=%f;%s;%s;0\n", elapsed_time, | ||
| 242 | conntime_warning_range ? conntime_warning_range : "", | ||
| 243 | conntime_critical_range ? conntime_critical_range : "", | ||
| 244 | query_val, warning_range ? warning_range : "", critical_range ? critical_range : ""); | ||
| 245 | return exit_status; | ||
| 225 | } | 246 | } |
| 226 | 247 | ||
| 227 | /* process command-line arguments */ | 248 | /* process command-line arguments */ |
| @@ -234,6 +255,9 @@ process_arguments (int argc, char **argv) | |||
| 234 | static struct option longopts[] = { | 255 | static struct option longopts[] = { |
| 235 | STD_LONG_OPTS, | 256 | STD_LONG_OPTS, |
| 236 | 257 | ||
| 258 | {"conntime-warning", required_argument, 0, 'W'}, | ||
| 259 | {"conntime-critical", required_argument, 0, 'C'}, | ||
| 260 | |||
| 237 | {"driver", required_argument, 0, 'd'}, | 261 | {"driver", required_argument, 0, 'd'}, |
| 238 | {"option", required_argument, 0, 'o'}, | 262 | {"option", required_argument, 0, 'o'}, |
| 239 | {"query", required_argument, 0, 'q'}, | 263 | {"query", required_argument, 0, 'q'}, |
| @@ -242,7 +266,7 @@ process_arguments (int argc, char **argv) | |||
| 242 | }; | 266 | }; |
| 243 | 267 | ||
| 244 | while (1) { | 268 | while (1) { |
| 245 | c = getopt_long (argc, argv, "Vvht:c:w:H:d:o:q:D:", | 269 | c = getopt_long (argc, argv, "Vvht:c:w:H:W:C:d:o:q:D:", |
| 246 | longopts, &option); | 270 | longopts, &option); |
| 247 | 271 | ||
| 248 | if (c == EOF) | 272 | if (c == EOF) |
| @@ -270,6 +294,13 @@ process_arguments (int argc, char **argv) | |||
| 270 | else | 294 | else |
| 271 | timeout_interval = atoi (optarg); | 295 | timeout_interval = atoi (optarg); |
| 272 | 296 | ||
| 297 | case 'C': /* critical conntime range */ | ||
| 298 | conntime_critical_range = optarg; | ||
| 299 | break; | ||
| 300 | case 'W': /* warning conntime range */ | ||
| 301 | conntime_warning_range = optarg; | ||
| 302 | break; | ||
| 303 | |||
| 273 | case 'H': /* host */ | 304 | case 'H': /* host */ |
| 274 | if (!is_host (optarg)) | 305 | if (!is_host (optarg)) |
| 275 | usage2 (_("Invalid hostname/address"), optarg); | 306 | usage2 (_("Invalid hostname/address"), optarg); |
| @@ -323,6 +354,7 @@ process_arguments (int argc, char **argv) | |||
| 323 | } | 354 | } |
| 324 | 355 | ||
| 325 | set_thresholds (&query_thresholds, warning_range, critical_range); | 356 | set_thresholds (&query_thresholds, warning_range, critical_range); |
| 357 | set_thresholds (&conntime_thresholds, conntime_warning_range, conntime_critical_range); | ||
| 326 | 358 | ||
| 327 | return validate_arguments (); | 359 | return validate_arguments (); |
| 328 | } | 360 | } |
| @@ -369,6 +401,11 @@ print_help (void) | |||
| 369 | printf ("\n"); | 401 | printf ("\n"); |
| 370 | 402 | ||
| 371 | printf (UT_WARN_CRIT_RANGE); | 403 | printf (UT_WARN_CRIT_RANGE); |
| 404 | printf (" %s\n", "-W, --conntime-warning=RANGE"); | ||
| 405 | printf (" %s\n", _("Connection time warning range")); | ||
| 406 | printf (" %s\n", "-C, --conntime-critical=RANGE"); | ||
| 407 | printf (" %s\n", _("Connection time critical range")); | ||
| 408 | printf ("\n"); | ||
| 372 | 409 | ||
| 373 | printf (UT_TIMEOUT, DEFAULT_SOCKET_TIMEOUT); | 410 | printf (UT_TIMEOUT, DEFAULT_SOCKET_TIMEOUT); |
| 374 | 411 | ||
| @@ -394,7 +431,8 @@ print_usage (void) | |||
| 394 | { | 431 | { |
| 395 | printf ("%s\n", _("Usage:")); | 432 | printf ("%s\n", _("Usage:")); |
| 396 | printf ("%s -d <DBI driver> [-o <DBI driver option> [...]] -q <SQL query>\n", progname); | 433 | printf ("%s -d <DBI driver> [-o <DBI driver option> [...]] -q <SQL query>\n", progname); |
| 397 | printf (" [-H <host>] [-c <critical value>] [-w <warning value>]\n"); | 434 | printf (" [-H <host>] [-c <critical range>] [-w <warning range>]\n"); |
| 435 | printf (" [-C <critical conntime range>] [-W <warning conntime range>]\n"); | ||
| 398 | } | 436 | } |
| 399 | 437 | ||
| 400 | double | 438 | double |
