diff options
Diffstat (limited to 'plugins/check_real.c')
| -rw-r--r-- | plugins/check_real.c | 320 |
1 files changed, 203 insertions, 117 deletions
diff --git a/plugins/check_real.c b/plugins/check_real.c index ec0928ed..15c8a20c 100644 --- a/plugins/check_real.c +++ b/plugins/check_real.c | |||
| @@ -28,19 +28,21 @@ | |||
| 28 | * | 28 | * |
| 29 | *****************************************************************************/ | 29 | *****************************************************************************/ |
| 30 | 30 | ||
| 31 | #include "output.h" | ||
| 32 | #include "perfdata.h" | ||
| 31 | #include "states.h" | 33 | #include "states.h" |
| 32 | #include <stdio.h> | 34 | #include <stdio.h> |
| 33 | const char *progname = "check_real"; | ||
| 34 | const char *copyright = "2000-2024"; | ||
| 35 | const char *email = "devel@monitoring-plugins.org"; | ||
| 36 | |||
| 37 | #include "common.h" | 35 | #include "common.h" |
| 38 | #include "netutils.h" | 36 | #include "netutils.h" |
| 37 | #include "thresholds.h" | ||
| 39 | #include "utils.h" | 38 | #include "utils.h" |
| 40 | #include "check_real.d/config.h" | 39 | #include "check_real.d/config.h" |
| 41 | 40 | ||
| 42 | #define EXPECT "RTSP/1." | 41 | const char *progname = "check_real"; |
| 43 | #define URL "" | 42 | const char *copyright = "2000-2024"; |
| 43 | const char *email = "devel@monitoring-plugins.org"; | ||
| 44 | |||
| 45 | #define URL "" | ||
| 44 | 46 | ||
| 45 | typedef struct { | 47 | typedef struct { |
| 46 | int errorcode; | 48 | int errorcode; |
| @@ -68,41 +70,68 @@ int main(int argc, char **argv) { | |||
| 68 | 70 | ||
| 69 | const check_real_config config = tmp_config.config; | 71 | const check_real_config config = tmp_config.config; |
| 70 | 72 | ||
| 73 | if (config.output_format_is_set) { | ||
| 74 | mp_set_format(config.output_format); | ||
| 75 | } | ||
| 76 | |||
| 71 | /* initialize alarm signal handling */ | 77 | /* initialize alarm signal handling */ |
| 72 | signal(SIGALRM, socket_timeout_alarm_handler); | 78 | signal(SIGALRM, socket_timeout_alarm_handler); |
| 73 | 79 | ||
| 74 | /* set socket timeout */ | 80 | /* set socket timeout */ |
| 75 | alarm(socket_timeout); | 81 | alarm(socket_timeout); |
| 82 | time_t start_time; | ||
| 76 | time(&start_time); | 83 | time(&start_time); |
| 77 | 84 | ||
| 85 | mp_check overall = mp_check_init(); | ||
| 86 | mp_subcheck sc_connect = mp_subcheck_init(); | ||
| 87 | |||
| 78 | /* try to connect to the host at the given port number */ | 88 | /* try to connect to the host at the given port number */ |
| 79 | int socket; | 89 | int socket; |
| 80 | if (my_tcp_connect(config.server_address, config.server_port, &socket) != STATE_OK) { | 90 | if (my_tcp_connect(config.server_address, config.server_port, &socket) != STATE_OK) { |
| 81 | die(STATE_CRITICAL, _("Unable to connect to %s on port %d\n"), config.server_address, config.server_port); | 91 | xasprintf(&sc_connect.output, _("unable to connect to %s on port %d"), |
| 92 | config.server_address, config.server_port); | ||
| 93 | sc_connect = mp_set_subcheck_state(sc_connect, STATE_CRITICAL); | ||
| 94 | mp_add_subcheck_to_check(&overall, sc_connect); | ||
| 95 | mp_exit(overall); | ||
| 82 | } | 96 | } |
| 83 | 97 | ||
| 98 | xasprintf(&sc_connect.output, _("connected to %s on port %d"), config.server_address, | ||
| 99 | config.server_port); | ||
| 100 | sc_connect = mp_set_subcheck_state(sc_connect, STATE_OK); | ||
| 101 | mp_add_subcheck_to_check(&overall, sc_connect); | ||
| 102 | |||
| 84 | /* Part I - Server Check */ | 103 | /* Part I - Server Check */ |
| 104 | mp_subcheck sc_send = mp_subcheck_init(); | ||
| 85 | 105 | ||
| 86 | /* send the OPTIONS request */ | 106 | /* send the OPTIONS request */ |
| 87 | char buffer[MAX_INPUT_BUFFER]; | 107 | char buffer[MAX_INPUT_BUFFER]; |
| 88 | sprintf(buffer, "OPTIONS rtsp://%s:%d RTSP/1.0\r\n", config.host_name, config.server_port); | 108 | sprintf(buffer, "OPTIONS rtsp://%s:%d RTSP/1.0\r\n", config.host_name, config.server_port); |
| 89 | ssize_t sent_bytes = send(socket, buffer, strlen(buffer), 0); | 109 | ssize_t sent_bytes = send(socket, buffer, strlen(buffer), 0); |
| 90 | if (sent_bytes == -1) { | 110 | if (sent_bytes == -1) { |
| 91 | die(STATE_CRITICAL, _("Sending options to %s failed\n"), config.host_name); | 111 | xasprintf(&sc_send.output, _("Sending options to %s failed"), config.host_name); |
| 112 | sc_send = mp_set_subcheck_state(sc_send, STATE_CRITICAL); | ||
| 113 | mp_add_subcheck_to_check(&overall, sc_send); | ||
| 114 | mp_exit(overall); | ||
| 92 | } | 115 | } |
| 93 | 116 | ||
| 94 | /* send the header sync */ | 117 | /* send the header sync */ |
| 95 | sprintf(buffer, "CSeq: 1\r\n"); | 118 | sprintf(buffer, "CSeq: 1\r\n"); |
| 96 | sent_bytes = send(socket, buffer, strlen(buffer), 0); | 119 | sent_bytes = send(socket, buffer, strlen(buffer), 0); |
| 97 | if (sent_bytes == -1) { | 120 | if (sent_bytes == -1) { |
| 98 | die(STATE_CRITICAL, _("Sending header sync to %s failed\n"), config.host_name); | 121 | xasprintf(&sc_send.output, _("Sending header sync to %s failed"), config.host_name); |
| 122 | sc_send = mp_set_subcheck_state(sc_send, STATE_CRITICAL); | ||
| 123 | mp_add_subcheck_to_check(&overall, sc_send); | ||
| 124 | mp_exit(overall); | ||
| 99 | } | 125 | } |
| 100 | 126 | ||
| 101 | /* send a newline so the server knows we're done with the request */ | 127 | /* send a newline so the server knows we're done with the request */ |
| 102 | sprintf(buffer, "\r\n"); | 128 | sprintf(buffer, "\r\n"); |
| 103 | sent_bytes = send(socket, buffer, strlen(buffer), 0); | 129 | sent_bytes = send(socket, buffer, strlen(buffer), 0); |
| 104 | if (sent_bytes == -1) { | 130 | if (sent_bytes == -1) { |
| 105 | die(STATE_CRITICAL, _("Sending newline to %s failed\n"), config.host_name); | 131 | xasprintf(&sc_send.output, _("Sending newline to %s failed"), config.host_name); |
| 132 | sc_send = mp_set_subcheck_state(sc_send, STATE_CRITICAL); | ||
| 133 | mp_add_subcheck_to_check(&overall, sc_send); | ||
| 134 | mp_exit(overall); | ||
| 106 | } | 135 | } |
| 107 | 136 | ||
| 108 | /* watch for the REAL connection string */ | 137 | /* watch for the REAL connection string */ |
| @@ -110,156 +139,191 @@ int main(int argc, char **argv) { | |||
| 110 | 139 | ||
| 111 | /* return a CRITICAL status if we couldn't read any data */ | 140 | /* return a CRITICAL status if we couldn't read any data */ |
| 112 | if (received_bytes == -1) { | 141 | if (received_bytes == -1) { |
| 113 | die(STATE_CRITICAL, _("No data received from %s\n"), config.host_name); | 142 | xasprintf(&sc_send.output, _("No data received from %s"), config.host_name); |
| 143 | sc_send = mp_set_subcheck_state(sc_send, STATE_CRITICAL); | ||
| 144 | mp_add_subcheck_to_check(&overall, sc_send); | ||
| 145 | mp_exit(overall); | ||
| 114 | } | 146 | } |
| 115 | 147 | ||
| 116 | mp_state_enum result = STATE_OK; | 148 | time_t end_time; |
| 117 | char *status_line = NULL; | 149 | { |
| 118 | /* make sure we find the response we are looking for */ | 150 | mp_subcheck sc_options_request = mp_subcheck_init(); |
| 119 | if (!strstr(buffer, config.server_expect)) { | 151 | mp_state_enum options_result = STATE_OK; |
| 120 | if (config.server_port == PORT) { | 152 | /* make sure we find the response we are looking for */ |
| 121 | printf("%s\n", _("Invalid REAL response received from host")); | 153 | if (!strstr(buffer, config.server_expect)) { |
| 154 | if (config.server_port == PORT) { | ||
| 155 | xasprintf(&sc_options_request.output, "invalid REAL response received from host"); | ||
| 156 | } else { | ||
| 157 | xasprintf(&sc_options_request.output, | ||
| 158 | "invalid REAL response received from host on port %d", | ||
| 159 | config.server_port); | ||
| 160 | } | ||
| 122 | } else { | 161 | } else { |
| 123 | printf(_("Invalid REAL response received from host on port %d\n"), config.server_port); | 162 | /* else we got the REAL string, so check the return code */ |
| 124 | } | 163 | time(&end_time); |
| 125 | } else { | ||
| 126 | /* else we got the REAL string, so check the return code */ | ||
| 127 | 164 | ||
| 128 | time(&end_time); | 165 | options_result = STATE_OK; |
| 129 | 166 | ||
| 130 | result = STATE_OK; | 167 | char *status_line = strtok(buffer, "\n"); |
| 168 | xasprintf(&sc_options_request.output, "status line: %s", status_line); | ||
| 131 | 169 | ||
| 132 | status_line = strtok(buffer, "\n"); | 170 | if (strstr(status_line, "200")) { |
| 133 | 171 | options_result = STATE_OK; | |
| 134 | if (strstr(status_line, "200")) { | 172 | } |
| 135 | result = STATE_OK; | 173 | /* client errors options_result in a warning state */ |
| 174 | else if (strstr(status_line, "400")) { | ||
| 175 | options_result = STATE_WARNING; | ||
| 176 | } else if (strstr(status_line, "401")) { | ||
| 177 | options_result = STATE_WARNING; | ||
| 178 | } else if (strstr(status_line, "402")) { | ||
| 179 | options_result = STATE_WARNING; | ||
| 180 | } else if (strstr(status_line, "403")) { | ||
| 181 | options_result = STATE_WARNING; | ||
| 182 | } else if (strstr(status_line, "404")) { | ||
| 183 | options_result = STATE_WARNING; | ||
| 184 | } else if (strstr(status_line, "500")) { | ||
| 185 | /* server errors options_result in a critical state */ | ||
| 186 | options_result = STATE_CRITICAL; | ||
| 187 | } else if (strstr(status_line, "501")) { | ||
| 188 | options_result = STATE_CRITICAL; | ||
| 189 | } else if (strstr(status_line, "502")) { | ||
| 190 | options_result = STATE_CRITICAL; | ||
| 191 | } else if (strstr(status_line, "503")) { | ||
| 192 | options_result = STATE_CRITICAL; | ||
| 193 | } else { | ||
| 194 | options_result = STATE_UNKNOWN; | ||
| 195 | } | ||
| 136 | } | 196 | } |
| 137 | 197 | ||
| 138 | /* client errors result in a warning state */ | 198 | sc_options_request = mp_set_subcheck_state(sc_options_request, options_result); |
| 139 | else if (strstr(status_line, "400")) { | 199 | mp_add_subcheck_to_check(&overall, sc_options_request); |
| 140 | result = STATE_WARNING; | 200 | |
| 141 | } else if (strstr(status_line, "401")) { | 201 | if (options_result != STATE_OK) { |
| 142 | result = STATE_WARNING; | 202 | // exit here if Setting options already failed |
| 143 | } else if (strstr(status_line, "402")) { | 203 | mp_exit(overall); |
| 144 | result = STATE_WARNING; | ||
| 145 | } else if (strstr(status_line, "403")) { | ||
| 146 | result = STATE_WARNING; | ||
| 147 | } else if (strstr(status_line, "404")) { | ||
| 148 | result = STATE_WARNING; | ||
| 149 | } else if (strstr(status_line, "500")) { | ||
| 150 | /* server errors result in a critical state */ | ||
| 151 | result = STATE_CRITICAL; | ||
| 152 | } else if (strstr(status_line, "501")) { | ||
| 153 | result = STATE_CRITICAL; | ||
| 154 | } else if (strstr(status_line, "502")) { | ||
| 155 | result = STATE_CRITICAL; | ||
| 156 | } else if (strstr(status_line, "503")) { | ||
| 157 | result = STATE_CRITICAL; | ||
| 158 | } else { | ||
| 159 | result = STATE_UNKNOWN; | ||
| 160 | } | 204 | } |
| 161 | } | 205 | } |
| 162 | 206 | ||
| 163 | /* Part II - Check stream exists and is ok */ | 207 | /* Part II - Check stream exists and is ok */ |
| 164 | if ((result == STATE_OK) && (config.server_url != NULL)) { | 208 | if (config.server_url != NULL) { |
| 165 | |||
| 166 | /* Part I - Server Check */ | 209 | /* Part I - Server Check */ |
| 210 | mp_subcheck sc_describe = mp_subcheck_init(); | ||
| 167 | 211 | ||
| 168 | /* send the DESCRIBE request */ | 212 | /* send the DESCRIBE request */ |
| 169 | sprintf(buffer, "DESCRIBE rtsp://%s:%d%s RTSP/1.0\r\n", config.host_name, config.server_port, config.server_url); | 213 | sprintf(buffer, "DESCRIBE rtsp://%s:%d%s RTSP/1.0\r\n", config.host_name, |
| 214 | config.server_port, config.server_url); | ||
| 170 | 215 | ||
| 171 | ssize_t sent_bytes = send(socket, buffer, strlen(buffer), 0); | 216 | ssize_t sent_bytes = send(socket, buffer, strlen(buffer), 0); |
| 172 | if (sent_bytes == -1) { | 217 | if (sent_bytes == -1) { |
| 173 | die(STATE_CRITICAL, _("Sending DESCRIBE request to %s failed\n"), config.host_name); | 218 | sc_describe = mp_set_subcheck_state(sc_describe, STATE_CRITICAL); |
| 219 | xasprintf(&sc_describe.output, "sending DESCRIBE request to %s failed", | ||
| 220 | config.host_name); | ||
| 221 | mp_add_subcheck_to_check(&overall, sc_describe); | ||
| 222 | mp_exit(overall); | ||
| 174 | } | 223 | } |
| 175 | 224 | ||
| 176 | /* send the header sync */ | 225 | /* send the header sync */ |
| 177 | sprintf(buffer, "CSeq: 2\r\n"); | 226 | sprintf(buffer, "CSeq: 2\r\n"); |
| 178 | sent_bytes = send(socket, buffer, strlen(buffer), 0); | 227 | sent_bytes = send(socket, buffer, strlen(buffer), 0); |
| 179 | if (sent_bytes == -1) { | 228 | if (sent_bytes == -1) { |
| 180 | die(STATE_CRITICAL, _("Sending DESCRIBE request to %s failed\n"), config.host_name); | 229 | sc_describe = mp_set_subcheck_state(sc_describe, STATE_CRITICAL); |
| 230 | xasprintf(&sc_describe.output, "sending DESCRIBE request to %s failed", | ||
| 231 | config.host_name); | ||
| 232 | mp_add_subcheck_to_check(&overall, sc_describe); | ||
| 233 | mp_exit(overall); | ||
| 181 | } | 234 | } |
| 182 | 235 | ||
| 183 | /* send a newline so the server knows we're done with the request */ | 236 | /* send a newline so the server knows we're done with the request */ |
| 184 | sprintf(buffer, "\r\n"); | 237 | sprintf(buffer, "\r\n"); |
| 185 | sent_bytes = send(socket, buffer, strlen(buffer), 0); | 238 | sent_bytes = send(socket, buffer, strlen(buffer), 0); |
| 186 | if (sent_bytes == -1) { | 239 | if (sent_bytes == -1) { |
| 187 | die(STATE_CRITICAL, _("Sending DESCRIBE request to %s failed\n"), config.host_name); | 240 | sc_describe = mp_set_subcheck_state(sc_describe, STATE_CRITICAL); |
| 241 | xasprintf(&sc_describe.output, "sending DESCRIBE request to %s failed", | ||
| 242 | config.host_name); | ||
| 243 | mp_add_subcheck_to_check(&overall, sc_describe); | ||
| 244 | mp_exit(overall); | ||
| 188 | } | 245 | } |
| 189 | 246 | ||
| 190 | /* watch for the REAL connection string */ | 247 | /* watch for the REAL connection string */ |
| 191 | ssize_t recv_bytes = recv(socket, buffer, MAX_INPUT_BUFFER - 1, 0); | 248 | ssize_t recv_bytes = recv(socket, buffer, MAX_INPUT_BUFFER - 1, 0); |
| 192 | if (recv_bytes == -1) { | 249 | if (recv_bytes == -1) { |
| 193 | /* return a CRITICAL status if we couldn't read any data */ | 250 | /* return a CRITICAL status if we couldn't read any data */ |
| 194 | printf(_("No data received from host\n")); | 251 | sc_describe = mp_set_subcheck_state(sc_describe, STATE_CRITICAL); |
| 195 | result = STATE_CRITICAL; | 252 | xasprintf(&sc_describe.output, "No data received from host on DESCRIBE request"); |
| 253 | mp_add_subcheck_to_check(&overall, sc_describe); | ||
| 254 | mp_exit(overall); | ||
| 196 | } else { | 255 | } else { |
| 197 | buffer[result] = '\0'; /* null terminate received buffer */ | 256 | buffer[recv_bytes] = '\0'; /* null terminate received buffer */ |
| 198 | /* make sure we find the response we are looking for */ | 257 | /* make sure we find the response we are looking for */ |
| 199 | if (!strstr(buffer, config.server_expect)) { | 258 | if (!strstr(buffer, config.server_expect)) { |
| 200 | if (config.server_port == PORT) { | 259 | if (config.server_port == PORT) { |
| 201 | printf("%s\n", _("Invalid REAL response received from host")); | 260 | xasprintf(&sc_describe.output, "invalid REAL response received from host"); |
| 202 | } else { | 261 | } else { |
| 203 | printf(_("Invalid REAL response received from host on port %d\n"), config.server_port); | 262 | xasprintf(&sc_describe.output, |
| 263 | "invalid REAL response received from host on port %d", | ||
| 264 | config.server_port); | ||
| 204 | } | 265 | } |
| 205 | } else { | ||
| 206 | 266 | ||
| 267 | sc_describe = mp_set_subcheck_state(sc_describe, STATE_UNKNOWN); | ||
| 268 | mp_add_subcheck_to_check(&overall, sc_describe); | ||
| 269 | mp_exit(overall); | ||
| 270 | } else { | ||
| 207 | /* else we got the REAL string, so check the return code */ | 271 | /* else we got the REAL string, so check the return code */ |
| 208 | 272 | ||
| 209 | time(&end_time); | 273 | time(&end_time); |
| 210 | 274 | ||
| 211 | result = STATE_OK; | 275 | char *status_line = strtok(buffer, "\n"); |
| 212 | 276 | xasprintf(&sc_describe.output, "status line: %s", status_line); | |
| 213 | status_line = strtok(buffer, "\n"); | ||
| 214 | 277 | ||
| 278 | mp_state_enum describe_result; | ||
| 215 | if (strstr(status_line, "200")) { | 279 | if (strstr(status_line, "200")) { |
| 216 | result = STATE_OK; | 280 | describe_result = STATE_OK; |
| 217 | } | 281 | } |
| 218 | 282 | /* client errors describe_result in a warning state */ | |
| 219 | /* client errors result in a warning state */ | ||
| 220 | else if (strstr(status_line, "400")) { | 283 | else if (strstr(status_line, "400")) { |
| 221 | result = STATE_WARNING; | 284 | describe_result = STATE_WARNING; |
| 222 | } else if (strstr(status_line, "401")) { | 285 | } else if (strstr(status_line, "401")) { |
| 223 | result = STATE_WARNING; | 286 | describe_result = STATE_WARNING; |
| 224 | } else if (strstr(status_line, "402")) { | 287 | } else if (strstr(status_line, "402")) { |
| 225 | result = STATE_WARNING; | 288 | describe_result = STATE_WARNING; |
| 226 | } else if (strstr(status_line, "403")) { | 289 | } else if (strstr(status_line, "403")) { |
| 227 | result = STATE_WARNING; | 290 | describe_result = STATE_WARNING; |
| 228 | } else if (strstr(status_line, "404")) { | 291 | } else if (strstr(status_line, "404")) { |
| 229 | result = STATE_WARNING; | 292 | describe_result = STATE_WARNING; |
| 230 | } | 293 | } |
| 231 | 294 | /* server errors describe_result in a critical state */ | |
| 232 | /* server errors result in a critical state */ | ||
| 233 | else if (strstr(status_line, "500")) { | 295 | else if (strstr(status_line, "500")) { |
| 234 | result = STATE_CRITICAL; | 296 | describe_result = STATE_CRITICAL; |
| 235 | } else if (strstr(status_line, "501")) { | 297 | } else if (strstr(status_line, "501")) { |
| 236 | result = STATE_CRITICAL; | 298 | describe_result = STATE_CRITICAL; |
| 237 | } else if (strstr(status_line, "502")) { | 299 | } else if (strstr(status_line, "502")) { |
| 238 | result = STATE_CRITICAL; | 300 | describe_result = STATE_CRITICAL; |
| 239 | } else if (strstr(status_line, "503")) { | 301 | } else if (strstr(status_line, "503")) { |
| 240 | result = STATE_CRITICAL; | 302 | describe_result = STATE_CRITICAL; |
| 303 | } else { | ||
| 304 | describe_result = STATE_UNKNOWN; | ||
| 241 | } | 305 | } |
| 242 | 306 | ||
| 243 | else { | 307 | sc_describe = mp_set_subcheck_state(sc_describe, describe_result); |
| 244 | result = STATE_UNKNOWN; | 308 | mp_add_subcheck_to_check(&overall, sc_describe); |
| 245 | } | ||
| 246 | } | 309 | } |
| 247 | } | 310 | } |
| 248 | } | 311 | } |
| 249 | 312 | ||
| 250 | /* Return results */ | 313 | /* Return results */ |
| 251 | if (result == STATE_OK) { | 314 | mp_subcheck sc_timing = mp_subcheck_init(); |
| 252 | if (config.check_critical_time && (end_time - start_time) > config.critical_time) { | 315 | xasprintf(&sc_timing.output, "response time: %lds", end_time - start_time); |
| 253 | result = STATE_CRITICAL; | 316 | sc_timing = mp_set_subcheck_default_state(sc_timing, STATE_OK); |
| 254 | } else if (config.check_warning_time && (end_time - start_time) > config.warning_time) { | ||
| 255 | result = STATE_WARNING; | ||
| 256 | } | ||
| 257 | 317 | ||
| 258 | /* Put some HTML in here to create a dynamic link */ | 318 | mp_perfdata pd_response_time = perfdata_init(); |
| 259 | printf(_("REAL %s - %d second response time\n"), state_text(result), (int)(end_time - start_time)); | 319 | pd_response_time = mp_set_pd_value(pd_response_time, (end_time - start_time)); |
| 260 | } else { | 320 | pd_response_time.label = "response_time"; |
| 261 | printf("%s\n", status_line); | 321 | pd_response_time.uom = "s"; |
| 262 | } | 322 | pd_response_time = mp_pd_set_thresholds(pd_response_time, config.time_thresholds); |
| 323 | mp_add_perfdata_to_subcheck(&sc_connect, pd_response_time); | ||
| 324 | sc_timing = mp_set_subcheck_state(sc_timing, mp_get_pd_status(pd_response_time)); | ||
| 325 | |||
| 326 | mp_add_subcheck_to_check(&overall, sc_timing); | ||
| 263 | 327 | ||
| 264 | /* close the connection */ | 328 | /* close the connection */ |
| 265 | close(socket); | 329 | close(socket); |
| @@ -267,17 +331,28 @@ int main(int argc, char **argv) { | |||
| 267 | /* reset the alarm */ | 331 | /* reset the alarm */ |
| 268 | alarm(0); | 332 | alarm(0); |
| 269 | 333 | ||
| 270 | exit(result); | 334 | mp_exit(overall); |
| 271 | } | 335 | } |
| 272 | 336 | ||
| 273 | /* process command-line arguments */ | 337 | /* process command-line arguments */ |
| 274 | check_real_config_wrapper process_arguments(int argc, char **argv) { | 338 | check_real_config_wrapper process_arguments(int argc, char **argv) { |
| 275 | static struct option longopts[] = {{"hostname", required_argument, 0, 'H'}, {"IPaddress", required_argument, 0, 'I'}, | 339 | enum { |
| 276 | {"expect", required_argument, 0, 'e'}, {"url", required_argument, 0, 'u'}, | 340 | output_format_index = CHAR_MAX + 1, |
| 277 | {"port", required_argument, 0, 'p'}, {"critical", required_argument, 0, 'c'}, | 341 | }; |
| 278 | {"warning", required_argument, 0, 'w'}, {"timeout", required_argument, 0, 't'}, | 342 | |
| 279 | {"verbose", no_argument, 0, 'v'}, {"version", no_argument, 0, 'V'}, | 343 | static struct option longopts[] = {{"hostname", required_argument, 0, 'H'}, |
| 280 | {"help", no_argument, 0, 'h'}, {0, 0, 0, 0}}; | 344 | {"IPaddress", required_argument, 0, 'I'}, |
| 345 | {"expect", required_argument, 0, 'e'}, | ||
| 346 | {"url", required_argument, 0, 'u'}, | ||
| 347 | {"port", required_argument, 0, 'p'}, | ||
| 348 | {"critical", required_argument, 0, 'c'}, | ||
| 349 | {"warning", required_argument, 0, 'w'}, | ||
| 350 | {"timeout", required_argument, 0, 't'}, | ||
| 351 | {"verbose", no_argument, 0, 'v'}, | ||
| 352 | {"version", no_argument, 0, 'V'}, | ||
| 353 | {"help", no_argument, 0, 'h'}, | ||
| 354 | {"output-format", required_argument, 0, output_format_index}, | ||
| 355 | {0, 0, 0, 0}}; | ||
| 281 | 356 | ||
| 282 | check_real_config_wrapper result = { | 357 | check_real_config_wrapper result = { |
| 283 | .errorcode = OK, | 358 | .errorcode = OK, |
| @@ -332,21 +407,23 @@ check_real_config_wrapper process_arguments(int argc, char **argv) { | |||
| 332 | } | 407 | } |
| 333 | break; | 408 | break; |
| 334 | case 'w': /* warning time threshold */ | 409 | case 'w': /* warning time threshold */ |
| 335 | if (is_intnonneg(optarg)) { | 410 | { |
| 336 | result.config.warning_time = atoi(optarg); | 411 | mp_range_parsed critical_range = mp_parse_range_string(optarg); |
| 337 | result.config.check_warning_time = true; | 412 | if (critical_range.error != MP_PARSING_SUCCES) { |
| 338 | } else { | 413 | die(STATE_UNKNOWN, "failed to parse warning threshold: %s", optarg); |
| 339 | usage4(_("Warning time must be a positive integer")); | ||
| 340 | } | 414 | } |
| 341 | break; | 415 | result.config.time_thresholds = |
| 416 | mp_thresholds_set_warn(result.config.time_thresholds, critical_range.range); | ||
| 417 | } break; | ||
| 342 | case 'c': /* critical time threshold */ | 418 | case 'c': /* critical time threshold */ |
| 343 | if (is_intnonneg(optarg)) { | 419 | { |
| 344 | result.config.critical_time = atoi(optarg); | 420 | mp_range_parsed critical_range = mp_parse_range_string(optarg); |
| 345 | result.config.check_critical_time = true; | 421 | if (critical_range.error != MP_PARSING_SUCCES) { |
| 346 | } else { | 422 | die(STATE_UNKNOWN, "failed to parse critical threshold: %s", optarg); |
| 347 | usage4(_("Critical time must be a positive integer")); | ||
| 348 | } | 423 | } |
| 349 | break; | 424 | result.config.time_thresholds = |
| 425 | mp_thresholds_set_crit(result.config.time_thresholds, critical_range.range); | ||
| 426 | } break; | ||
| 350 | case 'v': /* verbose */ | 427 | case 'v': /* verbose */ |
| 351 | verbose = true; | 428 | verbose = true; |
| 352 | break; | 429 | break; |
| @@ -363,6 +440,18 @@ check_real_config_wrapper process_arguments(int argc, char **argv) { | |||
| 363 | case 'h': /* help */ | 440 | case 'h': /* help */ |
| 364 | print_help(); | 441 | print_help(); |
| 365 | exit(STATE_UNKNOWN); | 442 | exit(STATE_UNKNOWN); |
| 443 | case output_format_index: { | ||
| 444 | parsed_output_format parser = mp_parse_output_format(optarg); | ||
| 445 | if (!parser.parsing_success) { | ||
| 446 | // TODO List all available formats here, maybe add anothoer usage function | ||
| 447 | printf("Invalid output format: %s\n", optarg); | ||
| 448 | exit(STATE_UNKNOWN); | ||
| 449 | } | ||
| 450 | |||
| 451 | result.config.output_format_is_set = true; | ||
| 452 | result.config.output_format = parser.output_format; | ||
| 453 | break; | ||
| 454 | } | ||
| 366 | case '?': /* usage */ | 455 | case '?': /* usage */ |
| 367 | usage5(); | 456 | usage5(); |
| 368 | } | 457 | } |
| @@ -385,10 +474,6 @@ check_real_config_wrapper process_arguments(int argc, char **argv) { | |||
| 385 | result.config.host_name = strdup(result.config.server_address); | 474 | result.config.host_name = strdup(result.config.server_address); |
| 386 | } | 475 | } |
| 387 | 476 | ||
| 388 | if (result.config.server_expect == NULL) { | ||
| 389 | result.config.server_expect = strdup(EXPECT); | ||
| 390 | } | ||
| 391 | |||
| 392 | return result; | 477 | return result; |
| 393 | } | 478 | } |
| 394 | 479 | ||
| @@ -415,7 +500,7 @@ void print_help(void) { | |||
| 415 | printf(" %s\n", "-u, --url=STRING"); | 500 | printf(" %s\n", "-u, --url=STRING"); |
| 416 | printf(" %s\n", _("Connect to this url")); | 501 | printf(" %s\n", _("Connect to this url")); |
| 417 | printf(" %s\n", "-e, --expect=STRING"); | 502 | printf(" %s\n", "-e, --expect=STRING"); |
| 418 | printf(_("String to expect in first line of server response (default: %s)\n"), EXPECT); | 503 | printf(_("String to expect in first line of server response (default: %s)\n"), default_expect); |
| 419 | 504 | ||
| 420 | printf(UT_WARN_CRIT); | 505 | printf(UT_WARN_CRIT); |
| 421 | 506 | ||
| @@ -427,7 +512,8 @@ void print_help(void) { | |||
| 427 | printf("%s\n", _("This plugin will attempt to open an RTSP connection with the host.")); | 512 | printf("%s\n", _("This plugin will attempt to open an RTSP connection with the host.")); |
| 428 | printf("%s\n", _("Successful connects return STATE_OK, refusals and timeouts return")); | 513 | printf("%s\n", _("Successful connects return STATE_OK, refusals and timeouts return")); |
| 429 | printf("%s\n", _("STATE_CRITICAL, other errors return STATE_UNKNOWN. Successful connects,")); | 514 | printf("%s\n", _("STATE_CRITICAL, other errors return STATE_UNKNOWN. Successful connects,")); |
| 430 | printf("%s\n", _("but incorrect response messages from the host result in STATE_WARNING return")); | 515 | printf("%s\n", |
| 516 | _("but incorrect response messages from the host result in STATE_WARNING return")); | ||
| 431 | printf("%s\n", _("values.")); | 517 | printf("%s\n", _("values.")); |
| 432 | 518 | ||
| 433 | printf(UT_SUPPORT); | 519 | printf(UT_SUPPORT); |
