diff options
Diffstat (limited to 'plugins/check_time.c')
| -rw-r--r-- | plugins/check_time.c | 527 |
1 files changed, 254 insertions, 273 deletions
diff --git a/plugins/check_time.c b/plugins/check_time.c index f50ea427..fc9ba3f9 100644 --- a/plugins/check_time.c +++ b/plugins/check_time.c | |||
| @@ -1,374 +1,355 @@ | |||
| 1 | /***************************************************************************** | 1 | /***************************************************************************** |
| 2 | * | 2 | * |
| 3 | * Monitoring check_time plugin | 3 | * Monitoring check_time plugin |
| 4 | * | 4 | * |
| 5 | * License: GPL | 5 | * License: GPL |
| 6 | * Copyright (c) 1999-2007 Monitoring Plugins Development Team | 6 | * Copyright (c) 1999-2024 Monitoring Plugins Development Team |
| 7 | * | 7 | * |
| 8 | * Description: | 8 | * Description: |
| 9 | * | 9 | * |
| 10 | * This file contains the check_time plugin | 10 | * This file contains the check_time plugin |
| 11 | * | 11 | * |
| 12 | * This plugin will check the time difference with the specified host. | 12 | * This plugin will check the time difference with 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 | #include "states.h" | ||
| 31 | const char *progname = "check_time"; | 32 | const char *progname = "check_time"; |
| 32 | const char *copyright = "1999-2007"; | 33 | const char *copyright = "1999-2024"; |
| 33 | const char *email = "devel@monitoring-plugins.org"; | 34 | const char *email = "devel@monitoring-plugins.org"; |
| 34 | 35 | ||
| 35 | #include "common.h" | 36 | #include "common.h" |
| 36 | #include "netutils.h" | 37 | #include "netutils.h" |
| 37 | #include "utils.h" | 38 | #include "utils.h" |
| 39 | #include "check_time.d/config.h" | ||
| 40 | |||
| 41 | #define UNIX_EPOCH 2208988800UL | ||
| 42 | |||
| 43 | typedef struct { | ||
| 44 | int errorcode; | ||
| 45 | check_time_config config; | ||
| 46 | } check_time_config_wrapper; | ||
| 47 | static check_time_config_wrapper process_arguments(int /*argc*/, char ** /*argv*/); | ||
| 48 | static void print_help(void); | ||
| 49 | void print_usage(void); | ||
| 38 | 50 | ||
| 39 | enum { | 51 | int main(int argc, char **argv) { |
| 40 | TIME_PORT = 37 | 52 | setlocale(LC_ALL, ""); |
| 41 | }; | 53 | bindtextdomain(PACKAGE, LOCALEDIR); |
| 42 | 54 | textdomain(PACKAGE); | |
| 43 | #define UNIX_EPOCH 2208988800UL | ||
| 44 | |||
| 45 | uint32_t raw_server_time; | ||
| 46 | unsigned long server_time, diff_time; | ||
| 47 | int warning_time = 0; | ||
| 48 | bool check_warning_time = false; | ||
| 49 | int critical_time = 0; | ||
| 50 | bool check_critical_time = false; | ||
| 51 | unsigned long warning_diff = 0; | ||
| 52 | bool check_warning_diff = false; | ||
| 53 | unsigned long critical_diff = 0; | ||
| 54 | bool check_critical_diff = false; | ||
| 55 | int server_port = TIME_PORT; | ||
| 56 | char *server_address = NULL; | ||
| 57 | bool use_udp = false; | ||
| 58 | |||
| 59 | int process_arguments (int, char **); | ||
| 60 | void print_help (void); | ||
| 61 | void print_usage (void); | ||
| 62 | |||
| 63 | int | ||
| 64 | main (int argc, char **argv) | ||
| 65 | { | ||
| 66 | int sd; | ||
| 67 | int result = STATE_UNKNOWN; | ||
| 68 | time_t conntime; | ||
| 69 | |||
| 70 | setlocale (LC_ALL, ""); | ||
| 71 | bindtextdomain (PACKAGE, LOCALEDIR); | ||
| 72 | textdomain (PACKAGE); | ||
| 73 | 55 | ||
| 74 | /* Parse extra opts if any */ | 56 | /* Parse extra opts if any */ |
| 75 | argv=np_extra_opts (&argc, argv, progname); | 57 | argv = np_extra_opts(&argc, argv, progname); |
| 58 | |||
| 59 | check_time_config_wrapper tmp_config = process_arguments(argc, argv); | ||
| 60 | if (tmp_config.errorcode == ERROR) { | ||
| 61 | usage4(_("Could not parse arguments")); | ||
| 62 | } | ||
| 76 | 63 | ||
| 77 | if (process_arguments (argc, argv) == ERROR) | 64 | const check_time_config config = tmp_config.config; |
| 78 | usage4 (_("Could not parse arguments")); | ||
| 79 | 65 | ||
| 80 | /* initialize alarm signal handling */ | 66 | /* initialize alarm signal handling */ |
| 81 | signal (SIGALRM, socket_timeout_alarm_handler); | 67 | signal(SIGALRM, socket_timeout_alarm_handler); |
| 82 | 68 | ||
| 83 | /* set socket timeout */ | 69 | /* set socket timeout */ |
| 84 | alarm (socket_timeout); | 70 | alarm(socket_timeout); |
| 85 | time (&start_time); | 71 | time(&start_time); |
| 86 | 72 | ||
| 73 | int socket; | ||
| 74 | mp_state_enum result = STATE_UNKNOWN; | ||
| 87 | /* try to connect to the host at the given port number */ | 75 | /* try to connect to the host at the given port number */ |
| 88 | if (use_udp) { | 76 | if (config.use_udp) { |
| 89 | result = my_udp_connect (server_address, server_port, &sd); | 77 | result = my_udp_connect(config.server_address, config.server_port, &socket); |
| 90 | } else { | 78 | } else { |
| 91 | result = my_tcp_connect (server_address, server_port, &sd); | 79 | result = my_tcp_connect(config.server_address, config.server_port, &socket); |
| 92 | } | 80 | } |
| 93 | 81 | ||
| 94 | if (result != STATE_OK) { | 82 | if (result != STATE_OK) { |
| 95 | if (check_critical_time) | 83 | if (config.check_critical_time) { |
| 96 | result = STATE_CRITICAL; | 84 | result = STATE_CRITICAL; |
| 97 | else if (check_warning_time) | 85 | } else if (config.check_warning_time) { |
| 98 | result = STATE_WARNING; | 86 | result = STATE_WARNING; |
| 99 | else | 87 | } else { |
| 100 | result = STATE_UNKNOWN; | 88 | result = STATE_UNKNOWN; |
| 101 | die (result, | 89 | } |
| 102 | _("TIME UNKNOWN - could not connect to server %s, port %d\n"), | 90 | die(result, _("TIME UNKNOWN - could not connect to server %s, port %d\n"), |
| 103 | server_address, server_port); | 91 | config.server_address, config.server_port); |
| 104 | } | 92 | } |
| 105 | 93 | ||
| 106 | if (use_udp) { | 94 | if (config.use_udp) { |
| 107 | if (send (sd, "", 0, 0) < 0) { | 95 | if (send(socket, "", 0, 0) < 0) { |
| 108 | if (check_critical_time) | 96 | if (config.check_critical_time) { |
| 109 | result = STATE_CRITICAL; | 97 | result = STATE_CRITICAL; |
| 110 | else if (check_warning_time) | 98 | } else if (config.check_warning_time) { |
| 111 | result = STATE_WARNING; | 99 | result = STATE_WARNING; |
| 112 | else | 100 | } else { |
| 113 | result = STATE_UNKNOWN; | 101 | result = STATE_UNKNOWN; |
| 114 | die (result, | 102 | } |
| 115 | _("TIME UNKNOWN - could not send UDP request to server %s, port %d\n"), | 103 | die(result, _("TIME UNKNOWN - could not send UDP request to server %s, port %d\n"), |
| 116 | server_address, server_port); | 104 | config.server_address, config.server_port); |
| 117 | } | 105 | } |
| 118 | } | 106 | } |
| 119 | 107 | ||
| 120 | /* watch for the connection string */ | 108 | /* watch for the connection string */ |
| 121 | result = recv (sd, (void *)&raw_server_time, sizeof (raw_server_time), 0); | 109 | uint32_t raw_server_time; |
| 110 | result = recv(socket, (void *)&raw_server_time, sizeof(raw_server_time), 0); | ||
| 122 | 111 | ||
| 123 | /* close the connection */ | 112 | /* close the connection */ |
| 124 | close (sd); | 113 | close(socket); |
| 125 | 114 | ||
| 126 | /* reset the alarm */ | 115 | /* reset the alarm */ |
| 127 | time (&end_time); | 116 | time(&end_time); |
| 128 | alarm (0); | 117 | alarm(0); |
| 129 | 118 | ||
| 130 | /* return a WARNING status if we couldn't read any data */ | 119 | /* return a WARNING status if we couldn't read any data */ |
| 131 | if (result <= 0) { | 120 | if (result <= 0) { |
| 132 | if (check_critical_time) | 121 | if (config.check_critical_time) { |
| 133 | result = STATE_CRITICAL; | 122 | result = STATE_CRITICAL; |
| 134 | else if (check_warning_time) | 123 | } else if (config.check_warning_time) { |
| 135 | result = STATE_WARNING; | 124 | result = STATE_WARNING; |
| 136 | else | 125 | } else { |
| 137 | result = STATE_UNKNOWN; | 126 | result = STATE_UNKNOWN; |
| 138 | die (result, | 127 | } |
| 139 | _("TIME UNKNOWN - no data received from server %s, port %d\n"), | 128 | die(result, _("TIME UNKNOWN - no data received from server %s, port %d\n"), |
| 140 | server_address, server_port); | 129 | config.server_address, config.server_port); |
| 141 | } | 130 | } |
| 142 | 131 | ||
| 143 | result = STATE_OK; | 132 | result = STATE_OK; |
| 144 | 133 | ||
| 145 | conntime = (end_time - start_time); | 134 | time_t conntime = (end_time - start_time); |
| 146 | if (check_critical_time&& conntime > critical_time) | 135 | if (config.check_critical_time && conntime > config.critical_time) { |
| 147 | result = STATE_CRITICAL; | 136 | result = STATE_CRITICAL; |
| 148 | else if (check_warning_time && conntime > warning_time) | 137 | } else if (config.check_warning_time && conntime > config.warning_time) { |
| 149 | result = STATE_WARNING; | 138 | result = STATE_WARNING; |
| 139 | } | ||
| 150 | 140 | ||
| 151 | if (result != STATE_OK) | 141 | if (result != STATE_OK) { |
| 152 | die (result, _("TIME %s - %d second response time|%s\n"), | 142 | die(result, _("TIME %s - %d second response time|%s\n"), state_text(result), (int)conntime, |
| 153 | state_text (result), (int)conntime, | 143 | perfdata("time", (long)conntime, "s", config.check_warning_time, |
| 154 | perfdata ("time", (long)conntime, "s", | 144 | (long)config.warning_time, config.check_critical_time, |
| 155 | check_warning_time, (long)warning_time, | 145 | (long)config.critical_time, true, 0, false, 0)); |
| 156 | check_critical_time, (long)critical_time, | 146 | } |
| 157 | true, 0, false, 0)); | ||
| 158 | 147 | ||
| 159 | server_time = ntohl (raw_server_time) - UNIX_EPOCH; | 148 | unsigned long server_time; |
| 160 | if (server_time > (unsigned long)end_time) | 149 | unsigned long diff_time; |
| 150 | server_time = ntohl(raw_server_time) - UNIX_EPOCH; | ||
| 151 | if (server_time > (unsigned long)end_time) { | ||
| 161 | diff_time = server_time - (unsigned long)end_time; | 152 | diff_time = server_time - (unsigned long)end_time; |
| 162 | else | 153 | } else { |
| 163 | diff_time = (unsigned long)end_time - server_time; | 154 | diff_time = (unsigned long)end_time - server_time; |
| 155 | } | ||
| 164 | 156 | ||
| 165 | if (check_critical_diff&& diff_time > critical_diff) | 157 | if (config.check_critical_diff && diff_time > config.critical_diff) { |
| 166 | result = STATE_CRITICAL; | 158 | result = STATE_CRITICAL; |
| 167 | else if (check_warning_diff&& diff_time > warning_diff) | 159 | } else if (config.check_warning_diff && diff_time > config.warning_diff) { |
| 168 | result = STATE_WARNING; | 160 | result = STATE_WARNING; |
| 161 | } | ||
| 169 | 162 | ||
| 170 | printf (_("TIME %s - %lu second time difference|%s %s\n"), | 163 | printf(_("TIME %s - %lu second time difference|%s %s\n"), state_text(result), diff_time, |
| 171 | state_text (result), diff_time, | 164 | perfdata("time", (long)conntime, "s", config.check_warning_time, |
| 172 | perfdata ("time", (long)conntime, "s", | 165 | (long)config.warning_time, config.check_critical_time, |
| 173 | check_warning_time, (long)warning_time, | 166 | (long)config.critical_time, true, 0, false, 0), |
| 174 | check_critical_time, (long)critical_time, | 167 | perfdata("offset", diff_time, "s", config.check_warning_diff, config.warning_diff, |
| 175 | true, 0, false, 0), | 168 | config.check_critical_diff, config.critical_diff, true, 0, false, 0)); |
| 176 | perfdata ("offset", diff_time, "s", | ||
| 177 | check_warning_diff, warning_diff, | ||
| 178 | check_critical_diff, critical_diff, | ||
| 179 | true, 0, false, 0)); | ||
| 180 | return result; | 169 | return result; |
| 181 | } | 170 | } |
| 182 | 171 | ||
| 183 | |||
| 184 | |||
| 185 | /* process command-line arguments */ | 172 | /* process command-line arguments */ |
| 186 | int | 173 | check_time_config_wrapper process_arguments(int argc, char **argv) { |
| 187 | process_arguments (int argc, char **argv) | 174 | static struct option longopts[] = {{"hostname", required_argument, 0, 'H'}, |
| 188 | { | 175 | {"warning-variance", required_argument, 0, 'w'}, |
| 189 | int c; | 176 | {"critical-variance", required_argument, 0, 'c'}, |
| 190 | 177 | {"warning-connect", required_argument, 0, 'W'}, | |
| 191 | int option = 0; | 178 | {"critical-connect", required_argument, 0, 'C'}, |
| 192 | static struct option longopts[] = { | 179 | {"port", required_argument, 0, 'p'}, |
| 193 | {"hostname", required_argument, 0, 'H'}, | 180 | {"udp", no_argument, 0, 'u'}, |
| 194 | {"warning-variance", required_argument, 0, 'w'}, | 181 | {"timeout", required_argument, 0, 't'}, |
| 195 | {"critical-variance", required_argument, 0, 'c'}, | 182 | {"version", no_argument, 0, 'V'}, |
| 196 | {"warning-connect", required_argument, 0, 'W'}, | 183 | {"help", no_argument, 0, 'h'}, |
| 197 | {"critical-connect", required_argument, 0, 'C'}, | 184 | {0, 0, 0, 0}}; |
| 198 | {"port", required_argument, 0, 'p'}, | 185 | |
| 199 | {"udp", no_argument, 0, 'u'}, | 186 | if (argc < 2) { |
| 200 | {"timeout", required_argument, 0, 't'}, | 187 | usage("\n"); |
| 201 | {"version", no_argument, 0, 'V'}, | 188 | } |
| 202 | {"help", no_argument, 0, 'h'}, | ||
| 203 | {0, 0, 0, 0} | ||
| 204 | }; | ||
| 205 | 189 | ||
| 206 | if (argc < 2) | 190 | for (int i = 1; i < argc; i++) { |
| 207 | usage ("\n"); | 191 | if (strcmp("-to", argv[i]) == 0) { |
| 208 | 192 | strcpy(argv[i], "-t"); | |
| 209 | for (c = 1; c < argc; c++) { | 193 | } else if (strcmp("-wd", argv[i]) == 0) { |
| 210 | if (strcmp ("-to", argv[c]) == 0) | 194 | strcpy(argv[i], "-w"); |
| 211 | strcpy (argv[c], "-t"); | 195 | } else if (strcmp("-cd", argv[i]) == 0) { |
| 212 | else if (strcmp ("-wd", argv[c]) == 0) | 196 | strcpy(argv[i], "-c"); |
| 213 | strcpy (argv[c], "-w"); | 197 | } else if (strcmp("-wt", argv[i]) == 0) { |
| 214 | else if (strcmp ("-cd", argv[c]) == 0) | 198 | strcpy(argv[i], "-W"); |
| 215 | strcpy (argv[c], "-c"); | 199 | } else if (strcmp("-ct", argv[i]) == 0) { |
| 216 | else if (strcmp ("-wt", argv[c]) == 0) | 200 | strcpy(argv[i], "-C"); |
| 217 | strcpy (argv[c], "-W"); | 201 | } |
| 218 | else if (strcmp ("-ct", argv[c]) == 0) | ||
| 219 | strcpy (argv[c], "-C"); | ||
| 220 | } | 202 | } |
| 221 | 203 | ||
| 204 | check_time_config_wrapper result = { | ||
| 205 | .errorcode = OK, | ||
| 206 | .config = check_time_config_init(), | ||
| 207 | }; | ||
| 208 | |||
| 209 | int option_char; | ||
| 222 | while (true) { | 210 | while (true) { |
| 223 | c = getopt_long (argc, argv, "hVH:w:c:W:C:p:t:u", longopts, | 211 | int option = 0; |
| 224 | &option); | 212 | option_char = getopt_long(argc, argv, "hVH:w:c:W:C:p:t:u", longopts, &option); |
| 225 | 213 | ||
| 226 | if (c == -1 || c == EOF) | 214 | if (option_char == -1 || option_char == EOF) { |
| 227 | break; | 215 | break; |
| 216 | } | ||
| 228 | 217 | ||
| 229 | switch (c) { | 218 | switch (option_char) { |
| 230 | case '?': /* print short usage statement if args not parsable */ | 219 | case '?': /* print short usage statement if args not parsable */ |
| 231 | usage5 (); | 220 | usage5(); |
| 232 | case 'h': /* help */ | 221 | case 'h': /* help */ |
| 233 | print_help (); | 222 | print_help(); |
| 234 | exit (STATE_UNKNOWN); | 223 | exit(STATE_UNKNOWN); |
| 235 | case 'V': /* version */ | 224 | case 'V': /* version */ |
| 236 | print_revision (progname, NP_VERSION); | 225 | print_revision(progname, NP_VERSION); |
| 237 | exit (STATE_UNKNOWN); | 226 | exit(STATE_UNKNOWN); |
| 238 | case 'H': /* hostname */ | 227 | case 'H': /* hostname */ |
| 239 | if (!is_host (optarg)) | 228 | if (!is_host(optarg)) { |
| 240 | usage2 (_("Invalid hostname/address"), optarg); | 229 | usage2(_("Invalid hostname/address"), optarg); |
| 241 | server_address = optarg; | ||
| 242 | break; | ||
| 243 | case 'w': /* warning-variance */ | ||
| 244 | if (is_intnonneg (optarg)) { | ||
| 245 | warning_diff = strtoul (optarg, NULL, 10); | ||
| 246 | check_warning_diff = true; | ||
| 247 | } | 230 | } |
| 248 | else if (strspn (optarg, "0123456789:,") > 0) { | 231 | result.config.server_address = optarg; |
| 249 | if (sscanf (optarg, "%lu%*[:,]%d", &warning_diff, &warning_time) == 2) { | 232 | break; |
| 250 | check_warning_diff = true; | 233 | case 'w': /* warning-variance */ |
| 251 | check_warning_time = true; | 234 | if (is_intnonneg(optarg)) { |
| 252 | } | 235 | result.config.warning_diff = strtoul(optarg, NULL, 10); |
| 253 | else { | 236 | result.config.check_warning_diff = true; |
| 254 | usage4 (_("Warning thresholds must be a positive integer")); | 237 | } else if (strspn(optarg, "0123456789:,") > 0) { |
| 238 | if (sscanf(optarg, "%lu%*[:,]%d", &result.config.warning_diff, | ||
| 239 | &result.config.warning_time) == 2) { | ||
| 240 | result.config.check_warning_diff = true; | ||
| 241 | result.config.check_warning_time = true; | ||
| 242 | } else { | ||
| 243 | usage4(_("Warning thresholds must be a positive integer")); | ||
| 255 | } | 244 | } |
| 256 | } | 245 | } else { |
| 257 | else { | 246 | usage4(_("Warning threshold must be a positive integer")); |
| 258 | usage4 (_("Warning threshold must be a positive integer")); | ||
| 259 | } | 247 | } |
| 260 | break; | 248 | break; |
| 261 | case 'c': /* critical-variance */ | 249 | case 'c': /* critical-variance */ |
| 262 | if (is_intnonneg (optarg)) { | 250 | if (is_intnonneg(optarg)) { |
| 263 | critical_diff = strtoul (optarg, NULL, 10); | 251 | result.config.critical_diff = strtoul(optarg, NULL, 10); |
| 264 | check_critical_diff = true; | 252 | result.config.check_critical_diff = true; |
| 265 | } | 253 | } else if (strspn(optarg, "0123456789:,") > 0) { |
| 266 | else if (strspn (optarg, "0123456789:,") > 0) { | 254 | if (sscanf(optarg, "%lu%*[:,]%d", &result.config.critical_diff, |
| 267 | if (sscanf (optarg, "%lu%*[:,]%d", &critical_diff, &critical_time) == | 255 | &result.config.critical_time) == 2) { |
| 268 | 2) { | 256 | result.config.check_critical_diff = true; |
| 269 | check_critical_diff = true; | 257 | result.config.check_critical_time = true; |
| 270 | check_critical_time = true; | 258 | } else { |
| 271 | } | 259 | usage4(_("Critical thresholds must be a positive integer")); |
| 272 | else { | ||
| 273 | usage4 (_("Critical thresholds must be a positive integer")); | ||
| 274 | } | 260 | } |
| 275 | } | 261 | } else { |
| 276 | else { | 262 | usage4(_("Critical threshold must be a positive integer")); |
| 277 | usage4 (_("Critical threshold must be a positive integer")); | ||
| 278 | } | 263 | } |
| 279 | break; | 264 | break; |
| 280 | case 'W': /* warning-connect */ | 265 | case 'W': /* warning-connect */ |
| 281 | if (!is_intnonneg (optarg)) | 266 | if (!is_intnonneg(optarg)) { |
| 282 | usage4 (_("Warning threshold must be a positive integer")); | 267 | usage4(_("Warning threshold must be a positive integer")); |
| 283 | else | 268 | } else { |
| 284 | warning_time = atoi (optarg); | 269 | result.config.warning_time = atoi(optarg); |
| 285 | check_warning_time = true; | 270 | } |
| 271 | result.config.check_warning_time = true; | ||
| 286 | break; | 272 | break; |
| 287 | case 'C': /* critical-connect */ | 273 | case 'C': /* critical-connect */ |
| 288 | if (!is_intnonneg (optarg)) | 274 | if (!is_intnonneg(optarg)) { |
| 289 | usage4 (_("Critical threshold must be a positive integer")); | 275 | usage4(_("Critical threshold must be a positive integer")); |
| 290 | else | 276 | } else { |
| 291 | critical_time = atoi (optarg); | 277 | result.config.critical_time = atoi(optarg); |
| 292 | check_critical_time = true; | 278 | } |
| 279 | result.config.check_critical_time = true; | ||
| 293 | break; | 280 | break; |
| 294 | case 'p': /* port */ | 281 | case 'p': /* port */ |
| 295 | if (!is_intnonneg (optarg)) | 282 | if (!is_intnonneg(optarg)) { |
| 296 | usage4 (_("Port must be a positive integer")); | 283 | usage4(_("Port must be a positive integer")); |
| 297 | else | 284 | } else { |
| 298 | server_port = atoi (optarg); | 285 | result.config.server_port = atoi(optarg); |
| 286 | } | ||
| 299 | break; | 287 | break; |
| 300 | case 't': /* timeout */ | 288 | case 't': /* timeout */ |
| 301 | if (!is_intnonneg (optarg)) | 289 | if (!is_intnonneg(optarg)) { |
| 302 | usage2 (_("Timeout interval must be a positive integer"), optarg); | 290 | usage2(_("Timeout interval must be a positive integer"), optarg); |
| 303 | else | 291 | } else { |
| 304 | socket_timeout = atoi (optarg); | 292 | socket_timeout = atoi(optarg); |
| 293 | } | ||
| 305 | break; | 294 | break; |
| 306 | case 'u': /* udp */ | 295 | case 'u': /* udp */ |
| 307 | use_udp = true; | 296 | result.config.use_udp = true; |
| 308 | } | 297 | } |
| 309 | } | 298 | } |
| 310 | 299 | ||
| 311 | c = optind; | 300 | option_char = optind; |
| 312 | if (server_address == NULL) { | 301 | if (result.config.server_address == NULL) { |
| 313 | if (argc > c) { | 302 | if (argc > option_char) { |
| 314 | if (!is_host (argv[c])) | 303 | if (!is_host(argv[option_char])) { |
| 315 | usage2 (_("Invalid hostname/address"), optarg); | 304 | usage2(_("Invalid hostname/address"), optarg); |
| 316 | server_address = argv[c]; | 305 | } |
| 317 | } | 306 | result.config.server_address = argv[option_char]; |
| 318 | else { | 307 | } else { |
| 319 | usage4 (_("Hostname was not supplied")); | 308 | usage4(_("Hostname was not supplied")); |
| 320 | } | 309 | } |
| 321 | } | 310 | } |
| 322 | 311 | ||
| 323 | return OK; | 312 | return result; |
| 324 | } | 313 | } |
| 325 | 314 | ||
| 326 | 315 | void print_help(void) { | |
| 327 | |||
| 328 | void | ||
| 329 | print_help (void) | ||
| 330 | { | ||
| 331 | char *myport; | 316 | char *myport; |
| 332 | xasprintf (&myport, "%d", TIME_PORT); | 317 | xasprintf(&myport, "%d", TIME_PORT); |
| 333 | 318 | ||
| 334 | print_revision (progname, NP_VERSION); | 319 | print_revision(progname, NP_VERSION); |
| 335 | 320 | ||
| 336 | printf ("Copyright (c) 1999 Ethan Galstad\n"); | 321 | printf("Copyright (c) 1999 Ethan Galstad\n"); |
| 337 | printf (COPYRIGHT, copyright, email); | 322 | printf(COPYRIGHT, copyright, email); |
| 338 | 323 | ||
| 339 | printf ("%s\n", _("This plugin will check the time on the specified host.")); | 324 | printf("%s\n", _("This plugin will check the time on the specified host.")); |
| 340 | 325 | ||
| 341 | printf ("\n\n"); | 326 | printf("\n\n"); |
| 342 | 327 | ||
| 343 | print_usage (); | 328 | print_usage(); |
| 344 | 329 | ||
| 345 | printf (UT_HELP_VRSN); | 330 | printf(UT_HELP_VRSN); |
| 346 | printf (UT_EXTRA_OPTS); | 331 | printf(UT_EXTRA_OPTS); |
| 347 | 332 | ||
| 348 | printf (UT_HOST_PORT, 'p', myport); | 333 | printf(UT_HOST_PORT, 'p', myport); |
| 349 | 334 | ||
| 350 | printf (" %s\n", "-u, --udp"); | 335 | printf(" %s\n", "-u, --udp"); |
| 351 | printf (" %s\n", _("Use UDP to connect, not TCP")); | 336 | printf(" %s\n", _("Use UDP to connect, not TCP")); |
| 352 | printf (" %s\n", "-w, --warning-variance=INTEGER"); | 337 | printf(" %s\n", "-w, --warning-variance=INTEGER"); |
| 353 | printf (" %s\n", _("Time difference (sec.) necessary to result in a warning status")); | 338 | printf(" %s\n", _("Time difference (sec.) necessary to result in a warning status")); |
| 354 | printf (" %s\n", "-c, --critical-variance=INTEGER"); | 339 | printf(" %s\n", "-c, --critical-variance=INTEGER"); |
| 355 | printf (" %s\n", _("Time difference (sec.) necessary to result in a critical status")); | 340 | printf(" %s\n", _("Time difference (sec.) necessary to result in a critical status")); |
| 356 | printf (" %s\n", "-W, --warning-connect=INTEGER"); | 341 | printf(" %s\n", "-W, --warning-connect=INTEGER"); |
| 357 | printf (" %s\n", _("Response time (sec.) necessary to result in warning status")); | 342 | printf(" %s\n", _("Response time (sec.) necessary to result in warning status")); |
| 358 | printf (" %s\n", "-C, --critical-connect=INTEGER"); | 343 | printf(" %s\n", "-C, --critical-connect=INTEGER"); |
| 359 | printf (" %s\n", _("Response time (sec.) necessary to result in critical status")); | 344 | printf(" %s\n", _("Response time (sec.) necessary to result in critical status")); |
| 360 | 345 | ||
| 361 | printf (UT_CONN_TIMEOUT, DEFAULT_SOCKET_TIMEOUT); | 346 | printf(UT_CONN_TIMEOUT, DEFAULT_SOCKET_TIMEOUT); |
| 362 | 347 | ||
| 363 | printf (UT_SUPPORT); | 348 | printf(UT_SUPPORT); |
| 364 | } | 349 | } |
| 365 | 350 | ||
| 366 | 351 | void print_usage(void) { | |
| 367 | 352 | printf("%s\n", _("Usage:")); | |
| 368 | void | 353 | printf("%s -H <host_address> [-p port] [-u] [-w variance] [-c variance]\n", progname); |
| 369 | print_usage (void) | 354 | printf(" [-W connect_time] [-C connect_time] [-t timeout]\n"); |
| 370 | { | ||
| 371 | printf ("%s\n", _("Usage:")); | ||
| 372 | printf ("%s -H <host_address> [-p port] [-u] [-w variance] [-c variance]\n",progname); | ||
| 373 | printf (" [-W connect_time] [-C connect_time] [-t timeout]\n"); | ||
| 374 | } | 355 | } |
