diff options
Diffstat (limited to 'plugins-root/check_icmp.c')
-rw-r--r-- | plugins-root/check_icmp.c | 51 |
1 files changed, 42 insertions, 9 deletions
diff --git a/plugins-root/check_icmp.c b/plugins-root/check_icmp.c index cd059c38..7a23e05a 100644 --- a/plugins-root/check_icmp.c +++ b/plugins-root/check_icmp.c | |||
@@ -3,7 +3,7 @@ | |||
3 | * Nagios check_icmp plugin | 3 | * Nagios check_icmp plugin |
4 | * | 4 | * |
5 | * License: GPL | 5 | * License: GPL |
6 | * Copyright (c) 2005-2006 nagios-plugins team | 6 | * Copyright (c) 2005-2007 nagios-plugins team |
7 | * | 7 | * |
8 | * Original Author : Andreas Ericsson <ae@op5.se> | 8 | * Original Author : Andreas Ericsson <ae@op5.se> |
9 | * | 9 | * |
@@ -46,7 +46,7 @@ | |||
46 | /* char *progname = "check_icmp"; */ | 46 | /* char *progname = "check_icmp"; */ |
47 | char *progname; | 47 | char *progname; |
48 | const char *revision = "$Revision$"; | 48 | const char *revision = "$Revision$"; |
49 | const char *copyright = "2005-2006"; | 49 | const char *copyright = "2005-2007"; |
50 | const char *email = "nagiosplug-devel@lists.sourceforge.net"; | 50 | const char *email = "nagiosplug-devel@lists.sourceforge.net"; |
51 | 51 | ||
52 | /** nagios plugins basic includes */ | 52 | /** nagios plugins basic includes */ |
@@ -212,6 +212,7 @@ static struct timeval prog_start; | |||
212 | static unsigned long long max_completion_time = 0; | 212 | static unsigned long long max_completion_time = 0; |
213 | static unsigned char ttl = 0; /* outgoing ttl */ | 213 | static unsigned char ttl = 0; /* outgoing ttl */ |
214 | static unsigned int warn_down = 1, crit_down = 1; /* host down threshold values */ | 214 | static unsigned int warn_down = 1, crit_down = 1; /* host down threshold values */ |
215 | static int min_hosts_alive = -1; | ||
215 | float pkt_backoff_factor = 1.5; | 216 | float pkt_backoff_factor = 1.5; |
216 | float target_backoff_factor = 1.5; | 217 | float target_backoff_factor = 1.5; |
217 | 218 | ||
@@ -437,7 +438,7 @@ main(int argc, char **argv) | |||
437 | 438 | ||
438 | /* parse the arguments */ | 439 | /* parse the arguments */ |
439 | for(i = 1; i < argc; i++) { | 440 | for(i = 1; i < argc; i++) { |
440 | while((arg = getopt(argc, argv, "vhVw:c:n:p:t:H:i:b:I:l:")) != EOF) { | 441 | while((arg = getopt(argc, argv, "vhVw:c:n:p:t:H:i:b:I:l:m:")) != EOF) { |
441 | switch(arg) { | 442 | switch(arg) { |
442 | case 'v': | 443 | case 'v': |
443 | debug++; | 444 | debug++; |
@@ -471,6 +472,9 @@ main(int argc, char **argv) | |||
471 | case 'l': | 472 | case 'l': |
472 | ttl = (unsigned char)strtoul(optarg, NULL, 0); | 473 | ttl = (unsigned char)strtoul(optarg, NULL, 0); |
473 | break; | 474 | break; |
475 | case 'm': | ||
476 | min_hosts_alive = (int)strtoul(optarg, NULL, 0); | ||
477 | break; | ||
474 | case 'd': /* implement later, for cluster checks */ | 478 | case 'd': /* implement later, for cluster checks */ |
475 | warn_down = (unsigned char)strtoul(optarg, &ptr, 0); | 479 | warn_down = (unsigned char)strtoul(optarg, &ptr, 0); |
476 | if(ptr) { | 480 | if(ptr) { |
@@ -587,6 +591,11 @@ main(int argc, char **argv) | |||
587 | crash("packets is > 20 (%d)", packets); | 591 | crash("packets is > 20 (%d)", packets); |
588 | } | 592 | } |
589 | 593 | ||
594 | if(min_hosts_alive < -1) { | ||
595 | errno = 0; | ||
596 | crash("minimum alive hosts is negative (%i)", min_hosts_alive); | ||
597 | } | ||
598 | |||
590 | host = list; | 599 | host = list; |
591 | table = malloc(sizeof(struct rta_host **) * (argc - 1)); | 600 | table = malloc(sizeof(struct rta_host **) * (argc - 1)); |
592 | i = 0; | 601 | i = 0; |
@@ -879,6 +888,8 @@ finish(int sig) | |||
879 | struct rta_host *host; | 888 | struct rta_host *host; |
880 | char *status_string[] = | 889 | char *status_string[] = |
881 | {"OK", "WARNING", "CRITICAL", "UNKNOWN", "DEPENDENT"}; | 890 | {"OK", "WARNING", "CRITICAL", "UNKNOWN", "DEPENDENT"}; |
891 | int hosts_ok = 0; | ||
892 | int hosts_warn = 0; | ||
882 | 893 | ||
883 | alarm(0); | 894 | alarm(0); |
884 | if(debug > 1) printf("finish(%d) called\n", sig); | 895 | if(debug > 1) printf("finish(%d) called\n", sig); |
@@ -911,13 +922,25 @@ finish(int sig) | |||
911 | } | 922 | } |
912 | host->pl = pl; | 923 | host->pl = pl; |
913 | host->rta = rta; | 924 | host->rta = rta; |
914 | if(!status && (pl >= warn.pl || rta >= warn.rta)) status = STATE_WARNING; | 925 | if(pl >= crit.pl || rta >= crit.rta) { |
915 | if(pl >= crit.pl || rta >= crit.rta) status = STATE_CRITICAL; | 926 | status = STATE_CRITICAL; |
927 | } | ||
928 | else if(!status && (pl >= warn.pl || rta >= warn.rta)) { | ||
929 | status = STATE_WARNING; | ||
930 | hosts_warn++; | ||
931 | } | ||
932 | else { | ||
933 | hosts_ok++; | ||
934 | } | ||
916 | 935 | ||
917 | host = host->next; | 936 | host = host->next; |
918 | } | 937 | } |
919 | /* this is inevitable */ | 938 | /* this is inevitable */ |
920 | if(!targets_alive) status = STATE_CRITICAL; | 939 | if(!targets_alive) status = STATE_CRITICAL; |
940 | if(min_hosts_alive > -1) { | ||
941 | if(hosts_ok >= min_hosts_alive) status = STATE_OK; | ||
942 | else if((hosts_ok + hosts_warn) >= min_hosts_alive) status = STATE_WARNING; | ||
943 | } | ||
921 | printf("%s - ", status_string[status]); | 944 | printf("%s - ", status_string[status]); |
922 | 945 | ||
923 | host = list; | 946 | host = list; |
@@ -964,10 +987,15 @@ finish(int sig) | |||
964 | host = host->next; | 987 | host = host->next; |
965 | } | 988 | } |
966 | 989 | ||
990 | if(min_hosts_alive > -1) { | ||
991 | if(hosts_ok >= min_hosts_alive) status = STATE_OK; | ||
992 | else if((hosts_ok + hosts_warn) >= min_hosts_alive) status = STATE_WARNING; | ||
993 | } | ||
994 | |||
967 | /* finish with an empty line */ | 995 | /* finish with an empty line */ |
968 | puts(""); | 996 | puts(""); |
969 | if(debug) printf("targets: %u, targets_alive: %u\n", | 997 | if(debug) printf("targets: %u, targets_alive: %u, hosts_ok: %u, hosts_warn: %u, min_hosts_alive: %i\n", |
970 | targets, targets_alive); | 998 | targets, targets_alive, hosts_ok, hosts_warn, min_hosts_alive); |
971 | 999 | ||
972 | exit(status); | 1000 | exit(status); |
973 | } | 1001 | } |
@@ -1211,6 +1239,9 @@ print_help(void) | |||
1211 | printf (" %s\n", "-I"); | 1239 | printf (" %s\n", "-I"); |
1212 | printf (" %s", _("max target interval (currently ")); | 1240 | printf (" %s", _("max target interval (currently ")); |
1213 | printf ("%0.3fms)\n", (float)target_interval / 1000); | 1241 | printf ("%0.3fms)\n", (float)target_interval / 1000); |
1242 | printf (" %s\n", "-m"); | ||
1243 | printf (" %s",_("number of alive hosts required for success")); | ||
1244 | printf ("\n"); | ||
1214 | printf (" %s\n", "-l"); | 1245 | printf (" %s\n", "-l"); |
1215 | printf (" %s", _("TTL on outgoing packets (currently ")); | 1246 | printf (" %s", _("TTL on outgoing packets (currently ")); |
1216 | printf ("%u)", ttl); | 1247 | printf ("%u)", ttl); |
@@ -1228,10 +1259,12 @@ print_help(void) | |||
1228 | printf ("%s\n", _("packet loss. The default values should work well for most users.")); | 1259 | printf ("%s\n", _("packet loss. The default values should work well for most users.")); |
1229 | printf ("%s\n", _("You can specify different RTA factors using the standardized abbreviations")); | 1260 | printf ("%s\n", _("You can specify different RTA factors using the standardized abbreviations")); |
1230 | printf ("%s\n\n", _("us (microseconds), ms (milliseconds, default) or just plain s for seconds.")); | 1261 | printf ("%s\n\n", _("us (microseconds), ms (milliseconds, default) or just plain s for seconds.")); |
1231 | printf ("%s\n", _("Threshold format for -d is warn,crit. 12,14 means WARNING if >= 12 hops")); | 1262 | /* -d not yet implemented */ |
1263 | /* printf ("%s\n", _("Threshold format for -d is warn,crit. 12,14 means WARNING if >= 12 hops")); | ||
1232 | printf ("%s\n", _("are spent and CRITICAL if >= 14 hops are spent.")); | 1264 | printf ("%s\n", _("are spent and CRITICAL if >= 14 hops are spent.")); |
1233 | printf ("%s\n\n", _("NOTE: Some systems decrease TTL when forming ICMP_ECHOREPLY, others do not.")); | 1265 | printf ("%s\n\n", _("NOTE: Some systems decrease TTL when forming ICMP_ECHOREPLY, others do not."));*/ |
1234 | printf ("%s\n\n", _("The -v switch can be specified several times for increased verbosity.")); | 1266 | printf ("%s\n\n", _("The -v switch can be specified several times for increased verbosity.")); |
1267 | |||
1235 | /* printf ("%s\n", _("Long options are currently unsupported.")); | 1268 | /* printf ("%s\n", _("Long options are currently unsupported.")); |
1236 | printf ("%s\n", _("Options marked with * require an argument")); | 1269 | printf ("%s\n", _("Options marked with * require an argument")); |
1237 | */ | 1270 | */ |