mirror of
https://github.com/monitoring-plugins/monitoring-plugins.git
synced 2026-05-28 04:35:40 -04:00
check_time: clang-format
This commit is contained in:
parent
399121ed0d
commit
53e102b6ac
1 changed files with 51 additions and 34 deletions
|
|
@ -68,8 +68,9 @@ int main(int argc, char **argv) {
|
|||
/* Parse extra opts if any */
|
||||
argv = np_extra_opts(&argc, argv, progname);
|
||||
|
||||
if (process_arguments(argc, argv) == ERROR)
|
||||
if (process_arguments(argc, argv) == ERROR) {
|
||||
usage4(_("Could not parse arguments"));
|
||||
}
|
||||
|
||||
/* initialize alarm signal handling */
|
||||
signal(SIGALRM, socket_timeout_alarm_handler);
|
||||
|
|
@ -88,23 +89,25 @@ int main(int argc, char **argv) {
|
|||
}
|
||||
|
||||
if (result != STATE_OK) {
|
||||
if (check_critical_time)
|
||||
if (check_critical_time) {
|
||||
result = STATE_CRITICAL;
|
||||
else if (check_warning_time)
|
||||
} else if (check_warning_time) {
|
||||
result = STATE_WARNING;
|
||||
else
|
||||
} else {
|
||||
result = STATE_UNKNOWN;
|
||||
}
|
||||
die(result, _("TIME UNKNOWN - could not connect to server %s, port %d\n"), server_address, server_port);
|
||||
}
|
||||
|
||||
if (use_udp) {
|
||||
if (send(socket, "", 0, 0) < 0) {
|
||||
if (check_critical_time)
|
||||
if (check_critical_time) {
|
||||
result = STATE_CRITICAL;
|
||||
else if (check_warning_time)
|
||||
} else if (check_warning_time) {
|
||||
result = STATE_WARNING;
|
||||
else
|
||||
} else {
|
||||
result = STATE_UNKNOWN;
|
||||
}
|
||||
die(result, _("TIME UNKNOWN - could not send UDP request to server %s, port %d\n"), server_address, server_port);
|
||||
}
|
||||
}
|
||||
|
|
@ -121,38 +124,43 @@ int main(int argc, char **argv) {
|
|||
|
||||
/* return a WARNING status if we couldn't read any data */
|
||||
if (result <= 0) {
|
||||
if (check_critical_time)
|
||||
if (check_critical_time) {
|
||||
result = STATE_CRITICAL;
|
||||
else if (check_warning_time)
|
||||
} else if (check_warning_time) {
|
||||
result = STATE_WARNING;
|
||||
else
|
||||
} else {
|
||||
result = STATE_UNKNOWN;
|
||||
}
|
||||
die(result, _("TIME UNKNOWN - no data received from server %s, port %d\n"), server_address, server_port);
|
||||
}
|
||||
|
||||
result = STATE_OK;
|
||||
|
||||
time_t conntime = (end_time - start_time);
|
||||
if (check_critical_time && conntime > critical_time)
|
||||
if (check_critical_time && conntime > critical_time) {
|
||||
result = STATE_CRITICAL;
|
||||
else if (check_warning_time && conntime > warning_time)
|
||||
} else if (check_warning_time && conntime > warning_time) {
|
||||
result = STATE_WARNING;
|
||||
}
|
||||
|
||||
if (result != STATE_OK)
|
||||
if (result != STATE_OK) {
|
||||
die(result, _("TIME %s - %d second response time|%s\n"), state_text(result), (int)conntime,
|
||||
perfdata("time", (long)conntime, "s", check_warning_time, (long)warning_time, check_critical_time, (long)critical_time, true, 0,
|
||||
false, 0));
|
||||
}
|
||||
|
||||
server_time = ntohl(raw_server_time) - UNIX_EPOCH;
|
||||
if (server_time > (unsigned long)end_time)
|
||||
if (server_time > (unsigned long)end_time) {
|
||||
diff_time = server_time - (unsigned long)end_time;
|
||||
else
|
||||
} else {
|
||||
diff_time = (unsigned long)end_time - server_time;
|
||||
}
|
||||
|
||||
if (check_critical_diff && diff_time > critical_diff)
|
||||
if (check_critical_diff && diff_time > critical_diff) {
|
||||
result = STATE_CRITICAL;
|
||||
else if (check_warning_diff && diff_time > warning_diff)
|
||||
} else if (check_warning_diff && diff_time > warning_diff) {
|
||||
result = STATE_WARNING;
|
||||
}
|
||||
|
||||
printf(_("TIME %s - %lu second time difference|%s %s\n"), state_text(result), diff_time,
|
||||
perfdata("time", (long)conntime, "s", check_warning_time, (long)warning_time, check_critical_time, (long)critical_time, true, 0,
|
||||
|
|
@ -175,20 +183,22 @@ int process_arguments(int argc, char **argv) {
|
|||
{"help", no_argument, 0, 'h'},
|
||||
{0, 0, 0, 0}};
|
||||
|
||||
if (argc < 2)
|
||||
if (argc < 2) {
|
||||
usage("\n");
|
||||
}
|
||||
|
||||
for (int i = 1; i < argc; i++) {
|
||||
if (strcmp("-to", argv[i]) == 0)
|
||||
if (strcmp("-to", argv[i]) == 0) {
|
||||
strcpy(argv[i], "-t");
|
||||
else if (strcmp("-wd", argv[i]) == 0)
|
||||
} else if (strcmp("-wd", argv[i]) == 0) {
|
||||
strcpy(argv[i], "-w");
|
||||
else if (strcmp("-cd", argv[i]) == 0)
|
||||
} else if (strcmp("-cd", argv[i]) == 0) {
|
||||
strcpy(argv[i], "-c");
|
||||
else if (strcmp("-wt", argv[i]) == 0)
|
||||
} else if (strcmp("-wt", argv[i]) == 0) {
|
||||
strcpy(argv[i], "-W");
|
||||
else if (strcmp("-ct", argv[i]) == 0)
|
||||
} else if (strcmp("-ct", argv[i]) == 0) {
|
||||
strcpy(argv[i], "-C");
|
||||
}
|
||||
}
|
||||
|
||||
int option_char;
|
||||
|
|
@ -196,8 +206,9 @@ int process_arguments(int argc, char **argv) {
|
|||
int option = 0;
|
||||
option_char = getopt_long(argc, argv, "hVH:w:c:W:C:p:t:u", longopts, &option);
|
||||
|
||||
if (option_char == -1 || option_char == EOF)
|
||||
if (option_char == -1 || option_char == EOF) {
|
||||
break;
|
||||
}
|
||||
|
||||
switch (option_char) {
|
||||
case '?': /* print short usage statement if args not parsable */
|
||||
|
|
@ -209,8 +220,9 @@ int process_arguments(int argc, char **argv) {
|
|||
print_revision(progname, NP_VERSION);
|
||||
exit(STATE_UNKNOWN);
|
||||
case 'H': /* hostname */
|
||||
if (!is_host(optarg))
|
||||
if (!is_host(optarg)) {
|
||||
usage2(_("Invalid hostname/address"), optarg);
|
||||
}
|
||||
server_address = optarg;
|
||||
break;
|
||||
case 'w': /* warning-variance */
|
||||
|
|
@ -244,30 +256,34 @@ int process_arguments(int argc, char **argv) {
|
|||
}
|
||||
break;
|
||||
case 'W': /* warning-connect */
|
||||
if (!is_intnonneg(optarg))
|
||||
if (!is_intnonneg(optarg)) {
|
||||
usage4(_("Warning threshold must be a positive integer"));
|
||||
else
|
||||
} else {
|
||||
warning_time = atoi(optarg);
|
||||
}
|
||||
check_warning_time = true;
|
||||
break;
|
||||
case 'C': /* critical-connect */
|
||||
if (!is_intnonneg(optarg))
|
||||
if (!is_intnonneg(optarg)) {
|
||||
usage4(_("Critical threshold must be a positive integer"));
|
||||
else
|
||||
} else {
|
||||
critical_time = atoi(optarg);
|
||||
}
|
||||
check_critical_time = true;
|
||||
break;
|
||||
case 'p': /* port */
|
||||
if (!is_intnonneg(optarg))
|
||||
if (!is_intnonneg(optarg)) {
|
||||
usage4(_("Port must be a positive integer"));
|
||||
else
|
||||
} else {
|
||||
server_port = atoi(optarg);
|
||||
}
|
||||
break;
|
||||
case 't': /* timeout */
|
||||
if (!is_intnonneg(optarg))
|
||||
if (!is_intnonneg(optarg)) {
|
||||
usage2(_("Timeout interval must be a positive integer"), optarg);
|
||||
else
|
||||
} else {
|
||||
socket_timeout = atoi(optarg);
|
||||
}
|
||||
break;
|
||||
case 'u': /* udp */
|
||||
use_udp = true;
|
||||
|
|
@ -277,8 +293,9 @@ int process_arguments(int argc, char **argv) {
|
|||
option_char = optind;
|
||||
if (server_address == NULL) {
|
||||
if (argc > option_char) {
|
||||
if (!is_host(argv[option_char]))
|
||||
if (!is_host(argv[option_char])) {
|
||||
usage2(_("Invalid hostname/address"), optarg);
|
||||
}
|
||||
server_address = argv[option_char];
|
||||
} else {
|
||||
usage4(_("Hostname was not supplied"));
|
||||
|
|
|
|||
Loading…
Reference in a new issue