diff options
Diffstat (limited to 'plugins/check_real.c')
-rw-r--r-- | plugins/check_real.c | 484 |
1 files changed, 215 insertions, 269 deletions
diff --git a/plugins/check_real.c b/plugins/check_real.c index 15e035b..369a88b 100644 --- a/plugins/check_real.c +++ b/plugins/check_real.c | |||
@@ -1,35 +1,35 @@ | |||
1 | /***************************************************************************** | 1 | /***************************************************************************** |
2 | * | 2 | * |
3 | * Monitoring check_real plugin | 3 | * Monitoring check_real plugin |
4 | * | 4 | * |
5 | * License: GPL | 5 | * License: GPL |
6 | * Copyright (c) 2000-2007 Monitoring Plugins Development Team | 6 | * Copyright (c) 2000-2024 Monitoring Plugins Development Team |
7 | * | 7 | * |
8 | * Description: | 8 | * Description: |
9 | * | 9 | * |
10 | * This file contains the check_real plugin | 10 | * This file contains the check_real plugin |
11 | * | 11 | * |
12 | * This plugin tests the REAL service on the specified host. | 12 | * This plugin tests the REAL service on the specified host. |
13 | * | 13 | * |
14 | * | 14 | * |
15 | * This program is free software: you can redistribute it and/or modify | 15 | * This program is free software: you can redistribute it and/or modify |
16 | * it under the terms of the GNU General Public License as published by | 16 | * it under the terms of the GNU General Public License as published by |
17 | * the Free Software Foundation, either version 3 of the License, or | 17 | * the Free Software Foundation, either version 3 of the License, or |
18 | * (at your option) any later version. | 18 | * (at your option) any later version. |
19 | * | 19 | * |
20 | * This program is distributed in the hope that it will be useful, | 20 | * This program is distributed in the hope that it will be useful, |
21 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 21 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
22 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 22 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
23 | * GNU General Public License for more details. | 23 | * GNU General Public License for more details. |
24 | * | 24 | * |
25 | * You should have received a copy of the GNU General Public License | 25 | * You should have received a copy of the GNU General Public License |
26 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | 26 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
27 | * | 27 | * |
28 | * | 28 | * |
29 | *****************************************************************************/ | 29 | *****************************************************************************/ |
30 | 30 | ||
31 | const char *progname = "check_real"; | 31 | const char *progname = "check_real"; |
32 | const char *copyright = "2000-2007"; | 32 | const char *copyright = "2000-2024"; |
33 | const char *email = "devel@monitoring-plugins.org"; | 33 | const char *email = "devel@monitoring-plugins.org"; |
34 | 34 | ||
35 | #include "common.h" | 35 | #include "common.h" |
@@ -37,121 +37,111 @@ const char *email = "devel@monitoring-plugins.org"; | |||
37 | #include "utils.h" | 37 | #include "utils.h" |
38 | 38 | ||
39 | enum { | 39 | enum { |
40 | PORT = 554 | 40 | PORT = 554 |
41 | }; | 41 | }; |
42 | 42 | ||
43 | #define EXPECT "RTSP/1." | 43 | #define EXPECT "RTSP/1." |
44 | #define URL "" | 44 | #define URL "" |
45 | 45 | ||
46 | int process_arguments (int, char **); | 46 | static int process_arguments(int, char **); |
47 | int validate_arguments (void); | 47 | static void print_help(void); |
48 | void print_help (void); | 48 | void print_usage(void); |
49 | void print_usage (void); | 49 | |
50 | 50 | static int server_port = PORT; | |
51 | int server_port = PORT; | 51 | static char *server_address; |
52 | char *server_address; | 52 | static char *host_name; |
53 | char *host_name; | 53 | static char *server_url = NULL; |
54 | char *server_url = NULL; | 54 | static char *server_expect; |
55 | char *server_expect; | 55 | static int warning_time = 0; |
56 | int warning_time = 0; | 56 | static bool check_warning_time = false; |
57 | bool check_warning_time = false; | 57 | static int critical_time = 0; |
58 | int critical_time = 0; | 58 | static bool check_critical_time = false; |
59 | bool check_critical_time = false; | 59 | static bool verbose = false; |
60 | bool verbose = false; | 60 | |
61 | 61 | int main(int argc, char **argv) { | |
62 | 62 | setlocale(LC_ALL, ""); | |
63 | 63 | bindtextdomain(PACKAGE, LOCALEDIR); | |
64 | int | 64 | textdomain(PACKAGE); |
65 | main (int argc, char **argv) | ||
66 | { | ||
67 | int sd; | ||
68 | int result = STATE_UNKNOWN; | ||
69 | char buffer[MAX_INPUT_BUFFER]; | ||
70 | char *status_line = NULL; | ||
71 | |||
72 | setlocale (LC_ALL, ""); | ||
73 | bindtextdomain (PACKAGE, LOCALEDIR); | ||
74 | textdomain (PACKAGE); | ||
75 | 65 | ||
76 | /* Parse extra opts if any */ | 66 | /* Parse extra opts if any */ |
77 | argv=np_extra_opts (&argc, argv, progname); | 67 | argv = np_extra_opts(&argc, argv, progname); |
78 | 68 | ||
79 | if (process_arguments (argc, argv) == ERROR) | 69 | if (process_arguments(argc, argv) == ERROR) |
80 | usage4 (_("Could not parse arguments")); | 70 | usage4(_("Could not parse arguments")); |
81 | 71 | ||
82 | /* initialize alarm signal handling */ | 72 | /* initialize alarm signal handling */ |
83 | signal (SIGALRM, socket_timeout_alarm_handler); | 73 | signal(SIGALRM, socket_timeout_alarm_handler); |
84 | 74 | ||
85 | /* set socket timeout */ | 75 | /* set socket timeout */ |
86 | alarm (socket_timeout); | 76 | alarm(socket_timeout); |
87 | time (&start_time); | 77 | time(&start_time); |
88 | 78 | ||
89 | /* try to connect to the host at the given port number */ | 79 | /* try to connect to the host at the given port number */ |
90 | if (my_tcp_connect (server_address, server_port, &sd) != STATE_OK) | 80 | int socket; |
91 | die (STATE_CRITICAL, _("Unable to connect to %s on port %d\n"), | 81 | if (my_tcp_connect(server_address, server_port, &socket) != STATE_OK) |
92 | server_address, server_port); | 82 | die(STATE_CRITICAL, _("Unable to connect to %s on port %d\n"), server_address, server_port); |
93 | 83 | ||
94 | /* Part I - Server Check */ | 84 | /* Part I - Server Check */ |
95 | 85 | ||
96 | /* send the OPTIONS request */ | 86 | /* send the OPTIONS request */ |
97 | sprintf (buffer, "OPTIONS rtsp://%s:%d RTSP/1.0\r\n", host_name, server_port); | 87 | char buffer[MAX_INPUT_BUFFER]; |
98 | result = send (sd, buffer, strlen (buffer), 0); | 88 | sprintf(buffer, "OPTIONS rtsp://%s:%d RTSP/1.0\r\n", host_name, server_port); |
89 | int result = send(socket, buffer, strlen(buffer), 0); | ||
99 | 90 | ||
100 | /* send the header sync */ | 91 | /* send the header sync */ |
101 | sprintf (buffer, "CSeq: 1\r\n"); | 92 | sprintf(buffer, "CSeq: 1\r\n"); |
102 | result = send (sd, buffer, strlen (buffer), 0); | 93 | result = send(socket, buffer, strlen(buffer), 0); |
103 | 94 | ||
104 | /* send a newline so the server knows we're done with the request */ | 95 | /* send a newline so the server knows we're done with the request */ |
105 | sprintf (buffer, "\r\n"); | 96 | sprintf(buffer, "\r\n"); |
106 | result = send (sd, buffer, strlen (buffer), 0); | 97 | result = send(socket, buffer, strlen(buffer), 0); |
107 | 98 | ||
108 | /* watch for the REAL connection string */ | 99 | /* watch for the REAL connection string */ |
109 | result = recv (sd, buffer, MAX_INPUT_BUFFER - 1, 0); | 100 | result = recv(socket, buffer, MAX_INPUT_BUFFER - 1, 0); |
110 | 101 | ||
111 | /* return a CRITICAL status if we couldn't read any data */ | 102 | /* return a CRITICAL status if we couldn't read any data */ |
112 | if (result == -1) | 103 | if (result == -1) |
113 | die (STATE_CRITICAL, _("No data received from %s\n"), host_name); | 104 | die(STATE_CRITICAL, _("No data received from %s\n"), host_name); |
114 | 105 | ||
106 | char *status_line = NULL; | ||
115 | /* make sure we find the response we are looking for */ | 107 | /* make sure we find the response we are looking for */ |
116 | if (!strstr (buffer, server_expect)) { | 108 | if (!strstr(buffer, server_expect)) { |
117 | if (server_port == PORT) | 109 | if (server_port == PORT) |
118 | printf ("%s\n", _("Invalid REAL response received from host")); | 110 | printf("%s\n", _("Invalid REAL response received from host")); |
119 | else | 111 | else |
120 | printf (_("Invalid REAL response received from host on port %d\n"), | 112 | printf(_("Invalid REAL response received from host on port %d\n"), server_port); |
121 | server_port); | 113 | } else { |
122 | } | ||
123 | else { | ||
124 | /* else we got the REAL string, so check the return code */ | 114 | /* else we got the REAL string, so check the return code */ |
125 | 115 | ||
126 | time (&end_time); | 116 | time(&end_time); |
127 | 117 | ||
128 | result = STATE_OK; | 118 | result = STATE_OK; |
129 | 119 | ||
130 | status_line = (char *) strtok (buffer, "\n"); | 120 | status_line = (char *)strtok(buffer, "\n"); |
131 | 121 | ||
132 | if (strstr (status_line, "200")) | 122 | if (strstr(status_line, "200")) |
133 | result = STATE_OK; | 123 | result = STATE_OK; |
134 | 124 | ||
135 | /* client errors result in a warning state */ | 125 | /* client errors result in a warning state */ |
136 | else if (strstr (status_line, "400")) | 126 | else if (strstr(status_line, "400")) |
137 | result = STATE_WARNING; | 127 | result = STATE_WARNING; |
138 | else if (strstr (status_line, "401")) | 128 | else if (strstr(status_line, "401")) |
139 | result = STATE_WARNING; | 129 | result = STATE_WARNING; |
140 | else if (strstr (status_line, "402")) | 130 | else if (strstr(status_line, "402")) |
141 | result = STATE_WARNING; | 131 | result = STATE_WARNING; |
142 | else if (strstr (status_line, "403")) | 132 | else if (strstr(status_line, "403")) |
143 | result = STATE_WARNING; | 133 | result = STATE_WARNING; |
144 | else if (strstr (status_line, "404")) | 134 | else if (strstr(status_line, "404")) |
145 | result = STATE_WARNING; | 135 | result = STATE_WARNING; |
146 | 136 | ||
147 | /* server errors result in a critical state */ | 137 | /* server errors result in a critical state */ |
148 | else if (strstr (status_line, "500")) | 138 | else if (strstr(status_line, "500")) |
149 | result = STATE_CRITICAL; | 139 | result = STATE_CRITICAL; |
150 | else if (strstr (status_line, "501")) | 140 | else if (strstr(status_line, "501")) |
151 | result = STATE_CRITICAL; | 141 | result = STATE_CRITICAL; |
152 | else if (strstr (status_line, "502")) | 142 | else if (strstr(status_line, "502")) |
153 | result = STATE_CRITICAL; | 143 | result = STATE_CRITICAL; |
154 | else if (strstr (status_line, "503")) | 144 | else if (strstr(status_line, "503")) |
155 | result = STATE_CRITICAL; | 145 | result = STATE_CRITICAL; |
156 | 146 | ||
157 | else | 147 | else |
@@ -159,74 +149,70 @@ main (int argc, char **argv) | |||
159 | } | 149 | } |
160 | 150 | ||
161 | /* Part II - Check stream exists and is ok */ | 151 | /* Part II - Check stream exists and is ok */ |
162 | if ((result == STATE_OK )&& (server_url != NULL) ) { | 152 | if ((result == STATE_OK) && (server_url != NULL)) { |
163 | 153 | ||
164 | /* Part I - Server Check */ | 154 | /* Part I - Server Check */ |
165 | 155 | ||
166 | /* send the DESCRIBE request */ | 156 | /* send the DESCRIBE request */ |
167 | sprintf (buffer, "DESCRIBE rtsp://%s:%d%s RTSP/1.0\r\n", host_name, | 157 | sprintf(buffer, "DESCRIBE rtsp://%s:%d%s RTSP/1.0\r\n", host_name, server_port, server_url); |
168 | server_port, server_url); | 158 | result = send(socket, buffer, strlen(buffer), 0); |
169 | result = send (sd, buffer, strlen (buffer), 0); | ||
170 | 159 | ||
171 | /* send the header sync */ | 160 | /* send the header sync */ |
172 | sprintf (buffer, "CSeq: 2\r\n"); | 161 | sprintf(buffer, "CSeq: 2\r\n"); |
173 | result = send (sd, buffer, strlen (buffer), 0); | 162 | result = send(socket, buffer, strlen(buffer), 0); |
174 | 163 | ||
175 | /* send a newline so the server knows we're done with the request */ | 164 | /* send a newline so the server knows we're done with the request */ |
176 | sprintf (buffer, "\r\n"); | 165 | sprintf(buffer, "\r\n"); |
177 | result = send (sd, buffer, strlen (buffer), 0); | 166 | result = send(socket, buffer, strlen(buffer), 0); |
178 | 167 | ||
179 | /* watch for the REAL connection string */ | 168 | /* watch for the REAL connection string */ |
180 | result = recv (sd, buffer, MAX_INPUT_BUFFER - 1, 0); | 169 | result = recv(socket, buffer, MAX_INPUT_BUFFER - 1, 0); |
181 | buffer[result] = '\0'; /* null terminate received buffer */ | 170 | buffer[result] = '\0'; /* null terminate received buffer */ |
182 | 171 | ||
183 | /* return a CRITICAL status if we couldn't read any data */ | 172 | /* return a CRITICAL status if we couldn't read any data */ |
184 | if (result == -1) { | 173 | if (result == -1) { |
185 | printf (_("No data received from host\n")); | 174 | printf(_("No data received from host\n")); |
186 | result = STATE_CRITICAL; | 175 | result = STATE_CRITICAL; |
187 | } | 176 | } else { |
188 | else { | ||
189 | /* make sure we find the response we are looking for */ | 177 | /* make sure we find the response we are looking for */ |
190 | if (!strstr (buffer, server_expect)) { | 178 | if (!strstr(buffer, server_expect)) { |
191 | if (server_port == PORT) | 179 | if (server_port == PORT) |
192 | printf ("%s\n", _("Invalid REAL response received from host")); | 180 | printf("%s\n", _("Invalid REAL response received from host")); |
193 | else | 181 | else |
194 | printf (_("Invalid REAL response received from host on port %d\n"), | 182 | printf(_("Invalid REAL response received from host on port %d\n"), server_port); |
195 | server_port); | 183 | } else { |
196 | } | ||
197 | else { | ||
198 | 184 | ||
199 | /* else we got the REAL string, so check the return code */ | 185 | /* else we got the REAL string, so check the return code */ |
200 | 186 | ||
201 | time (&end_time); | 187 | time(&end_time); |
202 | 188 | ||
203 | result = STATE_OK; | 189 | result = STATE_OK; |
204 | 190 | ||
205 | status_line = (char *) strtok (buffer, "\n"); | 191 | status_line = (char *)strtok(buffer, "\n"); |
206 | 192 | ||
207 | if (strstr (status_line, "200")) | 193 | if (strstr(status_line, "200")) |
208 | result = STATE_OK; | 194 | result = STATE_OK; |
209 | 195 | ||
210 | /* client errors result in a warning state */ | 196 | /* client errors result in a warning state */ |
211 | else if (strstr (status_line, "400")) | 197 | else if (strstr(status_line, "400")) |
212 | result = STATE_WARNING; | 198 | result = STATE_WARNING; |
213 | else if (strstr (status_line, "401")) | 199 | else if (strstr(status_line, "401")) |
214 | result = STATE_WARNING; | 200 | result = STATE_WARNING; |
215 | else if (strstr (status_line, "402")) | 201 | else if (strstr(status_line, "402")) |
216 | result = STATE_WARNING; | 202 | result = STATE_WARNING; |
217 | else if (strstr (status_line, "403")) | 203 | else if (strstr(status_line, "403")) |
218 | result = STATE_WARNING; | 204 | result = STATE_WARNING; |
219 | else if (strstr (status_line, "404")) | 205 | else if (strstr(status_line, "404")) |
220 | result = STATE_WARNING; | 206 | result = STATE_WARNING; |
221 | 207 | ||
222 | /* server errors result in a critical state */ | 208 | /* server errors result in a critical state */ |
223 | else if (strstr (status_line, "500")) | 209 | else if (strstr(status_line, "500")) |
224 | result = STATE_CRITICAL; | 210 | result = STATE_CRITICAL; |
225 | else if (strstr (status_line, "501")) | 211 | else if (strstr(status_line, "501")) |
226 | result = STATE_CRITICAL; | 212 | result = STATE_CRITICAL; |
227 | else if (strstr (status_line, "502")) | 213 | else if (strstr(status_line, "502")) |
228 | result = STATE_CRITICAL; | 214 | result = STATE_CRITICAL; |
229 | else if (strstr (status_line, "503")) | 215 | else if (strstr(status_line, "503")) |
230 | result = STATE_CRITICAL; | 216 | result = STATE_CRITICAL; |
231 | 217 | ||
232 | else | 218 | else |
@@ -238,217 +224,177 @@ main (int argc, char **argv) | |||
238 | /* Return results */ | 224 | /* Return results */ |
239 | if (result == STATE_OK) { | 225 | if (result == STATE_OK) { |
240 | 226 | ||
241 | if (check_critical_time | 227 | if (check_critical_time && (end_time - start_time) > critical_time) |
242 | && (end_time - start_time) > critical_time) result = STATE_CRITICAL; | 228 | result = STATE_CRITICAL; |
243 | else if (check_warning_time | 229 | else if (check_warning_time && (end_time - start_time) > warning_time) |
244 | && (end_time - start_time) > warning_time) result = | 230 | result = STATE_WARNING; |
245 | STATE_WARNING; | ||
246 | 231 | ||
247 | /* Put some HTML in here to create a dynamic link */ | 232 | /* Put some HTML in here to create a dynamic link */ |
248 | printf (_("REAL %s - %d second response time\n"), | 233 | printf(_("REAL %s - %d second response time\n"), state_text(result), (int)(end_time - start_time)); |
249 | state_text (result), | 234 | } else |
250 | (int) (end_time - start_time)); | 235 | printf("%s\n", status_line); |
251 | } | ||
252 | else | ||
253 | printf ("%s\n", status_line); | ||
254 | 236 | ||
255 | /* close the connection */ | 237 | /* close the connection */ |
256 | close (sd); | 238 | close(socket); |
257 | 239 | ||
258 | /* reset the alarm */ | 240 | /* reset the alarm */ |
259 | alarm (0); | 241 | alarm(0); |
260 | 242 | ||
261 | return result; | 243 | return result; |
262 | } | 244 | } |
263 | 245 | ||
264 | |||
265 | |||
266 | /* process command-line arguments */ | 246 | /* process command-line arguments */ |
267 | int | 247 | int process_arguments(int argc, char **argv) { |
268 | process_arguments (int argc, char **argv) | 248 | static struct option longopts[] = {{"hostname", required_argument, 0, 'H'}, {"IPaddress", required_argument, 0, 'I'}, |
269 | { | 249 | {"expect", required_argument, 0, 'e'}, {"url", required_argument, 0, 'u'}, |
270 | int c; | 250 | {"port", required_argument, 0, 'p'}, {"critical", required_argument, 0, 'c'}, |
271 | 251 | {"warning", required_argument, 0, 'w'}, {"timeout", required_argument, 0, 't'}, | |
272 | int option = 0; | 252 | {"verbose", no_argument, 0, 'v'}, {"version", no_argument, 0, 'V'}, |
273 | static struct option longopts[] = { | 253 | {"help", no_argument, 0, 'h'}, {0, 0, 0, 0}}; |
274 | {"hostname", required_argument, 0, 'H'}, | ||
275 | {"IPaddress", required_argument, 0, 'I'}, | ||
276 | {"expect", required_argument, 0, 'e'}, | ||
277 | {"url", required_argument, 0, 'u'}, | ||
278 | {"port", required_argument, 0, 'p'}, | ||
279 | {"critical", required_argument, 0, 'c'}, | ||
280 | {"warning", required_argument, 0, 'w'}, | ||
281 | {"timeout", required_argument, 0, 't'}, | ||
282 | {"verbose", no_argument, 0, 'v'}, | ||
283 | {"version", no_argument, 0, 'V'}, | ||
284 | {"help", no_argument, 0, 'h'}, | ||
285 | {0, 0, 0, 0} | ||
286 | }; | ||
287 | 254 | ||
288 | if (argc < 2) | 255 | if (argc < 2) |
289 | return ERROR; | 256 | return ERROR; |
290 | 257 | ||
291 | for (c = 1; c < argc; c++) { | 258 | for (int i = 1; i < argc; i++) { |
292 | if (strcmp ("-to", argv[c]) == 0) | 259 | if (strcmp("-to", argv[i]) == 0) |
293 | strcpy (argv[c], "-t"); | 260 | strcpy(argv[i], "-t"); |
294 | else if (strcmp ("-wt", argv[c]) == 0) | 261 | else if (strcmp("-wt", argv[i]) == 0) |
295 | strcpy (argv[c], "-w"); | 262 | strcpy(argv[i], "-w"); |
296 | else if (strcmp ("-ct", argv[c]) == 0) | 263 | else if (strcmp("-ct", argv[i]) == 0) |
297 | strcpy (argv[c], "-c"); | 264 | strcpy(argv[i], "-c"); |
298 | } | 265 | } |
299 | 266 | ||
300 | while (1) { | 267 | int option_char; |
301 | c = getopt_long (argc, argv, "+hvVI:H:e:u:p:w:c:t:", longopts, | 268 | while (true) { |
302 | &option); | 269 | int option = 0; |
270 | option_char = getopt_long(argc, argv, "+hvVI:H:e:u:p:w:c:t:", longopts, &option); | ||
303 | 271 | ||
304 | if (c == -1 || c == EOF) | 272 | if (option_char == -1 || option_char == EOF) |
305 | break; | 273 | break; |
306 | 274 | ||
307 | switch (c) { | 275 | switch (option_char) { |
308 | case 'I': /* hostname */ | 276 | case 'I': /* hostname */ |
309 | case 'H': /* hostname */ | 277 | case 'H': /* hostname */ |
310 | if (server_address) | 278 | if (server_address) |
311 | break; | 279 | break; |
312 | else if (is_host (optarg)) | 280 | else if (is_host(optarg)) |
313 | server_address = optarg; | 281 | server_address = optarg; |
314 | else | 282 | else |
315 | usage2 (_("Invalid hostname/address"), optarg); | 283 | usage2(_("Invalid hostname/address"), optarg); |
316 | break; | 284 | break; |
317 | case 'e': /* string to expect in response header */ | 285 | case 'e': /* string to expect in response header */ |
318 | server_expect = optarg; | 286 | server_expect = optarg; |
319 | break; | 287 | break; |
320 | case 'u': /* server URL */ | 288 | case 'u': /* server URL */ |
321 | server_url = optarg; | 289 | server_url = optarg; |
322 | break; | 290 | break; |
323 | case 'p': /* port */ | 291 | case 'p': /* port */ |
324 | if (is_intpos (optarg)) { | 292 | if (is_intpos(optarg)) { |
325 | server_port = atoi (optarg); | 293 | server_port = atoi(optarg); |
326 | } | 294 | } else { |
327 | else { | 295 | usage4(_("Port must be a positive integer")); |
328 | usage4 (_("Port must be a positive integer")); | ||
329 | } | 296 | } |
330 | break; | 297 | break; |
331 | case 'w': /* warning time threshold */ | 298 | case 'w': /* warning time threshold */ |
332 | if (is_intnonneg (optarg)) { | 299 | if (is_intnonneg(optarg)) { |
333 | warning_time = atoi (optarg); | 300 | warning_time = atoi(optarg); |
334 | check_warning_time = true; | 301 | check_warning_time = true; |
335 | } | 302 | } else { |
336 | else { | 303 | usage4(_("Warning time must be a positive integer")); |
337 | usage4 (_("Warning time must be a positive integer")); | ||
338 | } | 304 | } |
339 | break; | 305 | break; |
340 | case 'c': /* critical time threshold */ | 306 | case 'c': /* critical time threshold */ |
341 | if (is_intnonneg (optarg)) { | 307 | if (is_intnonneg(optarg)) { |
342 | critical_time = atoi (optarg); | 308 | critical_time = atoi(optarg); |
343 | check_critical_time = true; | 309 | check_critical_time = true; |
344 | } | 310 | } else { |
345 | else { | 311 | usage4(_("Critical time must be a positive integer")); |
346 | usage4 (_("Critical time must be a positive integer")); | ||
347 | } | 312 | } |
348 | break; | 313 | break; |
349 | case 'v': /* verbose */ | 314 | case 'v': /* verbose */ |
350 | verbose = true; | 315 | verbose = true; |
351 | break; | 316 | break; |
352 | case 't': /* timeout */ | 317 | case 't': /* timeout */ |
353 | if (is_intnonneg (optarg)) { | 318 | if (is_intnonneg(optarg)) { |
354 | socket_timeout = atoi (optarg); | 319 | socket_timeout = atoi(optarg); |
355 | } | 320 | } else { |
356 | else { | 321 | usage4(_("Timeout interval must be a positive integer")); |
357 | usage4 (_("Timeout interval must be a positive integer")); | ||
358 | } | 322 | } |
359 | break; | 323 | break; |
360 | case 'V': /* version */ | 324 | case 'V': /* version */ |
361 | print_revision (progname, NP_VERSION); | 325 | print_revision(progname, NP_VERSION); |
362 | exit (STATE_UNKNOWN); | 326 | exit(STATE_UNKNOWN); |
363 | case 'h': /* help */ | 327 | case 'h': /* help */ |
364 | print_help (); | 328 | print_help(); |
365 | exit (STATE_UNKNOWN); | 329 | exit(STATE_UNKNOWN); |
366 | case '?': /* usage */ | 330 | case '?': /* usage */ |
367 | usage5 (); | 331 | usage5(); |
368 | } | 332 | } |
369 | } | 333 | } |
370 | 334 | ||
371 | c = optind; | 335 | option_char = optind; |
372 | if (server_address==NULL && argc>c) { | 336 | if (server_address == NULL && argc > option_char) { |
373 | if (is_host (argv[c])) { | 337 | if (is_host(argv[option_char])) { |
374 | server_address = argv[c++]; | 338 | server_address = argv[option_char++]; |
375 | } | 339 | } else { |
376 | else { | 340 | usage2(_("Invalid hostname/address"), argv[option_char]); |
377 | usage2 (_("Invalid hostname/address"), argv[c]); | ||
378 | } | 341 | } |
379 | } | 342 | } |
380 | 343 | ||
381 | if (server_address==NULL) | 344 | if (server_address == NULL) |
382 | usage4 (_("You must provide a server to check")); | 345 | usage4(_("You must provide a server to check")); |
383 | 346 | ||
384 | if (host_name==NULL) | 347 | if (host_name == NULL) |
385 | host_name = strdup (server_address); | 348 | host_name = strdup(server_address); |
386 | 349 | ||
387 | if (server_expect == NULL) | 350 | if (server_expect == NULL) |
388 | server_expect = strdup(EXPECT); | 351 | server_expect = strdup(EXPECT); |
389 | 352 | ||
390 | return validate_arguments (); | ||
391 | } | ||
392 | |||
393 | |||
394 | |||
395 | int | ||
396 | validate_arguments (void) | ||
397 | { | ||
398 | return OK; | 353 | return OK; |
399 | } | 354 | } |
400 | 355 | ||
401 | 356 | void print_help(void) { | |
402 | |||
403 | void | ||
404 | print_help (void) | ||
405 | { | ||
406 | char *myport; | 357 | char *myport; |
407 | xasprintf (&myport, "%d", PORT); | 358 | xasprintf(&myport, "%d", PORT); |
408 | 359 | ||
409 | print_revision (progname, NP_VERSION); | 360 | print_revision(progname, NP_VERSION); |
410 | 361 | ||
411 | printf ("Copyright (c) 1999 Pedro Leite <leite@cic.ua.pt>\n"); | 362 | printf("Copyright (c) 1999 Pedro Leite <leite@cic.ua.pt>\n"); |
412 | printf (COPYRIGHT, copyright, email); | 363 | printf(COPYRIGHT, copyright, email); |
413 | 364 | ||
414 | printf ("%s\n", _("This plugin tests the REAL service on the specified host.")); | 365 | printf("%s\n", _("This plugin tests the REAL service on the specified host.")); |
415 | 366 | ||
416 | printf ("\n\n"); | 367 | printf("\n\n"); |
417 | 368 | ||
418 | print_usage (); | 369 | print_usage(); |
419 | 370 | ||
420 | printf (UT_HELP_VRSN); | 371 | printf(UT_HELP_VRSN); |
421 | printf (UT_EXTRA_OPTS); | 372 | printf(UT_EXTRA_OPTS); |
422 | 373 | ||
423 | printf (UT_HOST_PORT, 'p', myport); | 374 | printf(UT_HOST_PORT, 'p', myport); |
424 | 375 | ||
425 | printf (" %s\n", "-u, --url=STRING"); | 376 | printf(" %s\n", "-u, --url=STRING"); |
426 | printf (" %s\n", _("Connect to this url")); | 377 | printf(" %s\n", _("Connect to this url")); |
427 | printf (" %s\n", "-e, --expect=STRING"); | 378 | printf(" %s\n", "-e, --expect=STRING"); |
428 | printf (_("String to expect in first line of server response (default: %s)\n"), | 379 | printf(_("String to expect in first line of server response (default: %s)\n"), EXPECT); |
429 | EXPECT); | ||
430 | 380 | ||
431 | printf (UT_WARN_CRIT); | 381 | printf(UT_WARN_CRIT); |
432 | 382 | ||
433 | printf (UT_CONN_TIMEOUT, DEFAULT_SOCKET_TIMEOUT); | 383 | printf(UT_CONN_TIMEOUT, DEFAULT_SOCKET_TIMEOUT); |
434 | 384 | ||
435 | printf (UT_VERBOSE); | 385 | printf(UT_VERBOSE); |
436 | 386 | ||
437 | printf ("\n"); | 387 | printf("\n"); |
438 | printf ("%s\n", _("This plugin will attempt to open an RTSP connection with the host.")); | 388 | printf("%s\n", _("This plugin will attempt to open an RTSP connection with the host.")); |
439 | printf ("%s\n", _("Successful connects return STATE_OK, refusals and timeouts return")); | 389 | printf("%s\n", _("Successful connects return STATE_OK, refusals and timeouts return")); |
440 | printf ("%s\n", _("STATE_CRITICAL, other errors return STATE_UNKNOWN. Successful connects,")); | 390 | printf("%s\n", _("STATE_CRITICAL, other errors return STATE_UNKNOWN. Successful connects,")); |
441 | printf ("%s\n", _("but incorrect response messages from the host result in STATE_WARNING return")); | 391 | printf("%s\n", _("but incorrect response messages from the host result in STATE_WARNING return")); |
442 | printf ("%s\n", _("values.")); | 392 | printf("%s\n", _("values.")); |
443 | 393 | ||
444 | printf (UT_SUPPORT); | 394 | printf(UT_SUPPORT); |
445 | } | 395 | } |
446 | 396 | ||
447 | 397 | void print_usage(void) { | |
448 | 398 | printf("%s\n", _("Usage:")); | |
449 | void | 399 | printf("%s -H host [-e expect] [-p port] [-w warn] [-c crit] [-t timeout] [-v]\n", progname); |
450 | print_usage (void) | ||
451 | { | ||
452 | printf ("%s\n", _("Usage:")); | ||
453 | printf ("%s -H host [-e expect] [-p port] [-w warn] [-c crit] [-t timeout] [-v]\n", progname); | ||
454 | } | 400 | } |