summaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'plugins')
-rw-r--r--plugins/check_http.c24
-rw-r--r--plugins/check_mysql.c76
-rw-r--r--plugins/check_snmp.c41
-rwxr-xr-xplugins/tests/check_http.t13
4 files changed, 131 insertions, 23 deletions
diff --git a/plugins/check_http.c b/plugins/check_http.c
index 6db38e8..ea7a673 100644
--- a/plugins/check_http.c
+++ b/plugins/check_http.c
@@ -100,7 +100,9 @@ char *user_agent;
100int server_url_length; 100int server_url_length;
101int server_expect_yn = 0; 101int server_expect_yn = 0;
102char server_expect[MAX_INPUT_BUFFER] = HTTP_EXPECT; 102char server_expect[MAX_INPUT_BUFFER] = HTTP_EXPECT;
103char header_expect[MAX_INPUT_BUFFER] = "";
103char string_expect[MAX_INPUT_BUFFER] = ""; 104char string_expect[MAX_INPUT_BUFFER] = "";
105char output_header_search[30] = "";
104char output_string_search[30] = ""; 106char output_string_search[30] = "";
105char *warning_thresholds = NULL; 107char *warning_thresholds = NULL;
106char *critical_thresholds = NULL; 108char *critical_thresholds = NULL;
@@ -205,6 +207,7 @@ process_arguments (int argc, char **argv)
205 {"port", required_argument, 0, 'p'}, 207 {"port", required_argument, 0, 'p'},
206 {"authorization", required_argument, 0, 'a'}, 208 {"authorization", required_argument, 0, 'a'},
207 {"proxy_authorization", required_argument, 0, 'b'}, 209 {"proxy_authorization", required_argument, 0, 'b'},
210 {"header-string", required_argument, 0, 'd'},
208 {"string", required_argument, 0, 's'}, 211 {"string", required_argument, 0, 's'},
209 {"expect", required_argument, 0, 'e'}, 212 {"expect", required_argument, 0, 'e'},
210 {"regex", required_argument, 0, 'r'}, 213 {"regex", required_argument, 0, 'r'},
@@ -243,7 +246,7 @@ process_arguments (int argc, char **argv)
243 } 246 }
244 247
245 while (1) { 248 while (1) {
246 c = getopt_long (argc, argv, "Vvh46t:c:w:A:k:H:P:j:T:I:a:b:e:p:s:R:r:u:f:C:nlLS::m:M:N:E", longopts, &option); 249 c = getopt_long (argc, argv, "Vvh46t:c:w:A:k:H:P:j:T:I:a:b:d:e:p:s:R:r:u:f:C:nlLS::m:M:N:E", longopts, &option);
247 if (c == -1 || c == EOF) 250 if (c == -1 || c == EOF)
248 break; 251 break;
249 252
@@ -392,6 +395,10 @@ process_arguments (int argc, char **argv)
392 free(http_method); 395 free(http_method);
393 http_method = strdup (optarg); 396 http_method = strdup (optarg);
394 break; 397 break;
398 case 'd': /* string or substring */
399 strncpy (header_expect, optarg, MAX_INPUT_BUFFER - 1);
400 header_expect[MAX_INPUT_BUFFER - 1] = 0;
401 break;
395 case 's': /* string or substring */ 402 case 's': /* string or substring */
396 strncpy (string_expect, optarg, MAX_INPUT_BUFFER - 1); 403 strncpy (string_expect, optarg, MAX_INPUT_BUFFER - 1);
397 string_expect[MAX_INPUT_BUFFER - 1] = 0; 404 string_expect[MAX_INPUT_BUFFER - 1] = 0;
@@ -1085,6 +1092,17 @@ check_http (void)
1085 } 1092 }
1086 1093
1087 /* Page and Header content checks go here */ 1094 /* Page and Header content checks go here */
1095 if (strlen (header_expect)) {
1096 if (!strstr (header, header_expect)) {
1097 strncpy(&output_header_search[0],header_expect,sizeof(output_header_search));
1098 if(output_header_search[sizeof(output_header_search)-1]!='\0') {
1099 bcopy("...",&output_header_search[sizeof(output_header_search)-4],4);
1100 }
1101 xasprintf (&msg, _("%sheader '%s' not found on '%s://%s:%d%s', "), msg, output_header_search, use_ssl ? "https" : "http", host_name ? host_name : server_address, server_port, server_url);
1102 result = STATE_CRITICAL;
1103 }
1104 }
1105
1088 1106
1089 if (strlen (string_expect)) { 1107 if (strlen (string_expect)) {
1090 if (!strstr (page, string_expect)) { 1108 if (!strstr (page, string_expect)) {
@@ -1434,6 +1452,8 @@ print_help (void)
1434 printf (" %s", _("the first (status) line of the server response (default: ")); 1452 printf (" %s", _("the first (status) line of the server response (default: "));
1435 printf ("%s)\n", HTTP_EXPECT); 1453 printf ("%s)\n", HTTP_EXPECT);
1436 printf (" %s\n", _("If specified skips all other status line logic (ex: 3xx, 4xx, 5xx processing)")); 1454 printf (" %s\n", _("If specified skips all other status line logic (ex: 3xx, 4xx, 5xx processing)"));
1455 printf (" %s\n", "-d, --header-string=STRING");
1456 printf (" %s\n", _("String to expect in the response headers"));
1437 printf (" %s\n", "-s, --string=STRING"); 1457 printf (" %s\n", "-s, --string=STRING");
1438 printf (" %s\n", _("String to expect in the content")); 1458 printf (" %s\n", _("String to expect in the content"));
1439 printf (" %s\n", "-u, --url=PATH"); 1459 printf (" %s\n", "-u, --url=PATH");
@@ -1535,7 +1555,7 @@ print_usage (void)
1535 printf (" %s -H <vhost> | -I <IP-address> [-u <uri>] [-p <port>]\n",progname); 1555 printf (" %s -H <vhost> | -I <IP-address> [-u <uri>] [-p <port>]\n",progname);
1536 printf (" [-w <warn time>] [-c <critical time>] [-t <timeout>] [-L] [-a auth]\n"); 1556 printf (" [-w <warn time>] [-c <critical time>] [-t <timeout>] [-L] [-a auth]\n");
1537 printf (" [-b proxy_auth] [-f <ok|warning|critcal|follow|sticky|stickyport>]\n"); 1557 printf (" [-b proxy_auth] [-f <ok|warning|critcal|follow|sticky|stickyport>]\n");
1538 printf (" [-e <expect>] [-s string] [-l] [-r <regex> | -R <case-insensitive regex>]\n"); 1558 printf (" [-e <expect>] [-d string] [-s string] [-l] [-r <regex> | -R <case-insensitive regex>]\n");
1539 printf (" [-P string] [-m <min_pg_size>:<max_pg_size>] [-4|-6] [-N] [-M <age>]\n"); 1559 printf (" [-P string] [-m <min_pg_size>:<max_pg_size>] [-4|-6] [-N] [-M <age>]\n");
1540 printf (" [-A string] [-k string] [-S <version>] [--sni] [-C <warn_age>[,<crit_age>]]\n"); 1560 printf (" [-A string] [-k string] [-S <version>] [--sni] [-C <warn_age>[,<crit_age>]]\n");
1541 printf (" [-T <content-type>] [-j method]\n"); 1561 printf (" [-T <content-type>] [-j method]\n");
diff --git a/plugins/check_mysql.c b/plugins/check_mysql.c
index ad3d86f..11d4a2f 100644
--- a/plugins/check_mysql.c
+++ b/plugins/check_mysql.c
@@ -59,6 +59,32 @@ unsigned int db_port = MYSQL_PORT;
59int check_slave = 0, warn_sec = 0, crit_sec = 0; 59int check_slave = 0, warn_sec = 0, crit_sec = 0;
60int verbose = 0; 60int verbose = 0;
61 61
62static double warning_time = 0;
63static double critical_time = 0;
64
65#define LENGTH_METRIC_UNIT 6
66static const char *metric_unit[LENGTH_METRIC_UNIT] = {
67 "Open_files",
68 "Open_tables",
69 "Qcache_free_memory",
70 "Qcache_queries_in_cache",
71 "Threads_connected",
72 "Threads_running"
73};
74
75#define LENGTH_METRIC_COUNTER 9
76static const char *metric_counter[LENGTH_METRIC_COUNTER] = {
77 "Connections",
78 "Qcache_hits",
79 "Qcache_inserts",
80 "Qcache_lowmem_prunes",
81 "Qcache_not_cached",
82 "Queries",
83 "Questions",
84 "Table_locks_waited",
85 "Uptime"
86};
87
62thresholds *my_threshold = NULL; 88thresholds *my_threshold = NULL;
63 89
64int process_arguments (int, char **); 90int process_arguments (int, char **);
@@ -79,6 +105,9 @@ main (int argc, char **argv)
79 char *result = NULL; 105 char *result = NULL;
80 char *error = NULL; 106 char *error = NULL;
81 char slaveresult[SLAVERESULTSIZE]; 107 char slaveresult[SLAVERESULTSIZE];
108 char* perf;
109
110 perf = strdup ("");
82 111
83 setlocale (LC_ALL, ""); 112 setlocale (LC_ALL, "");
84 bindtextdomain (PACKAGE, LOCALEDIR); 113 bindtextdomain (PACKAGE, LOCALEDIR);
@@ -126,6 +155,37 @@ main (int argc, char **argv)
126 die (STATE_CRITICAL, "%s\n", mysql_error (&mysql)); 155 die (STATE_CRITICAL, "%s\n", mysql_error (&mysql));
127 } 156 }
128 157
158 /* try to fetch some perf data */
159 if (mysql_query (&mysql, "show global status") == 0) {
160 if ( (res = mysql_store_result (&mysql)) == NULL) {
161 error = strdup(mysql_error(&mysql));
162 mysql_close (&mysql);
163 die (STATE_CRITICAL, _("status store_result error: %s\n"), error);
164 }
165
166 while ( (row = mysql_fetch_row (res)) != NULL) {
167 int i;
168
169 for(i = 0; i < LENGTH_METRIC_UNIT; i++) {
170 if (strcmp(row[0], metric_unit[i]) == 0) {
171 xasprintf(&perf, "%s%s ", perf, perfdata(metric_unit[i],
172 atol(row[1]), "", FALSE, 0, FALSE, 0, FALSE, 0, FALSE, 0));
173 continue;
174 }
175 }
176 for(i = 0; i < LENGTH_METRIC_COUNTER; i++) {
177 if (strcmp(row[0], metric_counter[i]) == 0) {
178 xasprintf(&perf, "%s%s ", perf, perfdata(metric_counter[i],
179 atol(row[1]), "c", FALSE, 0, FALSE, 0, FALSE, 0, FALSE, 0));
180 continue;
181 }
182 }
183 }
184 /* remove trailing space */
185 if (strlen(perf) > 0)
186 perf[strlen(perf) - 1] = '\0';
187 }
188
129 if(check_slave) { 189 if(check_slave) {
130 /* check the slave status */ 190 /* check the slave status */
131 if (mysql_query (&mysql, "show slave status") != 0) { 191 if (mysql_query (&mysql, "show slave status") != 0) {
@@ -218,11 +278,17 @@ main (int argc, char **argv)
218 278
219 status = get_status(value, my_threshold); 279 status = get_status(value, my_threshold);
220 280
281 xasprintf (&perf, "%s %s", perf, fperfdata ("seconds behind master", value, "s",
282 TRUE, (double) warning_time,
283 TRUE, (double) critical_time,
284 FALSE, 0,
285 FALSE, 0));
286
221 if (status == STATE_WARNING) { 287 if (status == STATE_WARNING) {
222 printf("SLOW_SLAVE %s: %s\n", _("WARNING"), slaveresult); 288 printf("SLOW_SLAVE %s: %s|%s\n", _("WARNING"), slaveresult, perf);
223 exit(STATE_WARNING); 289 exit(STATE_WARNING);
224 } else if (status == STATE_CRITICAL) { 290 } else if (status == STATE_CRITICAL) {
225 printf("SLOW_SLAVE %s: %s\n", _("CRITICAL"), slaveresult); 291 printf("SLOW_SLAVE %s: %s|%s\n", _("CRITICAL"), slaveresult, perf);
226 exit(STATE_CRITICAL); 292 exit(STATE_CRITICAL);
227 } 293 }
228 } 294 }
@@ -237,9 +303,9 @@ main (int argc, char **argv)
237 303
238 /* print out the result of stats */ 304 /* print out the result of stats */
239 if (check_slave) { 305 if (check_slave) {
240 printf ("%s %s\n", result, slaveresult); 306 printf ("%s %s|%s\n", result, slaveresult, perf);
241 } else { 307 } else {
242 printf ("%s\n", result); 308 printf ("%s|%s\n", result, perf);
243 } 309 }
244 310
245 return STATE_OK; 311 return STATE_OK;
@@ -339,9 +405,11 @@ process_arguments (int argc, char **argv)
339 break; 405 break;
340 case 'w': 406 case 'w':
341 warning = optarg; 407 warning = optarg;
408 warning_time = strtod (warning, NULL);
342 break; 409 break;
343 case 'c': 410 case 'c':
344 critical = optarg; 411 critical = optarg;
412 critical_time = strtod (critical, NULL);
345 break; 413 break;
346 case 'V': /* version */ 414 case 'V': /* version */
347 print_revision (progname, NP_VERSION); 415 print_revision (progname, NP_VERSION);
diff --git a/plugins/check_snmp.c b/plugins/check_snmp.c
index 7c5d0ec..7c3bc4b 100644
--- a/plugins/check_snmp.c
+++ b/plugins/check_snmp.c
@@ -63,6 +63,7 @@ const char *email = "nagiosplug-devel@lists.sourceforge.net";
63#define L_CALCULATE_RATE CHAR_MAX+1 63#define L_CALCULATE_RATE CHAR_MAX+1
64#define L_RATE_MULTIPLIER CHAR_MAX+2 64#define L_RATE_MULTIPLIER CHAR_MAX+2
65#define L_INVERT_SEARCH CHAR_MAX+3 65#define L_INVERT_SEARCH CHAR_MAX+3
66#define L_OFFSET CHAR_MAX+4
66 67
67/* Gobble to string - stop incrementing c when c[0] match one of the 68/* Gobble to string - stop incrementing c when c[0] match one of the
68 * characters in s */ 69 * characters in s */
@@ -138,6 +139,7 @@ char *output_delim;
138char *miblist = NULL; 139char *miblist = NULL;
139int needmibs = FALSE; 140int needmibs = FALSE;
140int calculate_rate = 0; 141int calculate_rate = 0;
142double offset = 0.0;
141int rate_multiplier = 1; 143int rate_multiplier = 1;
142state_data *previous_state; 144state_data *previous_state;
143double previous_value[MAX_OIDS]; 145double previous_value[MAX_OIDS];
@@ -274,35 +276,36 @@ main (int argc, char **argv)
274 snmpcmd = strdup (PATH_TO_SNMPGET); 276 snmpcmd = strdup (PATH_TO_SNMPGET);
275 } 277 }
276 278
277 /* 9 arguments to pass before authpriv options + 1 for host and numoids. Add one for terminating NULL */ 279 /* 10 arguments to pass before authpriv options + 1 for host and numoids. Add one for terminating NULL */
278 command_line = calloc (9 + numauthpriv + 1 + numoids + 1, sizeof (char *)); 280 command_line = calloc (10 + numauthpriv + 1 + numoids + 1, sizeof (char *));
279 command_line[0] = snmpcmd; 281 command_line[0] = snmpcmd;
280 command_line[1] = strdup ("-t"); 282 command_line[1] = strdup ("-Le");
281 xasprintf (&command_line[2], "%d", timeout_interval); 283 command_line[2] = strdup ("-t");
282 command_line[3] = strdup ("-r"); 284 xasprintf (&command_line[3], "%d", timeout_interval);
283 xasprintf (&command_line[4], "%d", retries); 285 command_line[4] = strdup ("-r");
284 command_line[5] = strdup ("-m"); 286 xasprintf (&command_line[5], "%d", retries);
285 command_line[6] = strdup (miblist); 287 command_line[6] = strdup ("-m");
286 command_line[7] = "-v"; 288 command_line[7] = strdup (miblist);
287 command_line[8] = strdup (proto); 289 command_line[8] = "-v";
290 command_line[9] = strdup (proto);
288 291
289 for (i = 0; i < numauthpriv; i++) { 292 for (i = 0; i < numauthpriv; i++) {
290 command_line[9 + i] = authpriv[i]; 293 command_line[10 + i] = authpriv[i];
291 } 294 }
292 295
293 xasprintf (&command_line[9 + numauthpriv], "%s:%s", server_address, port); 296 xasprintf (&command_line[10 + numauthpriv], "%s:%s", server_address, port);
294 297
295 /* This is just for display purposes, so it can remain a string */ 298 /* This is just for display purposes, so it can remain a string */
296 xasprintf(&cl_hidden_auth, "%s -t %d -r %d -m %s -v %s %s %s:%s", 299 xasprintf(&cl_hidden_auth, "%s -Le -t %d -r %d -m %s -v %s %s %s:%s",
297 snmpcmd, timeout_interval, retries, strlen(miblist) ? miblist : "''", proto, "[authpriv]", 300 snmpcmd, timeout_interval, retries, strlen(miblist) ? miblist : "''", proto, "[authpriv]",
298 server_address, port); 301 server_address, port);
299 302
300 for (i = 0; i < numoids; i++) { 303 for (i = 0; i < numoids; i++) {
301 command_line[9 + numauthpriv + 1 + i] = oids[i]; 304 command_line[10 + numauthpriv + 1 + i] = oids[i];
302 xasprintf(&cl_hidden_auth, "%s %s", cl_hidden_auth, oids[i]); 305 xasprintf(&cl_hidden_auth, "%s %s", cl_hidden_auth, oids[i]);
303 } 306 }
304 307
305 command_line[9 + numauthpriv + 1 + numoids] = NULL; 308 command_line[10 + numauthpriv + 1 + numoids] = NULL;
306 309
307 if (verbose) 310 if (verbose)
308 printf ("%s\n", cl_hidden_auth); 311 printf ("%s\n", cl_hidden_auth);
@@ -429,7 +432,7 @@ main (int argc, char **argv)
429 ptr = strpbrk (show, "0123456789"); 432 ptr = strpbrk (show, "0123456789");
430 if (ptr == NULL) 433 if (ptr == NULL)
431 die (STATE_UNKNOWN,_("No valid data returned (%s)\n"), show); 434 die (STATE_UNKNOWN,_("No valid data returned (%s)\n"), show);
432 response_value[i] = strtod (ptr, NULL); 435 response_value[i] = strtod (ptr, NULL) + offset;
433 436
434 if(calculate_rate) { 437 if(calculate_rate) {
435 if (previous_state!=NULL) { 438 if (previous_state!=NULL) {
@@ -618,6 +621,7 @@ process_arguments (int argc, char **argv)
618 {"next", no_argument, 0, 'n'}, 621 {"next", no_argument, 0, 'n'},
619 {"rate", no_argument, 0, L_CALCULATE_RATE}, 622 {"rate", no_argument, 0, L_CALCULATE_RATE},
620 {"rate-multiplier", required_argument, 0, L_RATE_MULTIPLIER}, 623 {"rate-multiplier", required_argument, 0, L_RATE_MULTIPLIER},
624 {"offset", required_argument, 0, L_OFFSET},
621 {"invert-search", no_argument, 0, L_INVERT_SEARCH}, 625 {"invert-search", no_argument, 0, L_INVERT_SEARCH},
622 {"perf-oids", no_argument, 0, 'O'}, 626 {"perf-oids", no_argument, 0, 'O'},
623 {0, 0, 0, 0} 627 {0, 0, 0, 0}
@@ -832,6 +836,9 @@ process_arguments (int argc, char **argv)
832 if(!is_integer(optarg)||((rate_multiplier=atoi(optarg))<=0)) 836 if(!is_integer(optarg)||((rate_multiplier=atoi(optarg))<=0))
833 usage2(_("Rate multiplier must be a positive integer"),optarg); 837 usage2(_("Rate multiplier must be a positive integer"),optarg);
834 break; 838 break;
839 case L_OFFSET:
840 offset=strtod(optarg,NULL);
841 break;
835 case L_INVERT_SEARCH: 842 case L_INVERT_SEARCH:
836 invert_search=1; 843 invert_search=1;
837 break; 844 break;
@@ -1080,6 +1087,8 @@ print_help (void)
1080 printf (" %s\n", _("Enable rate calculation. See 'Rate Calculation' below")); 1087 printf (" %s\n", _("Enable rate calculation. See 'Rate Calculation' below"));
1081 printf (" %s\n", "--rate-multiplier"); 1088 printf (" %s\n", "--rate-multiplier");
1082 printf (" %s\n", _("Converts rate per second. For example, set to 60 to convert to per minute")); 1089 printf (" %s\n", _("Converts rate per second. For example, set to 60 to convert to per minute"));
1090 printf (" %s\n", "--offset=OFFSET");
1091 printf (" %s\n", _("Add/substract the specified OFFSET to numeric sensor data"));
1083 1092
1084 /* Tests Against Strings */ 1093 /* Tests Against Strings */
1085 printf (" %s\n", "-s, --string=STRING"); 1094 printf (" %s\n", "-s, --string=STRING");
diff --git a/plugins/tests/check_http.t b/plugins/tests/check_http.t
index 9f97abd..c3085e1 100755
--- a/plugins/tests/check_http.t
+++ b/plugins/tests/check_http.t
@@ -17,7 +17,7 @@ use Test::More;
17use NPTest; 17use NPTest;
18use FindBin qw($Bin); 18use FindBin qw($Bin);
19 19
20my $common_tests = 66; 20my $common_tests = 70;
21my $ssl_only_tests = 8; 21my $ssl_only_tests = 8;
22# Check that all dependent modules are available 22# Check that all dependent modules are available
23eval { 23eval {
@@ -151,6 +151,10 @@ sub run_server {
151 unshift @persist, $c; 151 unshift @persist, $c;
152 delete($persist[1000]); 152 delete($persist[1000]);
153 next MAINLOOP; 153 next MAINLOOP;
154 } elsif ($r->url->path eq "/header_check") {
155 $c->send_basic_header;
156 $c->send_header('foo');
157 $c->send_crlf;
154 } else { 158 } else {
155 $c->send_error(HTTP::Status->RC_FORBIDDEN); 159 $c->send_error(HTTP::Status->RC_FORBIDDEN);
156 } 160 }
@@ -223,6 +227,13 @@ sub run_common_tests {
223 is( $result->return_code, 2, "Missing string check"); 227 is( $result->return_code, 2, "Missing string check");
224 like( $result->output, qr%HTTP CRITICAL: HTTP/1\.1 200 OK - string 'NonRootWithOver30charsAndM...' not found on 'https?://127\.0\.0\.1:\d+/file/root'%, "Shows search string and location"); 228 like( $result->output, qr%HTTP CRITICAL: HTTP/1\.1 200 OK - string 'NonRootWithOver30charsAndM...' not found on 'https?://127\.0\.0\.1:\d+/file/root'%, "Shows search string and location");
225 229
230 $result = NPTest->testCmd( "$command -u /header_check -d foo" );
231 is( $result->return_code, 0, "header_check search for string");
232 like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - 96 bytes in [\d\.]+ second/', "Output correct" );
233
234 $result = NPTest->testCmd( "$command -u /header_check -d bar" );
235 is( $result->return_code, 2, "Missing header string check");
236 like( $result->output, qr%^HTTP CRITICAL: HTTP/1\.1 200 OK - header 'bar' not found on 'https?://127\.0\.0\.1:\d+/header_check'%, "Shows search string and location");
226 237
227 my $cmd; 238 my $cmd;
228 $cmd = "$command -u /slow"; 239 $cmd = "$command -u /slow";