1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
|
--- plutins/check_http.c 2002-10-28 18:02:11.000000000 +0100
+++ plugins/check_http.c 2002-10-28 19:42:30.000000000 +0100
@@ -44,7 +44,7 @@
\(-H <vhost> | -I <IP-address>) [-u <uri>] [-p <port>]\n\
[-w <warn time>] [-c <critical time>] [-t <timeout>] [-L]\n\
[-a auth] [-f <ok | warn | critcal | follow>] [-e <expect>]\n\
- [-s string] [-r <regex> | -R <case-insensitive regex>]\n\
+ [-s string] [-r <regex> | -R <case-insensitive regex>] [-x]\n\
[-P string]"
#define LONGOPTIONS "\
@@ -71,6 +71,8 @@
Seconds before connection times out (default: %d)\n\
-a, --authorization=AUTH_PAIR\n\
Username:password on sites with basic authentication\n\
+ -x, --reverse\n\
+ Reverse the result of -r|-R|-s (like grep -v)\n\
-L, --link=URL\n\
Wrap output in HTML link (obsoleted by urlize)\n\
-f, --onredirect=<ok|warning|critical|follow>\n\
@@ -190,6 +192,7 @@
int server_expect_yn = 0;
char server_expect[MAX_INPUT_BUFFER] = HTTP_EXPECT;
char string_expect[MAX_INPUT_BUFFER] = "";
+int found_reverse = FALSE; /* grep -v */
double warning_time = 0;
int check_warning_time = FALSE;
double critical_time = 0;
@@ -287,6 +290,7 @@
{"regex", required_argument, 0, 'r'},
{"ereg", required_argument, 0, 'r'},
{"eregi", required_argument, 0, 'R'},
+ {"reverse", no_argument, 0, 'x'},
{"onredirect", required_argument, 0, 'f'},
{"certificate", required_argument, 0, 'C'},
{0, 0, 0, 0}
@@ -309,7 +313,7 @@
strcpy (argv[c], "-n");
}
-#define OPTCHARS "Vvht:c:w:H:P:I:a:e:p:s:R:r:u:f:C:nLS"
+#define OPTCHARS "Vvht:c:w:H:P:I:a:e:p:s:R:r:u:f:C:nLSx"
while (1) {
#ifdef HAVE_GETOPT_H
@@ -442,6 +446,9 @@
usage ("check_http: call for regex which was not a compiled option\n");
#endif
break;
+ case 'x': /* grep -v */
+ found_reverse = TRUE;
+ break;
case 'v': /* verbose */
verbose = TRUE;
break;
@@ -849,31 +856,69 @@
if (strlen (string_expect)) {
if (strstr (page, string_expect)) {
- printf ("HTTP ok: %s - %7.3f second response time %s%s|time=%7.3f\n",
- status_line, elapsed_time,
- timestamp, (display_html ? "</A>" : ""), elapsed_time);
- exit (STATE_OK);
+ if (found_reverse) { /* grep -v */
+ printf ("HTTP CRITICAL: string found%s|time=%7.3f\n",
+ (display_html ? "</A>" : ""),
+ elapsed_time);
+ exit (STATE_CRITICAL) ;
+ } else {
+ printf ("HTTP ok: %s - %7.3f second response time %s%s|time=%7.3f\n",
+ status_line, elapsed_time,
+ timestamp,
+ (display_html ? "</A>" : ""),
+ elapsed_time);
+ exit (STATE_OK);
+ }
}
- else {
- printf ("HTTP CRITICAL: string not found%s|time=%7.3f\n",
- (display_html ? "</A>" : ""), elapsed_time);
- exit (STATE_CRITICAL);
+ else { /* not found */
+ if (found_reverse) { /* grep -v */
+ printf ("HTTP ok: %s - %7.3f second response time %s%s|time=%7.3f\n",
+ status_line, elapsed_time,
+ timestamp,
+ (display_html ? "</A>" : ""),
+ elapsed_time);
+ exit (STATE_OK) ;
+ } else {
+ printf ("HTTP CRITICAL: string not found%s|time=%7.3f\n",
+ (display_html ? "</A>" : ""), elapsed_time);
+ exit (STATE_CRITICAL);
+ }
}
}
#ifdef HAVE_REGEX_H
if (strlen (regexp)) {
errcode = regexec (&preg, page, REGS, pmatch, 0);
if (errcode == 0) {
- printf ("HTTP ok: %s - %7.3f second response time %s%s|time=%7.3f\n",
- status_line, elapsed_time,
- timestamp, (display_html ? "</A>" : ""), elapsed_time);
- exit (STATE_OK);
+ if (found_reverse) { /* grep -v */
+ printf ("HTTP CRITICAL: pattern found%s|time=%7.3f\n",
+ (display_html ? "</A>" : ""),
+ elapsed_time);
+ exit (STATE_CRITICAL);
+ } else {
+ printf ("HTTP ok: %s - %7.3f second response time %s%s|time=%7.3f\n",
+ status_line, elapsed_time,
+ timestamp,
+ (display_html ? "</A>" : ""),
+ elapsed_time);
+ exit (STATE_OK);
+ }
}
else {
if (errcode == REG_NOMATCH) {
- printf ("HTTP CRITICAL: pattern not found%s|time=%7.3f\n",
- (display_html ? "</A>" : ""), elapsed_time);
- exit (STATE_CRITICAL);
+ if (found_reverse) { /* grep -v */
+ printf ("HTTP ok: %s - %7.3f second response time %s%s|time=%7.3f\n",
+ status_line, elapsed_time,
+ timestamp,
+ (display_html ? "</A>" : ""),
+ elapsed_time);
+ exit (STATE_OK);
+
+ } else {
+ printf ("HTTP CRITICAL: pattern not found%s|time=%7.3f\n",
+ (display_html ? "</A>" : ""),
+ elapsed_time);
+ exit (STATE_CRITICAL);
+ }
}
else {
regerror (errcode, &preg, errbuf, MAX_INPUT_BUFFER);
|