diff options
| -rw-r--r-- | plugins/check_real.c | 94 |
1 files changed, 44 insertions, 50 deletions
diff --git a/plugins/check_real.c b/plugins/check_real.c index 03ed6557..cfab26f5 100644 --- a/plugins/check_real.c +++ b/plugins/check_real.c | |||
| @@ -43,28 +43,22 @@ enum { | |||
| 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); | ||
| 49 | void print_usage(void); | 48 | void print_usage(void); |
| 50 | 49 | ||
| 51 | int server_port = PORT; | 50 | static int server_port = PORT; |
| 52 | char *server_address; | 51 | static char *server_address; |
| 53 | char *host_name; | 52 | static char *host_name; |
| 54 | char *server_url = NULL; | 53 | static char *server_url = NULL; |
| 55 | char *server_expect; | 54 | static char *server_expect; |
| 56 | int warning_time = 0; | 55 | static int warning_time = 0; |
| 57 | bool check_warning_time = false; | 56 | static bool check_warning_time = false; |
| 58 | int critical_time = 0; | 57 | static int critical_time = 0; |
| 59 | bool check_critical_time = false; | 58 | static bool check_critical_time = false; |
| 60 | bool verbose = false; | 59 | static bool verbose = false; |
| 61 | 60 | ||
| 62 | int main(int argc, char **argv) { | 61 | int main(int argc, char **argv) { |
| 63 | int sd; | ||
| 64 | int result = STATE_UNKNOWN; | ||
| 65 | char buffer[MAX_INPUT_BUFFER]; | ||
| 66 | char *status_line = NULL; | ||
| 67 | |||
| 68 | setlocale(LC_ALL, ""); | 62 | setlocale(LC_ALL, ""); |
| 69 | bindtextdomain(PACKAGE, LOCALEDIR); | 63 | bindtextdomain(PACKAGE, LOCALEDIR); |
| 70 | textdomain(PACKAGE); | 64 | textdomain(PACKAGE); |
| @@ -83,30 +77,33 @@ int main(int argc, char **argv) { | |||
| 83 | time(&start_time); | 77 | time(&start_time); |
| 84 | 78 | ||
| 85 | /* try to connect to the host at the given port number */ | 79 | /* try to connect to the host at the given port number */ |
| 86 | if (my_tcp_connect(server_address, server_port, &sd) != STATE_OK) | 80 | int socket; |
| 81 | if (my_tcp_connect(server_address, server_port, &socket) != STATE_OK) | ||
| 87 | die(STATE_CRITICAL, _("Unable to connect to %s on port %d\n"), server_address, server_port); | 82 | die(STATE_CRITICAL, _("Unable to connect to %s on port %d\n"), server_address, server_port); |
| 88 | 83 | ||
| 89 | /* Part I - Server Check */ | 84 | /* Part I - Server Check */ |
| 90 | 85 | ||
| 91 | /* send the OPTIONS request */ | 86 | /* send the OPTIONS request */ |
| 87 | char buffer[MAX_INPUT_BUFFER]; | ||
| 92 | sprintf(buffer, "OPTIONS rtsp://%s:%d RTSP/1.0\r\n", host_name, server_port); | 88 | sprintf(buffer, "OPTIONS rtsp://%s:%d RTSP/1.0\r\n", host_name, server_port); |
| 93 | result = send(sd, buffer, strlen(buffer), 0); | 89 | int result = send(socket, buffer, strlen(buffer), 0); |
| 94 | 90 | ||
| 95 | /* send the header sync */ | 91 | /* send the header sync */ |
| 96 | sprintf(buffer, "CSeq: 1\r\n"); | 92 | sprintf(buffer, "CSeq: 1\r\n"); |
| 97 | result = send(sd, buffer, strlen(buffer), 0); | 93 | result = send(socket, buffer, strlen(buffer), 0); |
| 98 | 94 | ||
| 99 | /* 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 */ |
| 100 | sprintf(buffer, "\r\n"); | 96 | sprintf(buffer, "\r\n"); |
| 101 | result = send(sd, buffer, strlen(buffer), 0); | 97 | result = send(socket, buffer, strlen(buffer), 0); |
| 102 | 98 | ||
| 103 | /* watch for the REAL connection string */ | 99 | /* watch for the REAL connection string */ |
| 104 | result = recv(sd, buffer, MAX_INPUT_BUFFER - 1, 0); | 100 | result = recv(socket, buffer, MAX_INPUT_BUFFER - 1, 0); |
| 105 | 101 | ||
| 106 | /* return a CRITICAL status if we couldn't read any data */ | 102 | /* return a CRITICAL status if we couldn't read any data */ |
| 107 | if (result == -1) | 103 | if (result == -1) |
| 108 | die(STATE_CRITICAL, _("No data received from %s\n"), host_name); | 104 | die(STATE_CRITICAL, _("No data received from %s\n"), host_name); |
| 109 | 105 | ||
| 106 | char *status_line = NULL; | ||
| 110 | /* make sure we find the response we are looking for */ | 107 | /* make sure we find the response we are looking for */ |
| 111 | if (!strstr(buffer, server_expect)) { | 108 | if (!strstr(buffer, server_expect)) { |
| 112 | if (server_port == PORT) | 109 | if (server_port == PORT) |
| @@ -158,18 +155,18 @@ int main(int argc, char **argv) { | |||
| 158 | 155 | ||
| 159 | /* send the DESCRIBE request */ | 156 | /* send the DESCRIBE request */ |
| 160 | sprintf(buffer, "DESCRIBE rtsp://%s:%d%s RTSP/1.0\r\n", host_name, server_port, server_url); | 157 | sprintf(buffer, "DESCRIBE rtsp://%s:%d%s RTSP/1.0\r\n", host_name, server_port, server_url); |
| 161 | result = send(sd, buffer, strlen(buffer), 0); | 158 | result = send(socket, buffer, strlen(buffer), 0); |
| 162 | 159 | ||
| 163 | /* send the header sync */ | 160 | /* send the header sync */ |
| 164 | sprintf(buffer, "CSeq: 2\r\n"); | 161 | sprintf(buffer, "CSeq: 2\r\n"); |
| 165 | result = send(sd, buffer, strlen(buffer), 0); | 162 | result = send(socket, buffer, strlen(buffer), 0); |
| 166 | 163 | ||
| 167 | /* 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 */ |
| 168 | sprintf(buffer, "\r\n"); | 165 | sprintf(buffer, "\r\n"); |
| 169 | result = send(sd, buffer, strlen(buffer), 0); | 166 | result = send(socket, buffer, strlen(buffer), 0); |
| 170 | 167 | ||
| 171 | /* watch for the REAL connection string */ | 168 | /* watch for the REAL connection string */ |
| 172 | result = recv(sd, buffer, MAX_INPUT_BUFFER - 1, 0); | 169 | result = recv(socket, buffer, MAX_INPUT_BUFFER - 1, 0); |
| 173 | buffer[result] = '\0'; /* null terminate received buffer */ | 170 | buffer[result] = '\0'; /* null terminate received buffer */ |
| 174 | 171 | ||
| 175 | /* return a CRITICAL status if we couldn't read any data */ | 172 | /* return a CRITICAL status if we couldn't read any data */ |
| @@ -238,7 +235,7 @@ int main(int argc, char **argv) { | |||
| 238 | printf("%s\n", status_line); | 235 | printf("%s\n", status_line); |
| 239 | 236 | ||
| 240 | /* close the connection */ | 237 | /* close the connection */ |
| 241 | close(sd); | 238 | close(socket); |
| 242 | 239 | ||
| 243 | /* reset the alarm */ | 240 | /* reset the alarm */ |
| 244 | alarm(0); | 241 | alarm(0); |
| @@ -248,9 +245,6 @@ int main(int argc, char **argv) { | |||
| 248 | 245 | ||
| 249 | /* process command-line arguments */ | 246 | /* process command-line arguments */ |
| 250 | int process_arguments(int argc, char **argv) { | 247 | int process_arguments(int argc, char **argv) { |
| 251 | int c; | ||
| 252 | |||
| 253 | int option = 0; | ||
| 254 | static struct option longopts[] = {{"hostname", required_argument, 0, 'H'}, {"IPaddress", required_argument, 0, 'I'}, | 248 | static struct option longopts[] = {{"hostname", required_argument, 0, 'H'}, {"IPaddress", required_argument, 0, 'I'}, |
| 255 | {"expect", required_argument, 0, 'e'}, {"url", required_argument, 0, 'u'}, | 249 | {"expect", required_argument, 0, 'e'}, {"url", required_argument, 0, 'u'}, |
| 256 | {"port", required_argument, 0, 'p'}, {"critical", required_argument, 0, 'c'}, | 250 | {"port", required_argument, 0, 'p'}, {"critical", required_argument, 0, 'c'}, |
| @@ -261,22 +255,24 @@ int process_arguments(int argc, char **argv) { | |||
| 261 | if (argc < 2) | 255 | if (argc < 2) |
| 262 | return ERROR; | 256 | return ERROR; |
| 263 | 257 | ||
| 264 | for (c = 1; c < argc; c++) { | 258 | for (int i = 1; i < argc; i++) { |
| 265 | if (strcmp("-to", argv[c]) == 0) | 259 | if (strcmp("-to", argv[i]) == 0) |
| 266 | strcpy(argv[c], "-t"); | 260 | strcpy(argv[i], "-t"); |
| 267 | else if (strcmp("-wt", argv[c]) == 0) | 261 | else if (strcmp("-wt", argv[i]) == 0) |
| 268 | strcpy(argv[c], "-w"); | 262 | strcpy(argv[i], "-w"); |
| 269 | else if (strcmp("-ct", argv[c]) == 0) | 263 | else if (strcmp("-ct", argv[i]) == 0) |
| 270 | strcpy(argv[c], "-c"); | 264 | strcpy(argv[i], "-c"); |
| 271 | } | 265 | } |
| 272 | 266 | ||
| 273 | while (1) { | 267 | int option_char; |
| 274 | c = getopt_long(argc, argv, "+hvVI:H:e:u:p:w:c:t:", longopts, &option); | 268 | while (true) { |
| 269 | int option = 0; | ||
| 270 | option_char = getopt_long(argc, argv, "+hvVI:H:e:u:p:w:c:t:", longopts, &option); | ||
| 275 | 271 | ||
| 276 | if (c == -1 || c == EOF) | 272 | if (option_char == -1 || option_char == EOF) |
| 277 | break; | 273 | break; |
| 278 | 274 | ||
| 279 | switch (c) { | 275 | switch (option_char) { |
| 280 | case 'I': /* hostname */ | 276 | case 'I': /* hostname */ |
| 281 | case 'H': /* hostname */ | 277 | case 'H': /* hostname */ |
| 282 | if (server_address) | 278 | if (server_address) |
| @@ -336,12 +332,12 @@ int process_arguments(int argc, char **argv) { | |||
| 336 | } | 332 | } |
| 337 | } | 333 | } |
| 338 | 334 | ||
| 339 | c = optind; | 335 | option_char = optind; |
| 340 | if (server_address == NULL && argc > c) { | 336 | if (server_address == NULL && argc > option_char) { |
| 341 | if (is_host(argv[c])) { | 337 | if (is_host(argv[option_char])) { |
| 342 | server_address = argv[c++]; | 338 | server_address = argv[option_char++]; |
| 343 | } else { | 339 | } else { |
| 344 | usage2(_("Invalid hostname/address"), argv[c]); | 340 | usage2(_("Invalid hostname/address"), argv[option_char]); |
| 345 | } | 341 | } |
| 346 | } | 342 | } |
| 347 | 343 | ||
| @@ -354,11 +350,9 @@ int process_arguments(int argc, char **argv) { | |||
| 354 | if (server_expect == NULL) | 350 | if (server_expect == NULL) |
| 355 | server_expect = strdup(EXPECT); | 351 | server_expect = strdup(EXPECT); |
| 356 | 352 | ||
| 357 | return validate_arguments(); | 353 | return OK; |
| 358 | } | 354 | } |
| 359 | 355 | ||
| 360 | int validate_arguments(void) { return OK; } | ||
| 361 | |||
| 362 | void print_help(void) { | 356 | void print_help(void) { |
| 363 | char *myport; | 357 | char *myport; |
| 364 | xasprintf(&myport, "%d", PORT); | 358 | xasprintf(&myport, "%d", PORT); |
