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