mirror of
https://github.com/monitoring-plugins/monitoring-plugins.git
synced 2026-04-25 08:07:35 -04:00
check_time: style + linter fixes
This commit is contained in:
parent
a54dd50895
commit
eca51d0787
1 changed files with 28 additions and 31 deletions
|
|
@ -61,10 +61,6 @@ static void print_help(void);
|
|||
void print_usage(void);
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
int sd;
|
||||
int result = STATE_UNKNOWN;
|
||||
time_t conntime;
|
||||
|
||||
setlocale(LC_ALL, "");
|
||||
bindtextdomain(PACKAGE, LOCALEDIR);
|
||||
textdomain(PACKAGE);
|
||||
|
|
@ -82,11 +78,13 @@ int main(int argc, char **argv) {
|
|||
alarm(socket_timeout);
|
||||
time(&start_time);
|
||||
|
||||
int socket;
|
||||
int result = STATE_UNKNOWN;
|
||||
/* try to connect to the host at the given port number */
|
||||
if (use_udp) {
|
||||
result = my_udp_connect(server_address, server_port, &sd);
|
||||
result = my_udp_connect(server_address, server_port, &socket);
|
||||
} else {
|
||||
result = my_tcp_connect(server_address, server_port, &sd);
|
||||
result = my_tcp_connect(server_address, server_port, &socket);
|
||||
}
|
||||
|
||||
if (result != STATE_OK) {
|
||||
|
|
@ -100,7 +98,7 @@ int main(int argc, char **argv) {
|
|||
}
|
||||
|
||||
if (use_udp) {
|
||||
if (send(sd, "", 0, 0) < 0) {
|
||||
if (send(socket, "", 0, 0) < 0) {
|
||||
if (check_critical_time)
|
||||
result = STATE_CRITICAL;
|
||||
else if (check_warning_time)
|
||||
|
|
@ -112,10 +110,10 @@ int main(int argc, char **argv) {
|
|||
}
|
||||
|
||||
/* watch for the connection string */
|
||||
result = recv(sd, (void *)&raw_server_time, sizeof(raw_server_time), 0);
|
||||
result = recv(socket, (void *)&raw_server_time, sizeof(raw_server_time), 0);
|
||||
|
||||
/* close the connection */
|
||||
close(sd);
|
||||
close(socket);
|
||||
|
||||
/* reset the alarm */
|
||||
time(&end_time);
|
||||
|
|
@ -134,7 +132,7 @@ int main(int argc, char **argv) {
|
|||
|
||||
result = STATE_OK;
|
||||
|
||||
conntime = (end_time - start_time);
|
||||
time_t conntime = (end_time - start_time);
|
||||
if (check_critical_time && conntime > critical_time)
|
||||
result = STATE_CRITICAL;
|
||||
else if (check_warning_time && conntime > warning_time)
|
||||
|
|
@ -165,9 +163,6 @@ int main(int argc, char **argv) {
|
|||
|
||||
/* process command-line arguments */
|
||||
int process_arguments(int argc, char **argv) {
|
||||
int c;
|
||||
|
||||
int option = 0;
|
||||
static struct option longopts[] = {{"hostname", required_argument, 0, 'H'},
|
||||
{"warning-variance", required_argument, 0, 'w'},
|
||||
{"critical-variance", required_argument, 0, 'c'},
|
||||
|
|
@ -183,26 +178,28 @@ int process_arguments(int argc, char **argv) {
|
|||
if (argc < 2)
|
||||
usage("\n");
|
||||
|
||||
for (c = 1; c < argc; c++) {
|
||||
if (strcmp("-to", argv[c]) == 0)
|
||||
strcpy(argv[c], "-t");
|
||||
else if (strcmp("-wd", argv[c]) == 0)
|
||||
strcpy(argv[c], "-w");
|
||||
else if (strcmp("-cd", argv[c]) == 0)
|
||||
strcpy(argv[c], "-c");
|
||||
else if (strcmp("-wt", argv[c]) == 0)
|
||||
strcpy(argv[c], "-W");
|
||||
else if (strcmp("-ct", argv[c]) == 0)
|
||||
strcpy(argv[c], "-C");
|
||||
for (int i = 1; i < argc; i++) {
|
||||
if (strcmp("-to", argv[i]) == 0)
|
||||
strcpy(argv[i], "-t");
|
||||
else if (strcmp("-wd", argv[i]) == 0)
|
||||
strcpy(argv[i], "-w");
|
||||
else if (strcmp("-cd", argv[i]) == 0)
|
||||
strcpy(argv[i], "-c");
|
||||
else if (strcmp("-wt", argv[i]) == 0)
|
||||
strcpy(argv[i], "-W");
|
||||
else if (strcmp("-ct", argv[i]) == 0)
|
||||
strcpy(argv[i], "-C");
|
||||
}
|
||||
|
||||
int option_char;
|
||||
while (true) {
|
||||
c = getopt_long(argc, argv, "hVH:w:c:W:C:p:t:u", longopts, &option);
|
||||
int option = 0;
|
||||
option_char = getopt_long(argc, argv, "hVH:w:c:W:C:p:t:u", longopts, &option);
|
||||
|
||||
if (c == -1 || c == EOF)
|
||||
if (option_char == -1 || option_char == EOF)
|
||||
break;
|
||||
|
||||
switch (c) {
|
||||
switch (option_char) {
|
||||
case '?': /* print short usage statement if args not parsable */
|
||||
usage5();
|
||||
case 'h': /* help */
|
||||
|
|
@ -277,12 +274,12 @@ int process_arguments(int argc, char **argv) {
|
|||
}
|
||||
}
|
||||
|
||||
c = optind;
|
||||
option_char = optind;
|
||||
if (server_address == NULL) {
|
||||
if (argc > c) {
|
||||
if (!is_host(argv[c]))
|
||||
if (argc > option_char) {
|
||||
if (!is_host(argv[option_char]))
|
||||
usage2(_("Invalid hostname/address"), optarg);
|
||||
server_address = argv[c];
|
||||
server_address = argv[option_char];
|
||||
} else {
|
||||
usage4(_("Hostname was not supplied"));
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue