summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 2ab5043)
raw | patch | inline | side by side (parent: 2ab5043)
author | Karl DeBisschop <kdebisschop@users.sourceforge.net> | |
Fri, 7 Mar 2003 07:45:45 +0000 (07:45 +0000) | ||
committer | Karl DeBisschop <kdebisschop@users.sourceforge.net> | |
Fri, 7 Mar 2003 07:45:45 +0000 (07:45 +0000) |
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@374 f882894a-f735-0410-b71e-b25c423dba1c
plugins/check_smtp.c | patch | blob | history |
diff --git a/plugins/check_smtp.c b/plugins/check_smtp.c
index 8c0a246e594d5b56e53157ca723dee857965b5d0..f78d1126521ac20c7faf09725e2407fb192cdd4a 100644 (file)
--- a/plugins/check_smtp.c
+++ b/plugins/check_smtp.c
int check_warning_time = FALSE;
int critical_time = 0;
int check_critical_time = FALSE;
-int verbose = FALSE;
+int verbose = 0;
int
main (int argc, char **argv)
{
int sd;
+ double elapsed_time;
int result = STATE_UNKNOWN;
char buffer[MAX_INPUT_BUFFER] = "";
char *from_str = NULL;
char *helocmd = NULL;
+ struct timeval tv;
if (process_arguments (argc, argv) != OK)
usage ("Invalid command arguments supplied\n");
/* initialize the MAIL command with optional FROM command */
asprintf (&from_str, "%sFROM: %s%s", SMTP_DUMMYCMD, from_arg, "\r\n");
- if (verbose == TRUE)
+ if (verbose)
printf ("FROMCMD: %s\n", from_str);
/* initialize alarm signal handling */
- signal (SIGALRM, socket_timeout_alarm_handler);
+ (void) signal (SIGALRM, socket_timeout_alarm_handler);
/* set socket timeout */
- alarm (socket_timeout);
+ (void) alarm (socket_timeout);
+
+ /* start timer */
+ gettimeofday (&tv, NULL);
/* try to connect to the host at the given port number */
- time (&start_time);
result = my_tcp_connect (server_address, server_port, &sd);
/* we connected, so close connection before exiting */
/* allow for response to DUMMYCMD to reach us */
recv(sd, buffer, MAX_INPUT_BUFFER-1, 0);
- if (verbose == TRUE)
+ if (verbose)
printf("DUMMYCMD: %s\n%s\n",from_str,buffer);
#endif /* SMTP_USE_DUMMYCMD */
/* reset the alarm */
alarm (0);
- time (&end_time);
+ elapsed_time = delta_time (tv);
- if (check_critical_time == TRUE && (end_time - start_time) > critical_time)
+ if (check_critical_time && elapsed_time > (double) critical_time)
result = STATE_CRITICAL;
- else if (check_warning_time == TRUE && (end_time - start_time) > warning_time)
+ else if (check_warning_time && elapsed_time > (double) warning_time)
result = STATE_WARNING;
- if (verbose == TRUE)
- printf ("SMTP %s - %d sec. response time, %s\n",
- state_text (result), (int) (end_time - start_time), buffer);
+ if (verbose)
+ printf ("SMTP %s - %7.3f sec. response time, %s|time=%7.3f\n",
+ state_text (result), elapsed_time, buffer, elapsed_time);
else
- printf ("SMTP %s - %d second response time\n", state_text (result), (int) (end_time - start_time));
+ printf ("SMTP %s - %7.3f second response time|time=%7.3f\n",
+ state_text (result), elapsed_time, elapsed_time);
return result;
}
}
break;
case 'v': /* verbose */
- verbose = TRUE;
+ verbose++;
break;
case 't': /* timeout */
if (is_intnonneg (optarg)) {