diff options
author | Karl DeBisschop <kdebisschop@users.sourceforge.net> | 2003-03-07 07:45:45 +0000 |
---|---|---|
committer | Karl DeBisschop <kdebisschop@users.sourceforge.net> | 2003-03-07 07:45:45 +0000 |
commit | 1f7520fae4a776e0af2c5221071f1ff300de8727 (patch) | |
tree | 55f559f84be55413c4a2d864335be46bf61c5307 /plugins/check_smtp.c | |
parent | 2ab504386c324a382c83495c991cb60747d0950d (diff) | |
download | monitoring-plugins-1f7520fae4a776e0af2c5221071f1ff300de8727.tar.gz |
millisecond timing and perf data
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@374 f882894a-f735-0410-b71e-b25c423dba1c
Diffstat (limited to 'plugins/check_smtp.c')
-rw-r--r-- | plugins/check_smtp.c | 33 |
1 files changed, 19 insertions, 14 deletions
diff --git a/plugins/check_smtp.c b/plugins/check_smtp.c index 8c0a246e..f78d1126 100644 --- a/plugins/check_smtp.c +++ b/plugins/check_smtp.c | |||
@@ -73,16 +73,18 @@ int warning_time = 0; | |||
73 | int check_warning_time = FALSE; | 73 | int check_warning_time = FALSE; |
74 | int critical_time = 0; | 74 | int critical_time = 0; |
75 | int check_critical_time = FALSE; | 75 | int check_critical_time = FALSE; |
76 | int verbose = FALSE; | 76 | int verbose = 0; |
77 | 77 | ||
78 | int | 78 | int |
79 | main (int argc, char **argv) | 79 | main (int argc, char **argv) |
80 | { | 80 | { |
81 | int sd; | 81 | int sd; |
82 | double elapsed_time; | ||
82 | int result = STATE_UNKNOWN; | 83 | int result = STATE_UNKNOWN; |
83 | char buffer[MAX_INPUT_BUFFER] = ""; | 84 | char buffer[MAX_INPUT_BUFFER] = ""; |
84 | char *from_str = NULL; | 85 | char *from_str = NULL; |
85 | char *helocmd = NULL; | 86 | char *helocmd = NULL; |
87 | struct timeval tv; | ||
86 | 88 | ||
87 | if (process_arguments (argc, argv) != OK) | 89 | if (process_arguments (argc, argv) != OK) |
88 | usage ("Invalid command arguments supplied\n"); | 90 | usage ("Invalid command arguments supplied\n"); |
@@ -98,17 +100,19 @@ main (int argc, char **argv) | |||
98 | /* initialize the MAIL command with optional FROM command */ | 100 | /* initialize the MAIL command with optional FROM command */ |
99 | asprintf (&from_str, "%sFROM: %s%s", SMTP_DUMMYCMD, from_arg, "\r\n"); | 101 | asprintf (&from_str, "%sFROM: %s%s", SMTP_DUMMYCMD, from_arg, "\r\n"); |
100 | 102 | ||
101 | if (verbose == TRUE) | 103 | if (verbose) |
102 | printf ("FROMCMD: %s\n", from_str); | 104 | printf ("FROMCMD: %s\n", from_str); |
103 | 105 | ||
104 | /* initialize alarm signal handling */ | 106 | /* initialize alarm signal handling */ |
105 | signal (SIGALRM, socket_timeout_alarm_handler); | 107 | (void) signal (SIGALRM, socket_timeout_alarm_handler); |
106 | 108 | ||
107 | /* set socket timeout */ | 109 | /* set socket timeout */ |
108 | alarm (socket_timeout); | 110 | (void) alarm (socket_timeout); |
111 | |||
112 | /* start timer */ | ||
113 | gettimeofday (&tv, NULL); | ||
109 | 114 | ||
110 | /* try to connect to the host at the given port number */ | 115 | /* try to connect to the host at the given port number */ |
111 | time (&start_time); | ||
112 | result = my_tcp_connect (server_address, server_port, &sd); | 116 | result = my_tcp_connect (server_address, server_port, &sd); |
113 | 117 | ||
114 | /* we connected, so close connection before exiting */ | 118 | /* we connected, so close connection before exiting */ |
@@ -146,7 +150,7 @@ main (int argc, char **argv) | |||
146 | /* allow for response to DUMMYCMD to reach us */ | 150 | /* allow for response to DUMMYCMD to reach us */ |
147 | recv(sd, buffer, MAX_INPUT_BUFFER-1, 0); | 151 | recv(sd, buffer, MAX_INPUT_BUFFER-1, 0); |
148 | 152 | ||
149 | if (verbose == TRUE) | 153 | if (verbose) |
150 | printf("DUMMYCMD: %s\n%s\n",from_str,buffer); | 154 | printf("DUMMYCMD: %s\n%s\n",from_str,buffer); |
151 | #endif /* SMTP_USE_DUMMYCMD */ | 155 | #endif /* SMTP_USE_DUMMYCMD */ |
152 | 156 | ||
@@ -160,18 +164,19 @@ main (int argc, char **argv) | |||
160 | /* reset the alarm */ | 164 | /* reset the alarm */ |
161 | alarm (0); | 165 | alarm (0); |
162 | 166 | ||
163 | time (&end_time); | 167 | elapsed_time = delta_time (tv); |
164 | 168 | ||
165 | if (check_critical_time == TRUE && (end_time - start_time) > critical_time) | 169 | if (check_critical_time && elapsed_time > (double) critical_time) |
166 | result = STATE_CRITICAL; | 170 | result = STATE_CRITICAL; |
167 | else if (check_warning_time == TRUE && (end_time - start_time) > warning_time) | 171 | else if (check_warning_time && elapsed_time > (double) warning_time) |
168 | result = STATE_WARNING; | 172 | result = STATE_WARNING; |
169 | 173 | ||
170 | if (verbose == TRUE) | 174 | if (verbose) |
171 | printf ("SMTP %s - %d sec. response time, %s\n", | 175 | printf ("SMTP %s - %7.3f sec. response time, %s|time=%7.3f\n", |
172 | state_text (result), (int) (end_time - start_time), buffer); | 176 | state_text (result), elapsed_time, buffer, elapsed_time); |
173 | else | 177 | else |
174 | printf ("SMTP %s - %d second response time\n", state_text (result), (int) (end_time - start_time)); | 178 | printf ("SMTP %s - %7.3f second response time|time=%7.3f\n", |
179 | state_text (result), elapsed_time, elapsed_time); | ||
175 | 180 | ||
176 | return result; | 181 | return result; |
177 | } | 182 | } |
@@ -268,7 +273,7 @@ process_arguments (int argc, char **argv) | |||
268 | } | 273 | } |
269 | break; | 274 | break; |
270 | case 'v': /* verbose */ | 275 | case 'v': /* verbose */ |
271 | verbose = TRUE; | 276 | verbose++; |
272 | break; | 277 | break; |
273 | case 't': /* timeout */ | 278 | case 't': /* timeout */ |
274 | if (is_intnonneg (optarg)) { | 279 | if (is_intnonneg (optarg)) { |