diff options
Diffstat (limited to 'web/attachments/258626-check_mysql_query.c.diff')
-rw-r--r-- | web/attachments/258626-check_mysql_query.c.diff | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/web/attachments/258626-check_mysql_query.c.diff b/web/attachments/258626-check_mysql_query.c.diff new file mode 100644 index 0000000..c06efe0 --- /dev/null +++ b/web/attachments/258626-check_mysql_query.c.diff | |||
@@ -0,0 +1,92 @@ | |||
1 | --- check_mysql_query.c 2007-12-14 11:41:41.000000000 -0800 | ||
2 | +++ check_mysql_query.c 2007-12-14 12:17:56.000000000 -0800 | ||
3 | @@ -59,6 +59,8 @@ | ||
4 | void print_usage (void); | ||
5 | |||
6 | char *sql_query = NULL; | ||
7 | +unsigned int sql_column = 0; | ||
8 | + | ||
9 | int verbose = 0; | ||
10 | thresholds *my_thresholds = NULL; | ||
11 | |||
12 | @@ -74,6 +76,7 @@ | ||
13 | double value; | ||
14 | char *error = NULL; | ||
15 | int status; | ||
16 | + unsigned int numcols; | ||
17 | |||
18 | setlocale (LC_ALL, ""); | ||
19 | bindtextdomain (PACKAGE, LOCALEDIR); | ||
20 | @@ -121,6 +124,12 @@ | ||
21 | mysql_close(&mysql); | ||
22 | die (STATE_WARNING, "QUERY %s: %s\n", _("WARNING"), _("No rows returned")); | ||
23 | } | ||
24 | + | ||
25 | + /* Check number of columns in result */ | ||
26 | + numcols = mysql_num_fields(res); | ||
27 | + if(sql_column >= numcols) { | ||
28 | + die (STATE_WARNING, "QUERY %s: %s\n", _("WARNING"), _("Result has too few columns to satisfy --column")); | ||
29 | + } | ||
30 | |||
31 | /* fetch the first row */ | ||
32 | if ( (row = mysql_fetch_row (res)) == NULL) { | ||
33 | @@ -136,11 +145,11 @@ | ||
34 | /* close the connection */ | ||
35 | mysql_close (&mysql); | ||
36 | |||
37 | - if (! is_numeric(row[0])) { | ||
38 | + if (! is_numeric(row[sql_column])) { | ||
39 | die (STATE_CRITICAL, "QUERY %s: %s - '%s'\n", _("CRITICAL"), _("Is not a numeric"), row[0]); | ||
40 | } | ||
41 | |||
42 | - value = strtod(row[0], NULL); | ||
43 | + value = strtod(row[sql_column], NULL); | ||
44 | |||
45 | if (verbose >= 3) | ||
46 | printf("mysql result: %f\n", value); | ||
47 | @@ -182,6 +191,7 @@ | ||
48 | {"query", required_argument, 0, 'q'}, | ||
49 | {"warning", required_argument, 0, 'w'}, | ||
50 | {"critical", required_argument, 0, 'c'}, | ||
51 | + {"column", required_argument, 0, 'C'}, | ||
52 | {0, 0, 0, 0} | ||
53 | }; | ||
54 | |||
55 | @@ -189,7 +199,7 @@ | ||
56 | return ERROR; | ||
57 | |||
58 | while (1) { | ||
59 | - c = getopt_long (argc, argv, "hvVSP:p:u:d:H:q:w:c:", longopts, &option); | ||
60 | + c = getopt_long (argc, argv, "hvVSP:p:u:d:H:q:w:c:C:", longopts, &option); | ||
61 | |||
62 | if (c == -1 || c == EOF) | ||
63 | break; | ||
64 | @@ -233,6 +243,9 @@ | ||
65 | case 'q': | ||
66 | asprintf(&sql_query, "%s", optarg); | ||
67 | break; | ||
68 | + case 'C': /* column */ | ||
69 | + sql_column = atoi(optarg); | ||
70 | + break; | ||
71 | case 'w': | ||
72 | warning = optarg; | ||
73 | break; | ||
74 | @@ -292,7 +305,9 @@ | ||
75 | |||
76 | printf (_(UT_HELP_VRSN)); | ||
77 | printf (" -q, --query=STRING\n"); | ||
78 | - printf (" %s\n", _("SQL query to run. Only first column in first row will be read")); | ||
79 | + printf (" %s\n", _("SQL query to run. Only first column (unless -c says otherwise) in first row will be read")); | ||
80 | + printf (" -C, --column=INTEGER\n"); | ||
81 | + printf (" %s\n", _("Column number in result row to use for comparison (Default: 0)")); | ||
82 | printf (_(UT_WARN_CRIT_RANGE)); | ||
83 | printf (_(UT_HOST_PORT), 'P', myport); | ||
84 | printf (" -d, --database=STRING\n"); | ||
85 | @@ -317,6 +332,6 @@ | ||
86 | { | ||
87 | printf (_("Usage:")); | ||
88 | printf ("%s -q SQL_query [-w warn] [-c crit]\n",progname); | ||
89 | - printf ("[-d database] [-H host] [-P port] [-u user] [-p password]\n"); | ||
90 | + printf ("[ -C column ] [-d database] [-H host] [-P port] [-u user] [-p password]\n"); | ||
91 | } | ||
92 | |||