summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 5e4e3fe)
raw | patch | inline | side by side (parent: 5e4e3fe)
author | Sebastian Harl <sh@teamix.net> | |
Thu, 7 Apr 2011 15:59:24 +0000 (17:59 +0200) | ||
committer | Sebastian Harl <sh@teamix.net> | |
Thu, 7 Apr 2011 15:59:24 +0000 (17:59 +0200) |
The -W and -C options are used for that. The plugin return value is determined
by the worst check result.
by the worst check result.
plugins/check_dbi.c | patch | blob | history |
diff --git a/plugins/check_dbi.c b/plugins/check_dbi.c
index 47b239a9314786a61de4e4d1051a14649dfa45ba..d4ac4e3223b6fd47c4b7c07357ffaeb60633f53f 100644 (file)
--- a/plugins/check_dbi.c
+++ b/plugins/check_dbi.c
char *critical_range = NULL;
thresholds *query_thresholds = NULL;
+char *conntime_warning_range = NULL;
+char *conntime_critical_range = NULL;
+thresholds *conntime_thresholds = NULL;
+
char *np_dbi_driver = NULL;
driver_option_t *np_dbi_options = NULL;
int np_dbi_options_num = 0;
int
main (int argc, char **argv)
{
+ int conntime_status = STATE_UNKNOWN;
int status = STATE_UNKNOWN;
+ int exit_status = STATE_UNKNOWN;
+
dbi_driver driver;
dbi_conn conn;
if (verbose)
printf("Time elapsed: %f\n", elapsed_time);
+ conntime_status = get_status (elapsed_time, conntime_thresholds);
+
/* select a database */
if (np_dbi_database) {
if (verbose > 1)
printf("Closing connection\n");
dbi_conn_close (conn);
- printf ("%s - connection time: %fs, '%s' returned %f",
- state_text (status), elapsed_time, np_dbi_query, query_val);
- printf (" | conntime=%fs;;;0 query=%f;%s;%s;0\n", elapsed_time, query_val,
- warning_range ? warning_range : "", critical_range ? critical_range : "");
- return status;
+ /* 'conntime_status' is worse than 'status' (but not UNKOWN) */
+ if (((conntime_status < STATE_UNKNOWN) && (conntime_status > status))
+ /* 'status' is UNKNOWN and 'conntime_status' is not OK */
+ || ((status >= STATE_UNKNOWN) && (conntime_status != STATE_OK)))
+ exit_status = conntime_status;
+ else
+ exit_status = status;
+
+ printf ("%s - %s: connection time: %fs, %s: '%s' returned %f",
+ state_text (exit_status),
+ state_text (conntime_status), elapsed_time,
+ state_text (status), np_dbi_query, query_val);
+ printf (" | conntime=%fs;%s;%s;0 query=%f;%s;%s;0\n", elapsed_time,
+ conntime_warning_range ? conntime_warning_range : "",
+ conntime_critical_range ? conntime_critical_range : "",
+ query_val, warning_range ? warning_range : "", critical_range ? critical_range : "");
+ return exit_status;
}
/* process command-line arguments */
static struct option longopts[] = {
STD_LONG_OPTS,
+ {"conntime-warning", required_argument, 0, 'W'},
+ {"conntime-critical", required_argument, 0, 'C'},
+
{"driver", required_argument, 0, 'd'},
{"option", required_argument, 0, 'o'},
{"query", required_argument, 0, 'q'},
};
while (1) {
- c = getopt_long (argc, argv, "Vvht:c:w:H:d:o:q:D:",
+ c = getopt_long (argc, argv, "Vvht:c:w:H:W:C:d:o:q:D:",
longopts, &option);
if (c == EOF)
else
timeout_interval = atoi (optarg);
+ case 'C': /* critical conntime range */
+ conntime_critical_range = optarg;
+ break;
+ case 'W': /* warning conntime range */
+ conntime_warning_range = optarg;
+ break;
+
case 'H': /* host */
if (!is_host (optarg))
usage2 (_("Invalid hostname/address"), optarg);
}
set_thresholds (&query_thresholds, warning_range, critical_range);
+ set_thresholds (&conntime_thresholds, conntime_warning_range, conntime_critical_range);
return validate_arguments ();
}
printf ("\n");
printf (UT_WARN_CRIT_RANGE);
+ printf (" %s\n", "-W, --conntime-warning=RANGE");
+ printf (" %s\n", _("Connection time warning range"));
+ printf (" %s\n", "-C, --conntime-critical=RANGE");
+ printf (" %s\n", _("Connection time critical range"));
+ printf ("\n");
printf (UT_TIMEOUT, DEFAULT_SOCKET_TIMEOUT);
{
printf ("%s\n", _("Usage:"));
printf ("%s -d <DBI driver> [-o <DBI driver option> [...]] -q <SQL query>\n", progname);
- printf (" [-H <host>] [-c <critical value>] [-w <warning value>]\n");
+ printf (" [-H <host>] [-c <critical range>] [-w <warning range>]\n");
+ printf (" [-C <critical conntime range>] [-W <warning conntime range>]\n");
}
double