diff options
author | Karl DeBisschop <kdebisschop@users.sourceforge.net> | 2003-03-03 03:49:40 +0000 |
---|---|---|
committer | Karl DeBisschop <kdebisschop@users.sourceforge.net> | 2003-03-03 03:49:40 +0000 |
commit | 9ab752c789266a4c6e38615efffa33a83d8ee3c7 (patch) | |
tree | 20620985c24770a1fc1fb25e537fa4fed4dea771 | |
parent | 2789d116982e7fa2aaf93455d43e7f4ad93a42fc (diff) | |
download | monitoring-plugins-9ab752c789266a4c6e38615efffa33a83d8ee3c7.tar.gz |
accept comma-delimted list of hosts for checking if a multihomed host is alive
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@362 f882894a-f735-0410-b71e-b25c423dba1c
-rw-r--r-- | plugins/check_ping.c | 59 |
1 files changed, 38 insertions, 21 deletions
diff --git a/plugins/check_ping.c b/plugins/check_ping.c index c75ad587..480f631e 100644 --- a/plugins/check_ping.c +++ b/plugins/check_ping.c | |||
@@ -83,6 +83,7 @@ main (int argc, char **argv) | |||
83 | { | 83 | { |
84 | char *command_line = NULL; | 84 | char *command_line = NULL; |
85 | int result = STATE_UNKNOWN; | 85 | int result = STATE_UNKNOWN; |
86 | int this_result = STATE_UNKNOWN; | ||
86 | int i; | 87 | int i; |
87 | 88 | ||
88 | addresses = malloc (max_addr); | 89 | addresses = malloc (max_addr); |
@@ -113,7 +114,7 @@ main (int argc, char **argv) | |||
113 | printf ("%s ==> ", command_line); | 114 | printf ("%s ==> ", command_line); |
114 | 115 | ||
115 | /* run the command */ | 116 | /* run the command */ |
116 | run_ping (command_line, addresses[i]); | 117 | this_result = run_ping (command_line, addresses[i]); |
117 | 118 | ||
118 | if (pl == UNKNOWN_PACKET_LOSS || rta == UNKNOWN_TRIP_TIME) { | 119 | if (pl == UNKNOWN_PACKET_LOSS || rta == UNKNOWN_TRIP_TIME) { |
119 | printf ("%s\n", command_line); | 120 | printf ("%s\n", command_line); |
@@ -122,30 +123,32 @@ main (int argc, char **argv) | |||
122 | } | 123 | } |
123 | 124 | ||
124 | if (pl >= cpl || rta >= crta || rta < 0) | 125 | if (pl >= cpl || rta >= crta || rta < 0) |
125 | result = STATE_CRITICAL; | 126 | this_result = STATE_CRITICAL; |
126 | else if (pl >= wpl || rta >= wrta) | 127 | else if (pl >= wpl || rta >= wrta) |
127 | result = STATE_WARNING; | 128 | this_result = STATE_WARNING; |
128 | else if (pl < wpl && rta < wrta && pl >= 0 && rta >= 0) | 129 | else if (pl >= 0 && rta >= 0) |
129 | /* cannot use the max function because STATE_UNKNOWN is now 3 gt STATE_OK | 130 | this_result = max_state (STATE_OK, this_result); |
130 | result = max (result, STATE_OK); */ | ||
131 | if( !( (result == STATE_WARNING) || (result == STATE_CRITICAL) ) ) { | ||
132 | result = STATE_OK; | ||
133 | } | ||
134 | 131 | ||
132 | if (n_addresses > 1 && this_result != STATE_UNKNOWN) | ||
133 | terminate (STATE_OK, "%s is alive\n", addresses[i]); | ||
134 | |||
135 | if (display_html == TRUE) | 135 | if (display_html == TRUE) |
136 | printf ("<A HREF='%s/traceroute.cgi?%s'>", CGIURL, addresses[i]); | 136 | printf ("<A HREF='%s/traceroute.cgi?%s'>", CGIURL, addresses[i]); |
137 | if (pl == 100) | 137 | if (pl == 100) |
138 | printf ("PING %s - %sPacket loss = %d%%", state_text (result), warn_text, | 138 | printf ("PING %s - %sPacket loss = %d%%", state_text (this_result), warn_text, |
139 | pl); | 139 | pl); |
140 | else | 140 | else |
141 | printf ("PING %s - %sPacket loss = %d%%, RTA = %2.2f ms", | 141 | printf ("PING %s - %sPacket loss = %d%%, RTA = %2.2f ms", |
142 | state_text (result), warn_text, pl, rta); | 142 | state_text (this_result), warn_text, pl, rta); |
143 | if (display_html == TRUE) | 143 | if (display_html == TRUE) |
144 | printf ("</A>"); | 144 | printf ("</A>"); |
145 | printf ("\n"); | 145 | printf ("\n"); |
146 | 146 | ||
147 | if (verbose) | 147 | if (verbose) |
148 | printf ("%f:%d%% %f:%d%%\n", wrta, wpl, crta, cpl); | 148 | printf ("%f:%d%% %f:%d%%\n", wrta, wpl, crta, cpl); |
149 | |||
150 | result = max_state (result, this_result); | ||
151 | |||
149 | } | 152 | } |
150 | 153 | ||
151 | return result; | 154 | return result; |
@@ -157,6 +160,7 @@ int | |||
157 | process_arguments (int argc, char **argv) | 160 | process_arguments (int argc, char **argv) |
158 | { | 161 | { |
159 | int c = 1; | 162 | int c = 1; |
163 | char *ptr; | ||
160 | 164 | ||
161 | #ifdef HAVE_GETOPT_H | 165 | #ifdef HAVE_GETOPT_H |
162 | int option_index = 0; | 166 | int option_index = 0; |
@@ -169,7 +173,7 @@ process_arguments (int argc, char **argv) | |||
169 | }; | 173 | }; |
170 | #endif | 174 | #endif |
171 | 175 | ||
172 | #define OPTCHARS "Vvht:c:w:H:p:nL" | 176 | #define OPTCHARS "VvhnLt:c:w:H:p:" |
173 | 177 | ||
174 | if (argc < 2) | 178 | if (argc < 2) |
175 | return ERROR; | 179 | return ERROR; |
@@ -206,16 +210,23 @@ process_arguments (int argc, char **argv) | |||
206 | verbose = TRUE; | 210 | verbose = TRUE; |
207 | break; | 211 | break; |
208 | case 'H': /* hostname */ | 212 | case 'H': /* hostname */ |
209 | if (is_host (optarg) == FALSE) | 213 | ptr=optarg; |
210 | usage2 ("Invalid host name/address", optarg); | 214 | while (1) { |
211 | n_addresses++; | 215 | n_addresses++; |
212 | if (n_addresses > max_addr) { | 216 | if (n_addresses > max_addr) { |
213 | max_addr *= 2; | 217 | max_addr *= 2; |
214 | addresses = realloc (addresses, max_addr); | 218 | addresses = realloc (addresses, max_addr); |
215 | if (addresses == NULL) | 219 | if (addresses == NULL) |
216 | terminate (STATE_UNKNOWN, "Could not realloc() addresses\n"); | 220 | terminate (STATE_UNKNOWN, "Could not realloc() addresses\n"); |
221 | } | ||
222 | addresses[n_addresses-1] = ptr; | ||
223 | if (ptr = index (ptr, ',')) { | ||
224 | strcpy (ptr, ""); | ||
225 | ptr += sizeof(char); | ||
226 | } else { | ||
227 | break; | ||
228 | } | ||
217 | } | 229 | } |
218 | addresses[n_addresses-1] = optarg; | ||
219 | break; | 230 | break; |
220 | case 'p': /* number of packets to send */ | 231 | case 'p': /* number of packets to send */ |
221 | if (is_intnonneg (optarg)) | 232 | if (is_intnonneg (optarg)) |
@@ -326,6 +337,7 @@ int | |||
326 | validate_arguments () | 337 | validate_arguments () |
327 | { | 338 | { |
328 | float max_seconds; | 339 | float max_seconds; |
340 | int i; | ||
329 | 341 | ||
330 | if (wrta == UNKNOWN_TRIP_TIME) { | 342 | if (wrta == UNKNOWN_TRIP_TIME) { |
331 | printf ("<wrta> was not set\n"); | 343 | printf ("<wrta> was not set\n"); |
@@ -359,6 +371,11 @@ validate_arguments () | |||
359 | if (max_seconds > timeout_interval) | 371 | if (max_seconds > timeout_interval) |
360 | timeout_interval = (int)max_seconds; | 372 | timeout_interval = (int)max_seconds; |
361 | 373 | ||
374 | for (i=0; i<n_addresses; i++) { | ||
375 | if (is_host(addresses[i]) == FALSE) | ||
376 | usage2 ("Invalid host name/address", addresses[i]); | ||
377 | } | ||
378 | |||
362 | return OK; | 379 | return OK; |
363 | } | 380 | } |
364 | 381 | ||