From ab7d056ee36c064ae0a75fb0029cb8cf20df5b66 Mon Sep 17 00:00:00 2001 From: root Date: Fri, 18 Aug 2017 16:13:30 -0300 Subject: Add support to Jitter, MOS and Score --- lib/utils_base.c | 13 ++ plugins-root/check_icmp.c | 429 +++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 396 insertions(+), 46 deletions(-) diff --git a/lib/utils_base.c b/lib/utils_base.c index 3822bcf1..8a03d098 100644 --- a/lib/utils_base.c +++ b/lib/utils_base.c @@ -300,6 +300,19 @@ char *np_escaped_string (const char *string) { int np_check_if_root(void) { return (geteuid() == 0); } +int np_warn_if_not_root(void) { + int status = np_check_if_root(); + if(!status) { + printf(_("Warning: ")); + printf(_("This plugin must be either run as root or setuid root.\n")); + printf(_("To run as root, you can use a tool like sudo.\n")); + printf(_("To set the setuid permissions, use the command:\n")); + /* XXX could we use something like progname? */ + printf("\tchmod u+s yourpluginfile\n"); + } + return status; +} + /* * Extract the value from key/value pairs, or return NULL. The value returned * can be free()ed. diff --git a/plugins-root/check_icmp.c b/plugins-root/check_icmp.c index 4098874c..d68c4e0d 100644 --- a/plugins-root/check_icmp.c +++ b/plugins-root/check_icmp.c @@ -42,6 +42,10 @@ char *progname; const char *copyright = "2005-2008"; const char *email = "devel@monitoring-plugins.org"; +#ifdef __sun +#define _XPG4_2 +#endif + /** Monitoring Plugins basic includes */ #include "common.h" #include "netutils.h" @@ -120,18 +124,35 @@ typedef struct rta_host { unsigned char icmp_type, icmp_code; /* type and code from errors */ unsigned short flags; /* control/status flags */ double rta; /* measured RTA */ + int rta_status; double rtmax; /* max rtt */ double rtmin; /* min rtt */ + double jitter; /* measured jitter */ + int jitter_status; + double jitter_max; /* jitter rtt */ + double jitter_min; /* jitter rtt */ + double EffectiveLatency; + double mos; /* Mean opnion score */ + int mos_status; + double score; /* score */ + int score_status; + u_int last_tdiff; + u_int last_icmp_seq; /* Last ICMP_SEQ to check out of order pkts */ unsigned char pl; /* measured packet loss */ + int pl_status; struct rta_host *next; /* linked list */ + int order_status; } rta_host; #define FLAG_LOST_CAUSE 0x01 /* decidedly dead target. */ /* threshold structure. all values are maximum allowed, exclusive */ typedef struct threshold { - unsigned char pl; /* max allowed packet loss in percent */ - unsigned int rta; /* roundtrip time average, microseconds */ + unsigned char pl; /* max allowed packet loss in percent */ + unsigned int rta; /* roundtrip time average, microseconds */ + double jitter; /* jitter time average, microseconds */ + double mos; /* MOS */ + double score; /* Score */ } threshold; /* the data structure */ @@ -187,6 +208,7 @@ static int wait_for_reply(int, u_int); static int recvfrom_wto(int, void *, unsigned int, struct sockaddr *, u_int *, struct timeval*); static int send_icmp_ping(int, struct rta_host *); static int get_threshold(char *str, threshold *th); +static int get_threshold2(char *str, threshold *, threshold *, int type); static void run_checks(void); static void set_source_ip(char *); static int add_target(char *); @@ -223,6 +245,12 @@ static unsigned int warn_down = 1, crit_down = 1; /* host down threshold values static int min_hosts_alive = -1; float pkt_backoff_factor = 1.5; float target_backoff_factor = 1.5; +int rta_mode=0; +int pl_mode=0; +int jitter_mode=0; +int score_mode=0; +int mos_mode=0; +int order_mode=0; /** code start **/ static void @@ -378,6 +406,9 @@ main(int argc, char **argv) int icmp_sockerrno, udp_sockerrno, tcp_sockerrno; int result; struct rta_host *host; +#ifdef HAVE_SIGACTION + struct sigaction sig_action; +#endif #ifdef SO_TIMESTAMP int on = 1; #endif @@ -386,6 +417,9 @@ main(int argc, char **argv) bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); + /* print a helpful error message if geteuid != 0 */ + np_warn_if_not_root(); + /* we only need to be setsuid when we get the sockets, so do * that before pointer magic (esp. on network data) */ icmp_sockerrno = udp_sockerrno = tcp_sockerrno = sockets = 0; @@ -430,10 +464,19 @@ main(int argc, char **argv) table = NULL; mode = MODE_RTA; + /* Default critical thresholds */ crit.rta = 500000; crit.pl = 80; + crit.jitter = 50; + crit.mos= 3; + crit.score=70; + /* Default warning thresholds */ warn.rta = 200000; warn.pl = 40; + warn.jitter = 40; + warn.mos= 3.5; + warn.score=80; + protocols = HAVE_ICMP | HAVE_UDP | HAVE_TCP; pkt_interval = 80000; /* 80 msec packet interval by default */ packets = 5; @@ -469,14 +512,14 @@ main(int argc, char **argv) /* parse the arguments */ for(i = 1; i < argc; i++) { - while((arg = getopt(argc, argv, "vhVw:c:n:p:t:H:s:i:b:I:l:m:")) != EOF) { - unsigned short size; + while((arg = getopt(argc, argv, "vhVw:c:n:p:t:H:s:i:b:I:l:m:P:R:J:S:M:O")) != EOF) { + long size; switch(arg) { case 'v': debug++; break; case 'b': - size = (unsigned short)strtol(optarg,NULL,0); + size = strtol(optarg,NULL,0); if (size >= (sizeof(struct icmp) + sizeof(struct icmp_ping_data)) && size < MAX_PING_DATA) { icmp_data_size = size; @@ -526,11 +569,34 @@ main(int argc, char **argv) break; case 'V': /* version */ print_revision (progname, NP_VERSION); - exit (STATE_UNKNOWN); + exit (STATE_OK); case 'h': /* help */ print_help (); - exit (STATE_UNKNOWN); - } + exit (STATE_OK); + case 'R': /* RTA mode */ + get_threshold2(optarg, &warn, &crit,1); + rta_mode=1; + break; + case 'P': /* packet loss mode */ + get_threshold2(optarg, &warn, &crit,2); + pl_mode=1; + break; + case 'J': /* packet loss mode */ + get_threshold2(optarg, &warn, &crit,3); + jitter_mode=1; + break; + case 'M': /* MOS mode */ + get_threshold2(optarg, &warn, &crit,4); + mos_mode=1; + break; + case 'S': /* score mode */ + get_threshold2(optarg, &warn, &crit,5); + score_mode=1; + break; + case 'O': /* out of order mode */ + order_mode=1; + break; + } } } @@ -579,11 +645,25 @@ main(int argc, char **argv) if(warn.pl > crit.pl) warn.pl = crit.pl; if(warn.rta > crit.rta) warn.rta = crit.rta; if(warn_down > crit_down) crit_down = warn_down; - + if(warn.jitter > crit.jitter) crit.jitter = warn.jitter; + if(warn.mos < crit.mos) warn.mos = crit.mos; + if(warn.score < crit.score) warn.score = crit.score; + +#ifdef HAVE_SIGACTION + sig_action.sa_sigaction = NULL; + sig_action.sa_handler = finish; + sigfillset(&sig_action.sa_mask); + sig_action.sa_flags = SA_NODEFER|SA_RESTART; + sigaction(SIGINT, &sig_action, NULL); + sigaction(SIGHUP, &sig_action, NULL); + sigaction(SIGTERM, &sig_action, NULL); + sigaction(SIGALRM, &sig_action, NULL); +#else /* HAVE_SIGACTION */ signal(SIGINT, finish); signal(SIGHUP, finish); signal(SIGTERM, finish); signal(SIGALRM, finish); +#endif /* HAVE_SIGACTION */ if(debug) printf("Setting alarm timeout to %u seconds\n", timeout); alarm(timeout); @@ -608,7 +688,7 @@ main(int argc, char **argv) if(max_completion_time > (u_int)timeout * 1000000) { printf("max_completion_time: %llu timeout: %u\n", max_completion_time, timeout); - printf("Timeout must be at least %llu\n", + printf("Timout must be at lest %llu\n", max_completion_time / 1000000 + 1); } } @@ -633,7 +713,7 @@ main(int argc, char **argv) } host = list; - table = malloc(sizeof(struct rta_host **) * targets); + table = malloc(sizeof(struct rta_host *) * targets); i = 0; while(host) { host->id = i*packets; @@ -671,9 +751,9 @@ run_checks() /* we're still in the game, so send next packet */ (void)send_icmp_ping(icmp_sock, table[t]); - result = wait_for_reply(icmp_sock, target_interval); + (void)wait_for_reply(icmp_sock, target_interval); } - result = wait_for_reply(icmp_sock, pkt_interval * targets); + (void)wait_for_reply(icmp_sock, pkt_interval * targets); } if(icmp_pkts_en_route && targets_alive) { @@ -693,7 +773,7 @@ run_checks() * haven't yet */ if(debug) printf("Waiting for %u micro-seconds (%0.3f msecs)\n", final_wait, (float)final_wait / 1000); - result = wait_for_reply(icmp_sock, final_wait); + (void)wait_for_reply(icmp_sock, final_wait); } } @@ -714,6 +794,7 @@ wait_for_reply(int sock, u_int t) struct icmp_ping_data data; struct timeval wait_start, now; u_int tdiff, i, per_pkt_wait; + double jitter_tmp; /* if we can't listen or don't have anything to listen to, just return */ if(!t || !icmp_pkts_en_route) return 0; @@ -792,12 +873,43 @@ wait_for_reply(int sock, u_int t) host = table[ntohs(icp.icmp_seq)/packets]; tdiff = get_timevaldiff(&data.stime, &now); + if (host->last_tdiff>0) { + /* Calculate jitter */ + if (host->last_tdiff > tdiff) { + jitter_tmp = host->last_tdiff - tdiff; + } + else { + jitter_tmp = tdiff - host->last_tdiff; + } + if (host->jitter==0) { + host->jitter=jitter_tmp; + host->jitter_max=jitter_tmp; + host->jitter_min=jitter_tmp; + } + else { + host->jitter+=jitter_tmp; + if (jitter_tmp < host->jitter_min) + host->jitter_min=jitter_tmp; + if (jitter_tmp > host->jitter_max) + host->jitter_max=jitter_tmp; + } + + /* Check if packets in order */ + if (host->last_icmp_seq >= icp.icmp_seq) + host->order_status=STATE_CRITICAL; + } + host->last_tdiff=tdiff; + + host->last_icmp_seq=icp.icmp_seq; + + //printf("%d tdiff %d host->jitter %u host->last_tdiff %u\n", icp.icmp_seq, tdiff, host->jitter, host->last_tdiff); + host->time_waited += tdiff; host->icmp_recv++; icmp_recv++; - if (tdiff > host->rtmax) + if (tdiff > (int)host->rtmax) host->rtmax = tdiff; - if (tdiff < host->rtmin) + if (tdiff < (int)host->rtmin) host->rtmin = tdiff; if(debug) { @@ -945,8 +1057,10 @@ recvfrom_wto(int sock, void *buf, unsigned int len, struct sockaddr *saddr, hdr.msg_namelen = slen; hdr.msg_iov = &iov; hdr.msg_iovlen = 1; +#ifdef HAVE_MSGHDR_MSG_CONTROL hdr.msg_control = ans_data; hdr.msg_controllen = sizeof(ans_data); +#endif ret = recvmsg(sock, &hdr, 0); #ifdef SO_TIMESTAMP @@ -975,6 +1089,8 @@ finish(int sig) {"OK", "WARNING", "CRITICAL", "UNKNOWN", "DEPENDENT"}; int hosts_ok = 0; int hosts_warn = 0; + double R; + int shown=0; alarm(0); if(debug > 1) printf("finish(%d) called\n", sig); @@ -990,6 +1106,7 @@ finish(int sig) } /* iterate thrice to calculate values, give output, and print perfparse */ + status=STATE_OK; host = list; while(host) { if(!host->icmp_recv) { @@ -1005,19 +1122,104 @@ finish(int sig) pl = ((host->icmp_sent - host->icmp_recv) * 100) / host->icmp_sent; rta = (double)host->time_waited / host->icmp_recv; } + if (host->icmp_recv>1) { + host->jitter=(host->jitter / (host->icmp_recv - 1)/1000); + host->EffectiveLatency = (rta/1000) + host->jitter * 2 + 10; + if (host->EffectiveLatency < 160) + R = 93.2 - (host->EffectiveLatency / 40); + else + R = 93.2 - ((host->EffectiveLatency - 120) / 10); + R = R - (pl * 2.5); + if (R<0) R=0; + host->score = R; + host->mos= 1 + ((0.035) * R) + ((.000007) * R * (R-60) * (100-R)); + } + else { + host->jitter=0; + host->jitter_min=0; + host->jitter_max=0; + host->mos=0; + } host->pl = pl; host->rta = rta; - if(pl >= crit.pl || rta >= crit.rta) { - status = STATE_CRITICAL; + + /* if no new mode selected, use old schema */ + if (!rta_mode && !pl_mode && !jitter_mode && !score_mode && !mos_mode && !order_mode) { + rta_mode=1; + pl_mode=1; } - else if(!status && (pl >= warn.pl || rta >= warn.rta)) { - status = STATE_WARNING; - hosts_warn++; + + /* Check which mode is on and do the warn / Crit stuff */ + if (rta_mode) { + if(rta >= crit.rta) { + status = STATE_CRITICAL; + host->rta_status=STATE_CRITICAL; + } + else if(status!=STATE_CRITICAL && (rta >= warn.rta)) { + status = STATE_WARNING; + hosts_warn++; + host->rta_status=STATE_WARNING; + } + else { + hosts_ok++; + } } - else { - hosts_ok++; + if (pl_mode) { + if(pl >= crit.pl) { + status = STATE_CRITICAL; + host->pl_status=STATE_CRITICAL; + } + else if(status!=STATE_CRITICAL && (pl >= warn.pl)) { + status = STATE_WARNING; + hosts_warn++; + host->pl_status=STATE_WARNING; + } + else { + hosts_ok++; + } + } + if (jitter_mode) { + if(host->jitter >= crit.jitter) { + status = STATE_CRITICAL; + host->jitter_status=STATE_CRITICAL; + } + else if(status!=STATE_CRITICAL && (host->jitter >= warn.jitter)) { + status = STATE_WARNING; + hosts_warn++; + host->jitter_status=STATE_WARNING; + } + else { + hosts_ok++; + } + } + if (mos_mode) { + if(host->mos <= crit.mos) { + status = STATE_CRITICAL; + host->mos_status=STATE_CRITICAL; + } + else if(status!=STATE_CRITICAL && (host->mos <= warn.mos)) { + status = STATE_WARNING; + hosts_warn++; + host->mos_status=STATE_WARNING; + } + else { + hosts_ok++; + } + } + if (score_mode) { + if(host->score <= crit.score) { + status = STATE_CRITICAL; + host->score_status=STATE_CRITICAL; + } + else if(status!=STATE_CRITICAL && (host->score <= warn.score)) { + status = STATE_WARNING; + score_mode++; + host->score_status=STATE_WARNING; + } + else { + hosts_ok++; + } } - host = host->next; } /* this is inevitable */ @@ -1027,9 +1229,10 @@ finish(int sig) else if((hosts_ok + hosts_warn) >= min_hosts_alive) status = STATE_WARNING; } printf("%s - ", status_string[status]); - + host = list; while(host) { + if(debug) puts(""); if(i) { if(i < targets) printf(" :: "); @@ -1038,6 +1241,8 @@ finish(int sig) i++; if(!host->icmp_recv) { status = STATE_CRITICAL; + host->rtmin=0; + host->jitter_min=0; if(host->flags & FLAG_LOST_CAUSE) { printf("%s: %s @ %s. rta nan, lost %d%%", host->name, @@ -1050,26 +1255,92 @@ finish(int sig) } } else { /* !icmp_recv */ - printf("%s: rta %0.3fms, lost %u%%", - host->name, host->rta / 1000, host->pl); + printf("%s: ", host->name); + /* rta text output */ + if (rta_mode) { + shown=1; + if (status == STATE_OK) + printf("%s rta %0.3fms",(shown==1)?",":"", host->rta / 1000); + else if (status==STATE_WARNING && host->rta_status==status) + printf("%s rta %0.3fms > %0.3fms",(shown==1)?",":"", (float)host->rta / 1000, (float)warn.rta/1000); + else if (status==STATE_CRITICAL && host->rta_status==status) + printf("%s rta %0.3fms > %0.3fms",(shown==1)?",":"", (float)host->rta / 1000, (float)crit.rta/1000); + } + /* pl text output */ + if (pl_mode) { + shown=1; + if (status == STATE_OK) + printf("%s lost %u%%",(shown==1)?",":"", host->pl); + else if (status==STATE_WARNING && host->pl_status==status) + printf("%s lost %u%% > %u%%",(shown==1)?",":"", host->pl, warn.pl); + else if (status==STATE_CRITICAL && host->pl_status==status) + printf("%s lost %u%% > %u%%",(shown==1)?",":"", host->pl, crit.pl); + } + /* jitter text output */ + if (jitter_mode) { + shown=1; + if (status == STATE_OK) + printf("%s jitter %0.3fms",(shown==1)?",":"", (float)host->jitter); + else if (status==STATE_WARNING && host->jitter_status==status) + printf("%s jitter %0.3fms > %0.3fms",(shown==1)?",":"", (float)host->jitter, warn.jitter); + else if (status==STATE_CRITICAL && host->jitter_status==status) + printf("%s jitter %0.3fms > %0.3fms",(shown==1)?",":"", (float)host->jitter, crit.jitter); + } + /* mos text output */ + if (mos_mode) { + shown=1; + if (status == STATE_OK) + printf("%s MOS %0.1f",(shown==1)?",":"", (float)host->mos); + else if (status==STATE_WARNING && host->mos_status==status) + printf("%s MOS %0.1f < %0.1f",(shown==1)?",":"", (float)host->mos, (float)warn.mos); + else if (status==STATE_CRITICAL && host->mos_status==status) + printf("%s MOS %0.1f < %0.1f",(shown==1)?",":"", (float)host->mos, (float)crit.mos); + } + /* score text output */ + if (score_mode) { + shown=1; + if (status == STATE_OK) + printf("%s Score %u",(shown==1)?",":"", (int)host->score); + else if (status==STATE_WARNING && host->score_status==status ) + printf("%s Score %u < %u",(shown==1)?",":"", (int)host->score, (int)warn.score); + else if (status==STATE_CRITICAL && host->score_status==status ) + printf("%s Score %u < %u",(shown==1)?",":"", (int)host->score, (int)crit.score); + } + /* order statis text output */ + if (order_mode) { + shown=1; + if (status == STATE_OK) + printf("%s Packets in order",(shown==1)?",":""); + else if (status==STATE_CRITICAL && host->order_status==status) + printf("%s Packets out of order",(shown==1)?",":""); + } } - host = host->next; } /* iterate once more for pretty perfparse output */ - printf("|"); + if (!(!rta_mode && !pl_mode && !jitter_mode && !score_mode && !mos_mode && order_mode)) { + printf("|"); + } i = 0; host = list; while(host) { if(debug) puts(""); - printf("%srta=%0.3fms;%0.3f;%0.3f;0; %spl=%u%%;%u;%u;; %srtmax=%0.3fms;;;; %srtmin=%0.3fms;;;; ", - (targets > 1) ? host->name : "", - host->rta / 1000, (float)warn.rta / 1000, (float)crit.rta / 1000, - (targets > 1) ? host->name : "", host->pl, warn.pl, crit.pl, - (targets > 1) ? host->name : "", (float)host->rtmax / 1000, - (targets > 1) ? host->name : "", (host->rtmin < DBL_MAX) ? (float)host->rtmin / 1000 : (float)0); - + if (rta_mode && host->pl<100) { + printf("%srta=%0.3fms;%0.3f;%0.3f;0; %srtmax=%0.3fms;;;; %srtmin=%0.3fms;;;; ",(targets > 1) ? host->name : "", (float)host->rta / 1000, (float)warn.rta / 1000, (float)crit.rta / 1000, (targets > 1) ? host->name : "", (float)host->rtmax / 1000, (targets > 1) ? host->name : "", (float)host->rtmin / 1000); + } + if (pl_mode) { + printf("%spl=%u%%;%u;%u;0;100 ", (targets > 1) ? host->name : "", host->pl, warn.pl, crit.pl); + } + if (jitter_mode && host->pl<100) { + printf("%sjitter_avg=%0.3fms;%0.3f;%0.3f;0; %sjitter_max=%0.3fms;;;; %sjitter_min=%0.3fms;;;; ", (targets > 1) ? host->name : "", (float)host->jitter, (float)warn.jitter, (float)crit.jitter, (targets > 1) ? host->name : "", (float)host->jitter_max / 1000, (targets > 1) ? host->name : "",(float)host->jitter_min / 1000); + } + if (mos_mode && host->pl<100) { + printf("%smos=%0.1f;%0.1f;%0.1f;0;5 ", (targets > 1) ? host->name : "", (float)host->mos, (float)warn.mos, (float)crit.mos); + } + if (score_mode && host->pl<100) { + printf("%sscore=%u;%u;%u;0;100 ", (targets > 1) ? host->name : "", (int)host->score, (int)warn.score, (int)crit.score); + } host = host->next; } @@ -1144,8 +1415,20 @@ add_target_ip(char *arg, struct in_addr *in) /* fill out the sockaddr_in struct */ host->saddr_in.sin_family = AF_INET; host->saddr_in.sin_addr.s_addr = in->s_addr; - host->rtmin = DBL_MAX; + host->rtmax = 0; + host->jitter=0; + host->jitter_max=0; + host->jitter_min=DBL_MAX; + host->last_tdiff=0; + host->order_status=STATE_OK; + host->last_icmp_seq=0; + host->rta_status=0; + host->pl_status=0; + host->jitter_status=0; + host->mos_status=0; + host->score_status=0; + host->pl_status=0; if(!list) list = cursor = host; else cursor->next = host; @@ -1250,7 +1533,7 @@ get_timevar(const char *str) /* unit might be given as ms|m (millisec), * us|u (microsec) or just plain s, for seconds */ - u = p = '\0'; + p = '\0'; u = str[len - 1]; if(len >= 2 && !isdigit((int)str[len - 2])) p = str[len - 2]; if(p && u == 's') u = p; @@ -1262,7 +1545,7 @@ get_timevar(const char *str) else if(u == 's') factor = 1000000; /* seconds */ if(debug > 2) printf("factor is %u\n", factor); - i = strtoul(str, &ptr, 0); + i = strtoul(str, &ptr, 0); if(!ptr || *ptr != '.' || strlen(ptr) < 2 || factor == 1) return i * factor; @@ -1308,6 +1591,46 @@ get_threshold(char *str, threshold *th) return 0; } +/* not too good at checking errors, but it'll do (main() should barfe on -1) */ +static int +get_threshold2(char *str, threshold *warn, threshold *crit, int type) +{ + char *p = NULL, i = 0; + + if(!str || !strlen(str) || !warn || !crit) return -1; + /* pointer magic slims code by 10 lines. i is bof-stop on stupid libc's */ + p = &str[strlen(str) - 1]; + while(p != &str[0]) { + if( (*p == 'm') || (*p == '%') ) *p = '\0'; + else if(*p == ',' && i) { + *p = '\0'; /* reset it so get_timevar(str) works nicely later */ + if (type==1) + crit->rta = atof(p+1)*1000; + else if (type==2) + crit->pl = (unsigned char)strtoul(p+1, NULL, 0); + else if (type==3) + crit->jitter = atof(p+1); + else if (type==4) + crit->mos = atof(p+1); + else if (type==5) + crit->score = atof(p+1); + } + i = 1; + p--; + } + if (type==1) + warn->rta = atof(p)*1000; + else if (type==2) + warn->pl = (unsigned char)strtoul(p, NULL, 0); + if (type==3) + warn->jitter = atof(p); + else if (type==4) + warn->mos = atof(p); + else if (type==5) + warn->score = atof(p); + return 0; +} + unsigned short icmp_checksum(unsigned short *p, int n) { @@ -1332,10 +1655,9 @@ icmp_checksum(unsigned short *p, int n) void print_help(void) { - /*print_revision (progname);*/ /* FIXME: Why? */ - printf ("Copyright (c) 2005 Andreas Ericsson \n"); + printf (COPYRIGHT, copyright, email); printf ("\n\n"); @@ -1344,20 +1666,35 @@ print_help(void) printf (UT_HELP_VRSN); printf (UT_EXTRA_OPTS); - - printf (" %s\n", "-H"); - printf (" %s\n", _("specify a target")); - printf (" %s\n", "-w"); + printf (" %s\n", "-w"); printf (" %s", _("warning threshold (currently ")); printf ("%0.3fms,%u%%)\n", (float)warn.rta / 1000, warn.pl); printf (" %s\n", "-c"); printf (" %s", _("critical threshold (currently ")); printf ("%0.3fms,%u%%)\n", (float)crit.rta / 1000, crit.pl); + + printf (" %s\n", "-R"); + printf (" %s\n", _("RTA, round trip average, mode warning,critical, ex. 100ms,200ms unit in ms")); + printf (" %s\n", "-P"); + printf (" %s\n", _("packet loss mode, ex. 40%,50% , unit in %")); + printf (" %s\n", "-J"); + printf (" %s\n", _("jitter mode warning,critical, ex. 40.000ms,50.000ms , unit in ms ")); + printf (" %s\n", "-M"); + printf (" %s\n", _("MOS mode, between 0 and 4.4 warning,critical, ex. 3.5,3.0")); + printf (" %s\n", "-S"); + printf (" %s\n", _("score mode, max value 100 warning,critical, ex. 80,70 ")); + printf (" %s\n", "-O"); + printf (" %s\n", _("detect out of order ICMP packts ")); + printf (" %s\n", "-H"); + printf (" %s\n", _("specify a target")); printf (" %s\n", "-s"); printf (" %s\n", _("specify a source IP address or device name")); printf (" %s\n", "-n"); printf (" %s", _("number of packets to send (currently ")); printf ("%u)\n",packets); + printf (" %s\n", "-p"); + printf (" %s", _("number of packets to send (currently ")); + printf ("%u)\n",packets); printf (" %s\n", "-i"); printf (" %s", _("max packet interval (currently ")); printf ("%0.3fms)\n",(float)pkt_interval / 1000); @@ -1378,9 +1715,9 @@ print_help(void) printf (" %s %u + %d)\n", _("Packet size will be data bytes + icmp header (currently"),icmp_data_size, ICMP_MINLEN); printf (" %s\n", "-v"); printf (" %s\n", _("verbose")); - printf ("\n"); printf ("%s\n", _("Notes:")); + printf ("%s\n", _("If not mode R,P,J,M,S or O is informed, default icmp behavior, RTA and packet loss")); printf (" %s\n", _("The -H switch is optional. Naming a host (or several) to check is not.")); printf ("\n"); printf (" %s\n", _("Threshold format for -w and -c is 200.25,60% for 200.25 msec RTA and 60%")); -- cgit v1.2.3-74-g34f1 From f5c5a7438fa34f2ee2c0b9914806f9a26b56ba59 Mon Sep 17 00:00:00 2001 From: root Date: Mon, 21 Aug 2017 09:42:10 -0300 Subject: Clean up plugin exit --- plugins-root/check_icmp.c | 43 ++++++++++++++++++------------------------- 1 file changed, 18 insertions(+), 25 deletions(-) diff --git a/plugins-root/check_icmp.c b/plugins-root/check_icmp.c index d68c4e0d..2ad644ec 100644 --- a/plugins-root/check_icmp.c +++ b/plugins-root/check_icmp.c @@ -1090,7 +1090,6 @@ finish(int sig) int hosts_ok = 0; int hosts_warn = 0; double R; - int shown=0; alarm(0); if(debug > 1) printf("finish(%d) called\n", sig); @@ -1255,64 +1254,58 @@ finish(int sig) } } else { /* !icmp_recv */ - printf("%s: ", host->name); + printf("%s ", host->name); /* rta text output */ if (rta_mode) { - shown=1; if (status == STATE_OK) - printf("%s rta %0.3fms",(shown==1)?",":"", host->rta / 1000); + printf("rta %0.3fms", host->rta / 1000); else if (status==STATE_WARNING && host->rta_status==status) - printf("%s rta %0.3fms > %0.3fms",(shown==1)?",":"", (float)host->rta / 1000, (float)warn.rta/1000); + printf("rta %0.3fms > %0.3fms", (float)host->rta / 1000, (float)warn.rta/1000); else if (status==STATE_CRITICAL && host->rta_status==status) - printf("%s rta %0.3fms > %0.3fms",(shown==1)?",":"", (float)host->rta / 1000, (float)crit.rta/1000); + printf("rta %0.3fms > %0.3fms", (float)host->rta / 1000, (float)crit.rta/1000); } /* pl text output */ if (pl_mode) { - shown=1; if (status == STATE_OK) - printf("%s lost %u%%",(shown==1)?",":"", host->pl); + printf("lost %u%%", host->pl); else if (status==STATE_WARNING && host->pl_status==status) - printf("%s lost %u%% > %u%%",(shown==1)?",":"", host->pl, warn.pl); + printf("lost %u%% > %u%%", host->pl, warn.pl); else if (status==STATE_CRITICAL && host->pl_status==status) - printf("%s lost %u%% > %u%%",(shown==1)?",":"", host->pl, crit.pl); + printf("lost %u%% > %u%%", host->pl, crit.pl); } /* jitter text output */ if (jitter_mode) { - shown=1; if (status == STATE_OK) - printf("%s jitter %0.3fms",(shown==1)?",":"", (float)host->jitter); + printf("jitter %0.3fms", (float)host->jitter); else if (status==STATE_WARNING && host->jitter_status==status) - printf("%s jitter %0.3fms > %0.3fms",(shown==1)?",":"", (float)host->jitter, warn.jitter); + printf("jitter %0.3fms > %0.3fms", (float)host->jitter, warn.jitter); else if (status==STATE_CRITICAL && host->jitter_status==status) - printf("%s jitter %0.3fms > %0.3fms",(shown==1)?",":"", (float)host->jitter, crit.jitter); + printf("jitter %0.3fms > %0.3fms", (float)host->jitter, crit.jitter); } /* mos text output */ if (mos_mode) { - shown=1; if (status == STATE_OK) - printf("%s MOS %0.1f",(shown==1)?",":"", (float)host->mos); + printf("MOS %0.1f", (float)host->mos); else if (status==STATE_WARNING && host->mos_status==status) - printf("%s MOS %0.1f < %0.1f",(shown==1)?",":"", (float)host->mos, (float)warn.mos); + printf("MOS %0.1f < %0.1f", (float)host->mos, (float)warn.mos); else if (status==STATE_CRITICAL && host->mos_status==status) - printf("%s MOS %0.1f < %0.1f",(shown==1)?",":"", (float)host->mos, (float)crit.mos); + printf("MOS %0.1f < %0.1f", (float)host->mos, (float)crit.mos); } /* score text output */ if (score_mode) { - shown=1; if (status == STATE_OK) - printf("%s Score %u",(shown==1)?",":"", (int)host->score); + printf("Score %u", (int)host->score); else if (status==STATE_WARNING && host->score_status==status ) - printf("%s Score %u < %u",(shown==1)?",":"", (int)host->score, (int)warn.score); + printf("Score %u < %u", (int)host->score, (int)warn.score); else if (status==STATE_CRITICAL && host->score_status==status ) - printf("%s Score %u < %u",(shown==1)?",":"", (int)host->score, (int)crit.score); + printf("Score %u < %u", (int)host->score, (int)crit.score); } /* order statis text output */ if (order_mode) { - shown=1; if (status == STATE_OK) - printf("%s Packets in order",(shown==1)?",":""); + printf("Packets in order"); else if (status==STATE_CRITICAL && host->order_status==status) - printf("%s Packets out of order",(shown==1)?",":""); + printf("Packets out of order"); } } host = host->next; -- cgit v1.2.3-74-g34f1 From 8272d73e579739cccbfce61f7401cd5f8b9fd0e0 Mon Sep 17 00:00:00 2001 From: Danijel Tasov Date: Sat, 23 Sep 2023 16:18:08 +0200 Subject: remove root check We can perfectly do icmp without root by using capabalities. So, instead of doing unsufficient checks beforehand, we just try and fail if it doesn't work. Signed-off-by: Danijel Tasov --- lib/utils_base.c | 13 ------------- plugins-root/check_icmp.c | 3 --- 2 files changed, 16 deletions(-) diff --git a/lib/utils_base.c b/lib/utils_base.c index 8a03d098..3822bcf1 100644 --- a/lib/utils_base.c +++ b/lib/utils_base.c @@ -300,19 +300,6 @@ char *np_escaped_string (const char *string) { int np_check_if_root(void) { return (geteuid() == 0); } -int np_warn_if_not_root(void) { - int status = np_check_if_root(); - if(!status) { - printf(_("Warning: ")); - printf(_("This plugin must be either run as root or setuid root.\n")); - printf(_("To run as root, you can use a tool like sudo.\n")); - printf(_("To set the setuid permissions, use the command:\n")); - /* XXX could we use something like progname? */ - printf("\tchmod u+s yourpluginfile\n"); - } - return status; -} - /* * Extract the value from key/value pairs, or return NULL. The value returned * can be free()ed. diff --git a/plugins-root/check_icmp.c b/plugins-root/check_icmp.c index 2ad644ec..a7fad36a 100644 --- a/plugins-root/check_icmp.c +++ b/plugins-root/check_icmp.c @@ -417,9 +417,6 @@ main(int argc, char **argv) bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); - /* print a helpful error message if geteuid != 0 */ - np_warn_if_not_root(); - /* we only need to be setsuid when we get the sockets, so do * that before pointer magic (esp. on network data) */ icmp_sockerrno = udp_sockerrno = tcp_sockerrno = sockets = 0; -- cgit v1.2.3-74-g34f1 From 2f909de3405a2073bafed32a3ce47e466bb562ce Mon Sep 17 00:00:00 2001 From: Danijel Tasov Date: Sat, 23 Sep 2023 16:46:15 +0200 Subject: fix merge error Signed-off-by: Danijel Tasov --- plugins-root/check_icmp.c | 1 - 1 file changed, 1 deletion(-) diff --git a/plugins-root/check_icmp.c b/plugins-root/check_icmp.c index 72ad1d7d..a4854153 100644 --- a/plugins-root/check_icmp.c +++ b/plugins-root/check_icmp.c @@ -524,7 +524,6 @@ main(int argc, char **argv) /* parse the arguments */ for(i = 1; i < argc; i++) { while((arg = getopt(argc, argv, opts_str)) != EOF) { - while((arg = getopt(argc, argv, "vhVw:c:n:p:t:H:s:i:b:I:l:m:P:R:J:S:M:O")) != EOF) { switch(arg) { case 'v': debug++; -- cgit v1.2.3-74-g34f1 From 9387e21de7b66a44f2b8a5f907124afdcf7b88a8 Mon Sep 17 00:00:00 2001 From: Danijel Tasov Date: Mon, 25 Sep 2023 09:49:11 +0200 Subject: exit UNKNOWN on -V Signed-off-by: Danijel Tasov --- plugins-root/check_icmp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins-root/check_icmp.c b/plugins-root/check_icmp.c index a4854153..18eed74e 100644 --- a/plugins-root/check_icmp.c +++ b/plugins-root/check_icmp.c @@ -579,7 +579,7 @@ main(int argc, char **argv) break; case 'V': /* version */ print_revision (progname, NP_VERSION); - exit (STATE_OK); + exit (STATE_UNKNOWN); case 'h': /* help */ print_help (); exit (STATE_UNKNOWN); -- cgit v1.2.3-74-g34f1 From 3f0cc2533c21e0ce4c1975eac6146d758275a564 Mon Sep 17 00:00:00 2001 From: Danijel Tasov Date: Mon, 25 Sep 2023 09:49:11 +0200 Subject: Fix compile errors Signed-off-by: Danijel Tasov --- plugins-root/check_icmp.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/plugins-root/check_icmp.c b/plugins-root/check_icmp.c index 18eed74e..d1fe5b11 100644 --- a/plugins-root/check_icmp.c +++ b/plugins-root/check_icmp.c @@ -991,17 +991,17 @@ wait_for_reply(int sock, u_int t) if (jitter_tmp > host->jitter_max) host->jitter_max=jitter_tmp; } - + /* Check if packets in order */ - if (host->last_icmp_seq >= icp.icmp_seq) + if (host->last_icmp_seq >= packet.icp->icmp_seq) host->order_status=STATE_CRITICAL; } host->last_tdiff=tdiff; - - host->last_icmp_seq=icp.icmp_seq; - + + host->last_icmp_seq=packet.icp->icmp_seq; + //printf("%d tdiff %d host->jitter %u host->last_tdiff %u\n", icp.icmp_seq, tdiff, host->jitter, host->last_tdiff); - + host->time_waited += tdiff; host->icmp_recv++; icmp_recv++; @@ -1596,8 +1596,6 @@ add_target_ip(char *arg, struct sockaddr_storage *in) } /* fill out the sockaddr_in struct */ - host->saddr_in.sin_family = AF_INET; - host->saddr_in.sin_addr.s_addr = in->s_addr; host->rtmin = INFINITY; host->rtmax = 0; host->jitter=0; -- cgit v1.2.3-74-g34f1 From 111e25efcd36b00493f07760ae825b285cdb7037 Mon Sep 17 00:00:00 2001 From: Danijel Tasov Date: Mon, 25 Sep 2023 09:49:11 +0200 Subject: Fix speling Signed-off-by: Danijel Tasov --- plugins-root/check_icmp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins-root/check_icmp.c b/plugins-root/check_icmp.c index d1fe5b11..e77682ce 100644 --- a/plugins-root/check_icmp.c +++ b/plugins-root/check_icmp.c @@ -736,7 +736,7 @@ main(int argc, char **argv) if(max_completion_time > (u_int)timeout * 1000000) { printf("max_completion_time: %llu timeout: %u\n", max_completion_time, timeout); - printf("Timout must be at lest %llu\n", + printf("Timeout must be at least %llu\n", max_completion_time / 1000000 + 1); } } -- cgit v1.2.3-74-g34f1 From 2d6b467530ea55eea6341be45f759f67216e1f99 Mon Sep 17 00:00:00 2001 From: Danijel Tasov Date: Tue, 26 Sep 2023 10:01:05 +0200 Subject: add missing character --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 02ca61e1..6f903d61 100644 --- a/.gitignore +++ b/.gitignore @@ -94,7 +94,7 @@ NP-VERSION-FILE /gl/limits.h /gl/malloc/dynarray-skeleton.gl.h /gl/malloc/dynarray.gl.h -/gl/stdckdint. +/gl/stdckdint.h # /lib/ /lib/.deps -- cgit v1.2.3-74-g34f1 From 4ed1d74295efe1c41f6a1489e2f187ece0d8452b Mon Sep 17 00:00:00 2001 From: Danijel Tasov Date: Tue, 26 Sep 2023 17:26:43 +0200 Subject: fixed comment Signed-off-by: Danijel Tasov --- plugins-root/check_icmp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins-root/check_icmp.c b/plugins-root/check_icmp.c index e77682ce..e2ce0590 100644 --- a/plugins-root/check_icmp.c +++ b/plugins-root/check_icmp.c @@ -592,7 +592,7 @@ main(int argc, char **argv) get_threshold2(optarg, &warn, &crit,2); pl_mode=1; break; - case 'J': /* packet loss mode */ + case 'J': /* jitter mode */ get_threshold2(optarg, &warn, &crit,3); jitter_mode=1; break; -- cgit v1.2.3-74-g34f1 From 42125d928f3792414290b00e184d8859a90fcd9e Mon Sep 17 00:00:00 2001 From: Danijel Tasov Date: Tue, 26 Sep 2023 17:35:31 +0200 Subject: Add some spaces to the output needed if multiple modes are used at once Signed-off-by: Danijel Tasov --- plugins-root/check_icmp.c | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/plugins-root/check_icmp.c b/plugins-root/check_icmp.c index e2ce0590..a537c9c0 100644 --- a/plugins-root/check_icmp.c +++ b/plugins-root/check_icmp.c @@ -1379,10 +1379,10 @@ finish(int sig) else if((hosts_ok + hosts_warn) >= min_hosts_alive) status = STATE_WARNING; } printf("%s - ", status_string[status]); - + host = list; while(host) { - + if(debug) puts(""); if(i) { if(i < targets) printf(" :: "); @@ -1411,54 +1411,54 @@ finish(int sig) /* rta text output */ if (rta_mode) { if (status == STATE_OK) - printf("rta %0.3fms", host->rta / 1000); + printf(" rta %0.3fms", host->rta / 1000); else if (status==STATE_WARNING && host->rta_status==status) - printf("rta %0.3fms > %0.3fms", (float)host->rta / 1000, (float)warn.rta/1000); + printf(" rta %0.3fms > %0.3fms", (float)host->rta / 1000, (float)warn.rta/1000); else if (status==STATE_CRITICAL && host->rta_status==status) - printf("rta %0.3fms > %0.3fms", (float)host->rta / 1000, (float)crit.rta/1000); + printf(" rta %0.3fms > %0.3fms", (float)host->rta / 1000, (float)crit.rta/1000); } /* pl text output */ if (pl_mode) { if (status == STATE_OK) - printf("lost %u%%", host->pl); + printf(" lost %u%%", host->pl); else if (status==STATE_WARNING && host->pl_status==status) - printf("lost %u%% > %u%%", host->pl, warn.pl); + printf(" lost %u%% > %u%%", host->pl, warn.pl); else if (status==STATE_CRITICAL && host->pl_status==status) - printf("lost %u%% > %u%%", host->pl, crit.pl); + printf(" lost %u%% > %u%%", host->pl, crit.pl); } /* jitter text output */ if (jitter_mode) { if (status == STATE_OK) - printf("jitter %0.3fms", (float)host->jitter); + printf(" jitter %0.3fms", (float)host->jitter); else if (status==STATE_WARNING && host->jitter_status==status) - printf("jitter %0.3fms > %0.3fms", (float)host->jitter, warn.jitter); + printf(" jitter %0.3fms > %0.3fms", (float)host->jitter, warn.jitter); else if (status==STATE_CRITICAL && host->jitter_status==status) - printf("jitter %0.3fms > %0.3fms", (float)host->jitter, crit.jitter); + printf(" jitter %0.3fms > %0.3fms", (float)host->jitter, crit.jitter); } /* mos text output */ if (mos_mode) { if (status == STATE_OK) - printf("MOS %0.1f", (float)host->mos); + printf(" MOS %0.1f", (float)host->mos); else if (status==STATE_WARNING && host->mos_status==status) - printf("MOS %0.1f < %0.1f", (float)host->mos, (float)warn.mos); + printf(" MOS %0.1f < %0.1f", (float)host->mos, (float)warn.mos); else if (status==STATE_CRITICAL && host->mos_status==status) - printf("MOS %0.1f < %0.1f", (float)host->mos, (float)crit.mos); + printf(" MOS %0.1f < %0.1f", (float)host->mos, (float)crit.mos); } /* score text output */ if (score_mode) { if (status == STATE_OK) - printf("Score %u", (int)host->score); + printf(" Score %u", (int)host->score); else if (status==STATE_WARNING && host->score_status==status ) - printf("Score %u < %u", (int)host->score, (int)warn.score); + printf(" Score %u < %u", (int)host->score, (int)warn.score); else if (status==STATE_CRITICAL && host->score_status==status ) - printf("Score %u < %u", (int)host->score, (int)crit.score); + printf(" Score %u < %u", (int)host->score, (int)crit.score); } /* order statis text output */ if (order_mode) { if (status == STATE_OK) - printf("Packets in order"); + printf(" Packets in order"); else if (status==STATE_CRITICAL && host->order_status==status) - printf("Packets out of order"); + printf(" Packets out of order"); } } host = host->next; -- cgit v1.2.3-74-g34f1 From e6d2b0b08b72eaad11de8d85d13ea995ebcb9561 Mon Sep 17 00:00:00 2001 From: Danijel Tasov Date: Wed, 27 Sep 2023 09:52:34 +0200 Subject: cleanup more merge debris Signed-off-by: Danijel Tasov --- plugins-root/check_icmp.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/plugins-root/check_icmp.c b/plugins-root/check_icmp.c index a537c9c0..bb6f85b9 100644 --- a/plugins-root/check_icmp.c +++ b/plugins-root/check_icmp.c @@ -42,6 +42,7 @@ char *progname; const char *copyright = "2005-2008"; const char *email = "devel@monitoring-plugins.org"; +/* what does that do? */ #ifdef __sun #define _XPG4_2 #endif @@ -761,11 +762,7 @@ main(int argc, char **argv) } host = list; -//<<<<<<< HEAD FIXME - table = (struct rta_host**)malloc(sizeof(struct rta_host **) * targets); -//======= -// table = malloc(sizeof(struct rta_host *) * targets); -//>>>>>>> jitter-orig + table = malloc(sizeof(struct rta_host *) * targets); i = 0; while(host) { host->id = i*packets; @@ -1473,11 +1470,9 @@ finish(int sig) while(host) { if(debug) puts(""); if (rta_mode && host->pl<100) { - // FIXME printf("%srta=%0.3fms;%0.3f;%0.3f;0; %srtmax=%0.3fms;;;; %srtmin=%0.3fms;;;; ",(targets > 1) ? host->name : "", (float)host->rta / 1000, (float)warn.rta / 1000, (float)crit.rta / 1000, (targets > 1) ? host->name : "", (float)host->rtmax / 1000, (targets > 1) ? host->name : "", (float)host->rtmin / 1000); - printf("%srta=%0.3fms;%0.3f;%0.3f;0; %spl=%u%%;%u;%u;; %srtmax=%0.3fms;;;; %srtmin=%0.3fms;;;; ", + printf("%srta=%0.3fms;%0.3f;%0.3f;0; %srtmax=%0.3fms;;;; %srtmin=%0.3fms;;;; ", (targets > 1) ? host->name : "", host->rta / 1000, (float)warn.rta / 1000, (float)crit.rta / 1000, - (targets > 1) ? host->name : "", host->pl, warn.pl, crit.pl, (targets > 1) ? host->name : "", (float)host->rtmax / 1000, (targets > 1) ? host->name : "", (host->rtmin < INFINITY) ? (float)host->rtmin / 1000 : (float)0); } -- cgit v1.2.3-74-g34f1 From a0eb21988917f81a369208872c92465785ee866f Mon Sep 17 00:00:00 2001 From: Danijel Tasov Date: Thu, 28 Sep 2023 15:41:52 +0200 Subject: update-po Signed-off-by: Danijel Tasov --- plugins-root/check_icmp.c | 2 +- po/de.po | 24 +++++++++++++++++++++++- po/fr.po | 24 +++++++++++++++++++++++- po/monitoring-plugins.pot | 24 +++++++++++++++++++++++- 4 files changed, 70 insertions(+), 4 deletions(-) diff --git a/plugins-root/check_icmp.c b/plugins-root/check_icmp.c index bb6f85b9..f7e091af 100644 --- a/plugins-root/check_icmp.c +++ b/plugins-root/check_icmp.c @@ -1943,7 +1943,7 @@ print_help(void) printf (" %s\n", _("verbose")); printf ("\n"); printf ("%s\n", _("Notes:")); - printf ("%s\n", _("If not mode R,P,J,M,S or O is informed, default icmp behavior, RTA and packet loss")); + printf (" %s\n", _("If none of R,P,J,M,S or O is specified, default behavior is -R -P")); printf (" %s\n", _("The -H switch is optional. Naming a host (or several) to check is not.")); printf ("\n"); printf (" %s\n", _("Threshold format for -w and -c is 200.25,60% for 200.25 msec RTA and 60%")); diff --git a/po/de.po b/po/de.po index 9ea32df9..3a34db46 100644 --- a/po/de.po +++ b/po/de.po @@ -9,7 +9,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: devel@monitoring-plugins.org\n" -"POT-Creation-Date: 2023-09-22 15:36+0200\n" +"POT-Creation-Date: 2023-09-27 12:16+0200\n" "PO-Revision-Date: 2004-12-23 17:46+0100\n" "Last-Translator: \n" "Language-Team: Monitoring Plugin Development Team \n" "Language-Team: LANGUAGE \n" @@ -4892,6 +4892,25 @@ msgstr "" msgid "critical threshold (currently " msgstr "" +msgid "" +"RTA, round trip average, mode warning,critical, ex. 100ms,200ms unit in ms" +msgstr "" + +msgid "packet loss mode, ex. 40%,50% , unit in %" +msgstr "" + +msgid "jitter mode warning,critical, ex. 40.000ms,50.000ms , unit in ms " +msgstr "" + +msgid "MOS mode, between 0 and 4.4 warning,critical, ex. 3.5,3.0" +msgstr "" + +msgid "score mode, max value 100 warning,critical, ex. 80,70 " +msgstr "" + +msgid "detect out of order ICMP packts " +msgstr "" + msgid "specify a source IP address or device name" msgstr "" @@ -4922,6 +4941,9 @@ msgstr "" msgid "verbose" msgstr "" +msgid "If none of R,P,J,M,S or O is specified, default behavior is -R -P" +msgstr "" + msgid "The -H switch is optional. Naming a host (or several) to check is not." msgstr "" -- cgit v1.2.3-74-g34f1 From 396bcf50ce23fc34d14e4ef8fb6d9843b977f95c Mon Sep 17 00:00:00 2001 From: Danijel Tasov Date: Wed, 4 Oct 2023 10:21:41 +0200 Subject: adjust check_icmp tests --- plugins-root/check_icmp.c | 2 +- plugins-root/t/check_icmp.t | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/plugins-root/check_icmp.c b/plugins-root/check_icmp.c index f7e091af..a9a24ee8 100644 --- a/plugins-root/check_icmp.c +++ b/plugins-root/check_icmp.c @@ -1404,7 +1404,7 @@ finish(int sig) } } else { /* !icmp_recv */ - printf("%s ", host->name); + printf("%s:", host->name); /* rta text output */ if (rta_mode) { if (status == STATE_OK) diff --git a/plugins-root/t/check_icmp.t b/plugins-root/t/check_icmp.t index 96addd3b..07e175e9 100644 --- a/plugins-root/t/check_icmp.t +++ b/plugins-root/t/check_icmp.t @@ -18,8 +18,8 @@ if ($allow_sudo eq "yes" or $> == 0) { } my $sudo = $> == 0 ? '' : 'sudo'; -my $successOutput = '/OK - .*?: rta (?:[\d\.]+ms)|(?:nan), lost \d+%/'; -my $failureOutput = '/(WARNING|CRITICAL) - .*?: rta [\d\.]+ms, lost \d%/'; +my $successOutput = '/OK - .*? rta (?:[\d\.]+ms)|(?:nan), lost \d+%/'; +my $failureOutput = '/(WARNING|CRITICAL) - .*? rta [\d\.]+ms > [\d\.]+ms/'; my $host_responsive = getTestParameter( "NP_HOST_RESPONSIVE", "The hostname of system responsive to network requests", @@ -54,7 +54,7 @@ is( $res->return_code, 2, "Syntax ok, with forced critical" ); like( $res->output, $failureOutput, "Output OK" ); $res = NPTest->testCmd( - "$sudo ./check_icmp -H $host_nonresponsive -w 10000ms,100% -c 10000ms,100%" + "$sudo ./check_icmp -H $host_nonresponsive -w 10000ms,100% -c 10000ms,100% -t 2" ); is( $res->return_code, 2, "Timeout - host nonresponsive" ); like( $res->output, '/100%/', "Error contains '100%' string (for 100% packet loss)" ); @@ -66,13 +66,13 @@ is( $res->return_code, 3, "No hostname" ); like( $res->output, '/No hosts to check/', "Output with appropriate error message"); $res = NPTest->testCmd( - "$sudo ./check_icmp -H $host_nonresponsive -w 10000ms,100% -c 10000ms,100% -n 1 -m 0" + "$sudo ./check_icmp -H $host_nonresponsive -w 10000ms,100% -c 10000ms,100% -n 1 -m 0 -t 2" ); is( $res->return_code, 0, "One host nonresponsive - zero required" ); like( $res->output, $successOutput, "Output OK" ); $res = NPTest->testCmd( - "$sudo ./check_icmp -H $host_responsive -H $host_nonresponsive -w 10000ms,100% -c 10000ms,100% -n 1 -m 1" + "$sudo ./check_icmp -H $host_responsive -H $host_nonresponsive -w 10000ms,100% -c 10000ms,100% -n 1 -m 1 -t 2" ); is( $res->return_code, 0, "One of two host nonresponsive - one required" ); like( $res->output, $successOutput, "Output OK" ); -- cgit v1.2.3-74-g34f1 From 6585711b0b5beafed69881b66d9c105dad658a3f Mon Sep 17 00:00:00 2001 From: Danijel Tasov Date: Wed, 4 Oct 2023 10:22:35 +0200 Subject: fix host count on when checking multiple hosts --- plugins-root/check_icmp.c | 45 ++++++++++++++++++++++++--------------------- 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/plugins-root/check_icmp.c b/plugins-root/check_icmp.c index a9a24ee8..321612bb 100644 --- a/plugins-root/check_icmp.c +++ b/plugins-root/check_icmp.c @@ -1236,6 +1236,7 @@ finish(int sig) {"OK", "WARNING", "CRITICAL", "UNKNOWN", "DEPENDENT"}; int hosts_ok = 0; int hosts_warn = 0; + int this_status; double R; alarm(0); @@ -1256,6 +1257,7 @@ finish(int sig) host = list; while(host) { + this_status = STATE_OK; if(!host->icmp_recv) { /* rta 0 is ofcourse not entirely correct, but will still show up * conspicuously as missing entries in perfparse and cacti */ @@ -1296,79 +1298,80 @@ finish(int sig) pl_mode=1; } +#define THIS_STATUS_WARNING this_status = (this_status <= STATE_WARNING ? STATE_WARNING : this_status) /* Check which mode is on and do the warn / Crit stuff */ if (rta_mode) { if(rta >= crit.rta) { + this_status = STATE_CRITICAL; status = STATE_CRITICAL; host->rta_status=STATE_CRITICAL; } else if(status!=STATE_CRITICAL && (rta >= warn.rta)) { + THIS_STATUS_WARNING; status = STATE_WARNING; - hosts_warn++; host->rta_status=STATE_WARNING; } - else { - hosts_ok++; - } } if (pl_mode) { if(pl >= crit.pl) { + this_status = STATE_CRITICAL; status = STATE_CRITICAL; host->pl_status=STATE_CRITICAL; } else if(status!=STATE_CRITICAL && (pl >= warn.pl)) { + THIS_STATUS_WARNING; status = STATE_WARNING; - hosts_warn++; host->pl_status=STATE_WARNING; } - else { - hosts_ok++; - } } if (jitter_mode) { if(host->jitter >= crit.jitter) { + this_status = STATE_CRITICAL; status = STATE_CRITICAL; host->jitter_status=STATE_CRITICAL; } else if(status!=STATE_CRITICAL && (host->jitter >= warn.jitter)) { + THIS_STATUS_WARNING; status = STATE_WARNING; - hosts_warn++; host->jitter_status=STATE_WARNING; } - else { - hosts_ok++; - } } if (mos_mode) { if(host->mos <= crit.mos) { + this_status = STATE_CRITICAL; status = STATE_CRITICAL; host->mos_status=STATE_CRITICAL; } else if(status!=STATE_CRITICAL && (host->mos <= warn.mos)) { + THIS_STATUS_WARNING; status = STATE_WARNING; - hosts_warn++; host->mos_status=STATE_WARNING; } - else { - hosts_ok++; - } } if (score_mode) { if(host->score <= crit.score) { + this_status = STATE_CRITICAL; status = STATE_CRITICAL; host->score_status=STATE_CRITICAL; } else if(status!=STATE_CRITICAL && (host->score <= warn.score)) { + THIS_STATUS_WARNING; status = STATE_WARNING; - score_mode++; host->score_status=STATE_WARNING; } - else { - hosts_ok++; - } } + + if (this_status == STATE_WARNING) { + hosts_warn++; + } + else if (this_status == STATE_OK) { + hosts_ok++; + } + host = host->next; } + + /* this is inevitable */ if(!targets_alive) status = STATE_CRITICAL; if(min_hosts_alive > -1) { @@ -1404,7 +1407,7 @@ finish(int sig) } } else { /* !icmp_recv */ - printf("%s:", host->name); + printf("%s", host->name); /* rta text output */ if (rta_mode) { if (status == STATE_OK) -- cgit v1.2.3-74-g34f1 From df57a23e0ace0c1d1c19038fd3834b20742ef24a Mon Sep 17 00:00:00 2001 From: Danijel Tasov Date: Wed, 4 Oct 2023 10:39:30 +0200 Subject: update failure regex --- plugins-root/t/check_icmp.t | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins-root/t/check_icmp.t b/plugins-root/t/check_icmp.t index 07e175e9..9fb8fa06 100644 --- a/plugins-root/t/check_icmp.t +++ b/plugins-root/t/check_icmp.t @@ -19,7 +19,7 @@ if ($allow_sudo eq "yes" or $> == 0) { my $sudo = $> == 0 ? '' : 'sudo'; my $successOutput = '/OK - .*? rta (?:[\d\.]+ms)|(?:nan), lost \d+%/'; -my $failureOutput = '/(WARNING|CRITICAL) - .*? rta [\d\.]+ms > [\d\.]+ms/'; +my $failureOutput = '/(WARNING|CRITICAL) - .*? rta (?:[\d\.]+ms > [\d\.]+ms|nan)/'; my $host_responsive = getTestParameter( "NP_HOST_RESPONSIVE", "The hostname of system responsive to network requests", -- cgit v1.2.3-74-g34f1 From 4e7eb550791afdb5d3e496a84be00286ccb6fb5b Mon Sep 17 00:00:00 2001 From: Danijel Tasov Date: Wed, 4 Oct 2023 11:34:25 +0200 Subject: add some basic tests for the new modes Signed-off-by: Danijel Tasov --- plugins-root/t/check_icmp.t | 48 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/plugins-root/t/check_icmp.t b/plugins-root/t/check_icmp.t index 9fb8fa06..4f9db868 100644 --- a/plugins-root/t/check_icmp.t +++ b/plugins-root/t/check_icmp.t @@ -12,7 +12,7 @@ my $allow_sudo = getTestParameter( "NP_ALLOW_SUDO", "no" ); if ($allow_sudo eq "yes" or $> == 0) { - plan tests => 20; + plan tests => 39; } else { plan skip_all => "Need sudo to test check_icmp"; } @@ -94,3 +94,49 @@ $res = NPTest->testCmd( ); is( $res->return_code, 0, "Try max packet size" ); like( $res->output, $successOutput, "Output OK - Didn't overflow" ); + +$res = NPTest->testCmd( + "$sudo ./check_icmp -H $host_responsive -R 100,100 -n 1 -t 2" + ); +is( $res->return_code, 0, "rta works" ); +like( $res->output, $successOutput, "Output OK" ); +$res = NPTest->testCmd( + "$sudo ./check_icmp -H $host_responsive -P 80,90 -n 1 -t 2" + ); +is( $res->return_code, 0, "pl works" ); +like( $res->output, '/lost 0%/', "Output OK" ); + +$res = NPTest->testCmd( + "$sudo ./check_icmp -H $host_responsive -J 80,90 -t 2" + ); +is( $res->return_code, 0, "jitter works" ); +like( $res->output, '/jitter \d/', "Output OK" ); + +$res = NPTest->testCmd( + "$sudo ./check_icmp -H $host_responsive -M 4,3 -t 2" + ); +is( $res->return_code, 0, "mos works" ); +like( $res->output, '/MOS \d/', "Output OK" ); + +$res = NPTest->testCmd( + "$sudo ./check_icmp -H $host_responsive -S 80,70 -t 2" + ); +is( $res->return_code, 0, "score works" ); +like( $res->output, '/Score \d/', "Output OK" ); + +$res = NPTest->testCmd( + "$sudo ./check_icmp -H $host_responsive -O -t 2" + ); +is( $res->return_code, 0, "order works" ); +like( $res->output, '/Packets in order/', "Output OK" ); + +$res = NPTest->testCmd( + "$sudo ./check_icmp -H $host_responsive -O -S 80,70 -M 4,3 -J 80,90 -P 80,90 -R 100,100 -t 2" + ); +is( $res->return_code, 0, "order works" ); +like( $res->output, '/Packets in order/', "Output OK" ); +like( $res->output, '/Score \d/', "Output OK" ); +like( $res->output, '/MOS \d/', "Output OK" ); +like( $res->output, '/jitter \d/', "Output OK" ); +like( $res->output, '/lost 0%/', "Output OK" ); +like( $res->output, $successOutput, "Output OK" ); -- cgit v1.2.3-74-g34f1 From 843c0bfa46ed6d02c9b4998f66a9cc3a2834271d Mon Sep 17 00:00:00 2001 From: Danijel Tasov Date: Wed, 4 Oct 2023 11:44:22 +0200 Subject: remove sun ifdef my be readded later with proper comments Signed-off-by: Danijel Tasov --- plugins-root/check_icmp.c | 5 ----- 1 file changed, 5 deletions(-) diff --git a/plugins-root/check_icmp.c b/plugins-root/check_icmp.c index 321612bb..4a72315d 100644 --- a/plugins-root/check_icmp.c +++ b/plugins-root/check_icmp.c @@ -42,11 +42,6 @@ char *progname; const char *copyright = "2005-2008"; const char *email = "devel@monitoring-plugins.org"; -/* what does that do? */ -#ifdef __sun -#define _XPG4_2 -#endif - /** Monitoring Plugins basic includes */ #include "common.h" #include "netutils.h" -- cgit v1.2.3-74-g34f1 From 1f49981982cb47227457f8b37997f5639fceb778 Mon Sep 17 00:00:00 2001 From: Danijel Tasov Date: Wed, 4 Oct 2023 11:52:09 +0200 Subject: readability improvements Signed-off-by: Danijel Tasov --- plugins-root/check_icmp.c | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/plugins-root/check_icmp.c b/plugins-root/check_icmp.c index 4a72315d..246b4665 100644 --- a/plugins-root/check_icmp.c +++ b/plugins-root/check_icmp.c @@ -1478,13 +1478,31 @@ finish(int sig) printf("%spl=%u%%;%u;%u;0;100 ", (targets > 1) ? host->name : "", host->pl, warn.pl, crit.pl); } if (jitter_mode && host->pl<100) { - printf("%sjitter_avg=%0.3fms;%0.3f;%0.3f;0; %sjitter_max=%0.3fms;;;; %sjitter_min=%0.3fms;;;; ", (targets > 1) ? host->name : "", (float)host->jitter, (float)warn.jitter, (float)crit.jitter, (targets > 1) ? host->name : "", (float)host->jitter_max / 1000, (targets > 1) ? host->name : "",(float)host->jitter_min / 1000); + printf("%sjitter_avg=%0.3fms;%0.3f;%0.3f;0; %sjitter_max=%0.3fms;;;; %sjitter_min=%0.3fms;;;; ", + (targets > 1) ? host->name : "", + (float)host->jitter, + (float)warn.jitter, + (float)crit.jitter, + (targets > 1) ? host->name : "", + (float)host->jitter_max / 1000, (targets > 1) ? host->name : "", + (float)host->jitter_min / 1000 + ); } if (mos_mode && host->pl<100) { - printf("%smos=%0.1f;%0.1f;%0.1f;0;5 ", (targets > 1) ? host->name : "", (float)host->mos, (float)warn.mos, (float)crit.mos); + printf("%smos=%0.1f;%0.1f;%0.1f;0;5 ", + (targets > 1) ? host->name : "", + (float)host->mos, + (float)warn.mos, + (float)crit.mos + ); } if (score_mode && host->pl<100) { - printf("%sscore=%u;%u;%u;0;100 ", (targets > 1) ? host->name : "", (int)host->score, (int)warn.score, (int)crit.score); + printf("%sscore=%u;%u;%u;0;100 ", + (targets > 1) ? host->name : "", + (int)host->score, + (int)warn.score, + (int)crit.score + ); } host = host->next; } -- cgit v1.2.3-74-g34f1 From dfa5aa4b83c33ed6b609e7f79ebe1f03507b679c Mon Sep 17 00:00:00 2001 From: Danijel Tasov Date: Wed, 4 Oct 2023 11:56:23 +0200 Subject: unnecessary space Signed-off-by: Danijel Tasov --- plugins-root/check_icmp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins-root/check_icmp.c b/plugins-root/check_icmp.c index 246b4665..0401788c 100644 --- a/plugins-root/check_icmp.c +++ b/plugins-root/check_icmp.c @@ -1781,7 +1781,7 @@ get_timevar(const char *str) else if(u == 's') factor = 1000000; /* seconds */ if(debug > 2) printf("factor is %u\n", factor); - i = strtoul(str, &ptr, 0); + i = strtoul(str, &ptr, 0); if(!ptr || *ptr != '.' || strlen(ptr) < 2 || factor == 1) return i * factor; -- cgit v1.2.3-74-g34f1 From e365f9f58eed501baf1a80c47556191a48b99c3f Mon Sep 17 00:00:00 2001 From: Danijel Tasov Date: Fri, 6 Oct 2023 10:51:27 +0200 Subject: do not introduce new ints as bools --- plugins-root/check_icmp.c | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/plugins-root/check_icmp.c b/plugins-root/check_icmp.c index 0401788c..274277b7 100644 --- a/plugins-root/check_icmp.c +++ b/plugins-root/check_icmp.c @@ -242,12 +242,12 @@ static unsigned int warn_down = 1, crit_down = 1; /* host down threshold values static int min_hosts_alive = -1; float pkt_backoff_factor = 1.5; float target_backoff_factor = 1.5; -int rta_mode=0; -int pl_mode=0; -int jitter_mode=0; -int score_mode=0; -int mos_mode=0; -int order_mode=0; +bool rta_mode=false; +bool pl_mode=false; +bool jitter_mode=false; +bool score_mode=false; +bool mos_mode=false; +bool order_mode=false; /** code start **/ static void @@ -582,26 +582,26 @@ main(int argc, char **argv) break; case 'R': /* RTA mode */ get_threshold2(optarg, &warn, &crit,1); - rta_mode=1; + rta_mode=true; break; case 'P': /* packet loss mode */ get_threshold2(optarg, &warn, &crit,2); - pl_mode=1; + pl_mode=true; break; case 'J': /* jitter mode */ get_threshold2(optarg, &warn, &crit,3); - jitter_mode=1; + jitter_mode=true; break; case 'M': /* MOS mode */ get_threshold2(optarg, &warn, &crit,4); - mos_mode=1; + mos_mode=true; break; case 'S': /* score mode */ get_threshold2(optarg, &warn, &crit,5); - score_mode=1; + score_mode=true; break; case 'O': /* out of order mode */ - order_mode=1; + order_mode=true; break; } } @@ -758,6 +758,7 @@ main(int argc, char **argv) host = list; table = malloc(sizeof(struct rta_host *) * targets); + i = 0; while(host) { host->id = i*packets; @@ -1831,7 +1832,8 @@ get_threshold(char *str, threshold *th) static int get_threshold2(char *str, threshold *warn, threshold *crit, int type) { - char *p = NULL, i = 0; + char *p = NULL; + bool i = false; if(!str || !strlen(str) || !warn || !crit) return -1; /* pointer magic slims code by 10 lines. i is bof-stop on stupid libc's */ @@ -1851,7 +1853,7 @@ get_threshold2(char *str, threshold *warn, threshold *crit, int type) else if (type==5) crit->score = atof(p+1); } - i = 1; + i = true; p--; } if (type==1) -- cgit v1.2.3-74-g34f1 From 1ad7e163fad45d33a44f398fb2416f1b9086469a Mon Sep 17 00:00:00 2001 From: Danijel Tasov Date: Fri, 6 Oct 2023 10:54:20 +0200 Subject: check malloc --- plugins-root/check_icmp.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/plugins-root/check_icmp.c b/plugins-root/check_icmp.c index 274277b7..197ce32f 100644 --- a/plugins-root/check_icmp.c +++ b/plugins-root/check_icmp.c @@ -758,6 +758,10 @@ main(int argc, char **argv) host = list; table = malloc(sizeof(struct rta_host *) * targets); + if(!table) { + crash("main(): malloc failed for host table"); + return 3; + } i = 0; while(host) { -- cgit v1.2.3-74-g34f1 From 6d7d9a87aa74f00ed5603e13ebf96bb2b72e084a Mon Sep 17 00:00:00 2001 From: RincewindsHat <12514511+RincewindsHat@users.noreply.github.com> Date: Fri, 6 Oct 2023 15:08:52 +0200 Subject: Refactor get_threshold2 to be barely understandable --- plugins-root/check_icmp.c | 100 ++++++++++++++++++++++++++++++---------------- 1 file changed, 65 insertions(+), 35 deletions(-) diff --git a/plugins-root/check_icmp.c b/plugins-root/check_icmp.c index 197ce32f..79b93571 100644 --- a/plugins-root/check_icmp.c +++ b/plugins-root/check_icmp.c @@ -176,6 +176,16 @@ typedef union icmp_packet { #define MODE_ALL 2 #define MODE_ICMP 3 +enum enum_threshold_mode { + const_rta_mode, + const_packet_loss_mode, + const_jitter_mode, + const_mos_mode, + const_score_mode +}; + +typedef enum enum_threshold_mode threshold_mode; + /* the different ping types we can do * TODO: investigate ARP ping as well */ #define HAVE_ICMP 1 @@ -205,7 +215,7 @@ static int wait_for_reply(int, u_int); static int recvfrom_wto(int, void *, unsigned int, struct sockaddr *, u_int *, struct timeval*); static int send_icmp_ping(int, struct rta_host *); static int get_threshold(char *str, threshold *th); -static int get_threshold2(char *str, threshold *, threshold *, int type); +static int get_threshold2(char *str, size_t length, threshold *, threshold *, threshold_mode mode); static void run_checks(void); static void set_source_ip(char *); static int add_target(char *); @@ -581,23 +591,23 @@ main(int argc, char **argv) exit (STATE_UNKNOWN); break; case 'R': /* RTA mode */ - get_threshold2(optarg, &warn, &crit,1); + get_threshold2(optarg, strlen(optarg), &warn, &crit, const_rta_mode); rta_mode=true; break; case 'P': /* packet loss mode */ - get_threshold2(optarg, &warn, &crit,2); + get_threshold2(optarg, strlen(optarg), &warn, &crit, const_packet_loss_mode); pl_mode=true; break; case 'J': /* jitter mode */ - get_threshold2(optarg, &warn, &crit,3); + get_threshold2(optarg, strlen(optarg), &warn, &crit, const_jitter_mode); jitter_mode=true; break; case 'M': /* MOS mode */ - get_threshold2(optarg, &warn, &crit,4); + get_threshold2(optarg, strlen(optarg), &warn, &crit, const_mos_mode); mos_mode=true; break; case 'S': /* score mode */ - get_threshold2(optarg, &warn, &crit,5); + get_threshold2(optarg, strlen(optarg), &warn, &crit, const_score_mode); score_mode=true; break; case 'O': /* out of order mode */ @@ -1834,43 +1844,63 @@ get_threshold(char *str, threshold *th) /* not too good at checking errors, but it'll do (main() should barfe on -1) */ static int -get_threshold2(char *str, threshold *warn, threshold *crit, int type) +get_threshold2(char *str, size_t length, threshold *warn, threshold *crit, threshold_mode mode) { + if (!str || !length || !warn || !crit) return -1; + char *p = NULL; - bool i = false; + bool first_iteration = true; + + // pointer magic slims code by 10 lines. i is bof-stop on stupid libc's + // p points to the last char in str + p = &str[length - 1]; - if(!str || !strlen(str) || !warn || !crit) return -1; - /* pointer magic slims code by 10 lines. i is bof-stop on stupid libc's */ - p = &str[strlen(str) - 1]; while(p != &str[0]) { - if( (*p == 'm') || (*p == '%') ) *p = '\0'; - else if(*p == ',' && i) { + if( (*p == 'm') || (*p == '%') ) { + *p = '\0'; + } else if(*p == ',' && !first_iteration) { *p = '\0'; /* reset it so get_timevar(str) works nicely later */ - if (type==1) - crit->rta = atof(p+1)*1000; - else if (type==2) - crit->pl = (unsigned char)strtoul(p+1, NULL, 0); - else if (type==3) - crit->jitter = atof(p+1); - else if (type==4) - crit->mos = atof(p+1); - else if (type==5) - crit->score = atof(p+1); + + switch (mode) { + case const_rta_mode: + crit->rta = atof(p+1)*1000; + break; + case const_packet_loss_mode: + crit->pl = (unsigned char)strtoul(p+1, NULL, 0); + break; + case const_jitter_mode: + crit->jitter = atof(p+1); + break; + case const_mos_mode: + crit->mos = atof(p+1); + break; + case const_score_mode: + crit->score = atof(p+1); + break; + } } - i = true; + first_iteration = false; p--; } - if (type==1) - warn->rta = atof(p)*1000; - else if (type==2) - warn->pl = (unsigned char)strtoul(p, NULL, 0); - if (type==3) - warn->jitter = atof(p); - else if (type==4) - warn->mos = atof(p); - else if (type==5) - warn->score = atof(p); - return 0; + + switch (mode) { + case const_rta_mode: + warn->rta = atof(p)*1000; + break; + case const_packet_loss_mode: + warn->pl = (unsigned char)strtoul(p, NULL, 0); + break; + case const_jitter_mode: + warn->jitter = atof(p); + break; + case const_mos_mode: + warn->mos = atof(p); + break; + case const_score_mode: + warn->score = atof(p); + break; + } + return 0; } unsigned short -- cgit v1.2.3-74-g34f1 From d54588eaf0fc1ec35cfac988dbb2764069fbc909 Mon Sep 17 00:00:00 2001 From: RincewindsHat <12514511+RincewindsHat@users.noreply.github.com> Date: Fri, 6 Oct 2023 15:19:33 +0200 Subject: Update comment --- plugins-root/check_icmp.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins-root/check_icmp.c b/plugins-root/check_icmp.c index 79b93571..541e7955 100644 --- a/plugins-root/check_icmp.c +++ b/plugins-root/check_icmp.c @@ -43,7 +43,7 @@ const char *copyright = "2005-2008"; const char *email = "devel@monitoring-plugins.org"; /** Monitoring Plugins basic includes */ -#include "common.h" +#include "../plugins/common.h" #include "netutils.h" #include "utils.h" @@ -1851,10 +1851,10 @@ get_threshold2(char *str, size_t length, threshold *warn, threshold *crit, thres char *p = NULL; bool first_iteration = true; - // pointer magic slims code by 10 lines. i is bof-stop on stupid libc's // p points to the last char in str p = &str[length - 1]; + // first_iteration is bof-stop on stupid libc's while(p != &str[0]) { if( (*p == 'm') || (*p == '%') ) { *p = '\0'; -- cgit v1.2.3-74-g34f1 From aba1ef97f3fdfea191fe8ace2a41551be3dab027 Mon Sep 17 00:00:00 2001 From: RincewindsHat <12514511+RincewindsHat@users.noreply.github.com> Date: Fri, 6 Oct 2023 16:04:43 +0200 Subject: Change function type of get_thresholds to better reflect the options and describe it in general --- plugins-root/check_icmp.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/plugins-root/check_icmp.c b/plugins-root/check_icmp.c index 541e7955..ce88bec7 100644 --- a/plugins-root/check_icmp.c +++ b/plugins-root/check_icmp.c @@ -215,7 +215,7 @@ static int wait_for_reply(int, u_int); static int recvfrom_wto(int, void *, unsigned int, struct sockaddr *, u_int *, struct timeval*); static int send_icmp_ping(int, struct rta_host *); static int get_threshold(char *str, threshold *th); -static int get_threshold2(char *str, size_t length, threshold *, threshold *, threshold_mode mode); +static bool get_threshold2(char *str, size_t length, threshold *, threshold *, threshold_mode mode); static void run_checks(void); static void set_source_ip(char *); static int add_target(char *); @@ -1842,11 +1842,18 @@ get_threshold(char *str, threshold *th) return 0; } -/* not too good at checking errors, but it'll do (main() should barfe on -1) */ -static int -get_threshold2(char *str, size_t length, threshold *warn, threshold *crit, threshold_mode mode) -{ - if (!str || !length || !warn || !crit) return -1; +/* + * This functions receives a pointer to a string which should contain a threshold for the + * rta, packet_loss, jitter, mos or score mode in the form number,number[m|%]* assigns the + * parsed number to the corresponding threshold variable. + * @param[in,out] str String containing the given threshold values + * @param[in] length strlen(str) + * @param[out] warn Pointer to the warn threshold struct to which the values should be assigned + * @param[out] crit Pointer to the crit threshold struct to which the values should be assigned + * @param[in] mode Determines whether this a threshold vor rta, packet_loss, jitter, mos or score (exclusively) + */ +static bool get_threshold2(char *str, size_t length, threshold *warn, threshold *crit, threshold_mode mode) { + if (!str || !length || !warn || !crit) return false; char *p = NULL; bool first_iteration = true; @@ -1900,7 +1907,7 @@ get_threshold2(char *str, size_t length, threshold *warn, threshold *crit, thres warn->score = atof(p); break; } - return 0; + return true; } unsigned short -- cgit v1.2.3-74-g34f1 From 9faa417aeb468be0ebb646ee3fc276014795e76f Mon Sep 17 00:00:00 2001 From: RincewindsHat <12514511+RincewindsHat@users.noreply.github.com> Date: Fri, 6 Oct 2023 16:05:01 +0200 Subject: Remove useless return after crash --- plugins-root/check_icmp.c | 1 - 1 file changed, 1 deletion(-) diff --git a/plugins-root/check_icmp.c b/plugins-root/check_icmp.c index ce88bec7..c71ea29c 100644 --- a/plugins-root/check_icmp.c +++ b/plugins-root/check_icmp.c @@ -770,7 +770,6 @@ main(int argc, char **argv) table = malloc(sizeof(struct rta_host *) * targets); if(!table) { crash("main(): malloc failed for host table"); - return 3; } i = 0; -- cgit v1.2.3-74-g34f1 From 19dc0039365e5cae0ed866c10202c50338f70b0a Mon Sep 17 00:00:00 2001 From: RincewindsHat <12514511+RincewindsHat@users.noreply.github.com> Date: Sat, 7 Oct 2023 11:48:57 +0200 Subject: Do some actual error checking on the threshold parser --- plugins-root/check_icmp.c | 38 ++++++++++++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 6 deletions(-) diff --git a/plugins-root/check_icmp.c b/plugins-root/check_icmp.c index c71ea29c..7140aa50 100644 --- a/plugins-root/check_icmp.c +++ b/plugins-root/check_icmp.c @@ -526,7 +526,8 @@ main(int argc, char **argv) /* Reset argument scanning */ optind = 1; - unsigned long size; + unsigned long size; + bool err; /* parse the arguments */ for(i = 1; i < argc; i++) { while((arg = getopt(argc, argv, opts_str)) != EOF) { @@ -591,23 +592,48 @@ main(int argc, char **argv) exit (STATE_UNKNOWN); break; case 'R': /* RTA mode */ - get_threshold2(optarg, strlen(optarg), &warn, &crit, const_rta_mode); + err = get_threshold2(optarg, strlen(optarg), &warn, &crit, const_rta_mode); + + if (!err) { + crash("Failed to parse RTA threshold"); + } + rta_mode=true; break; case 'P': /* packet loss mode */ - get_threshold2(optarg, strlen(optarg), &warn, &crit, const_packet_loss_mode); + err = get_threshold2(optarg, strlen(optarg), &warn, &crit, const_packet_loss_mode); + + if (!err) { + crash("Failed to parse packet loss threshold"); + } + pl_mode=true; break; case 'J': /* jitter mode */ - get_threshold2(optarg, strlen(optarg), &warn, &crit, const_jitter_mode); + err = get_threshold2(optarg, strlen(optarg), &warn, &crit, const_jitter_mode); + + if (!err) { + crash("Failed to parse jitter threshold"); + } + jitter_mode=true; break; case 'M': /* MOS mode */ - get_threshold2(optarg, strlen(optarg), &warn, &crit, const_mos_mode); + err = get_threshold2(optarg, strlen(optarg), &warn, &crit, const_mos_mode); + + if (!err) { + crash("Failed to parse MOS threshold"); + } + mos_mode=true; break; case 'S': /* score mode */ - get_threshold2(optarg, strlen(optarg), &warn, &crit, const_score_mode); + err = get_threshold2(optarg, strlen(optarg), &warn, &crit, const_score_mode); + + if (!err) { + crash("Failed to parse score threshold"); + } + score_mode=true; break; case 'O': /* out of order mode */ -- cgit v1.2.3-74-g34f1 From b81847cb5f520ec23a1c907be330c1ad8eeeba2d Mon Sep 17 00:00:00 2001 From: RincewindsHat <12514511+RincewindsHat@users.noreply.github.com> Date: Sat, 7 Oct 2023 11:49:27 +0200 Subject: Refactor new threshold parser --- plugins-root/check_icmp.c | 82 ++++++++++++++++++++++++++--------------------- 1 file changed, 45 insertions(+), 37 deletions(-) diff --git a/plugins-root/check_icmp.c b/plugins-root/check_icmp.c index 7140aa50..7c04ef21 100644 --- a/plugins-root/check_icmp.c +++ b/plugins-root/check_icmp.c @@ -216,6 +216,7 @@ static int recvfrom_wto(int, void *, unsigned int, struct sockaddr *, u_int *, s static int send_icmp_ping(int, struct rta_host *); static int get_threshold(char *str, threshold *th); static bool get_threshold2(char *str, size_t length, threshold *, threshold *, threshold_mode mode); +static bool parse_threshold2_helper(char *s, size_t length, threshold *thr, threshold_mode mode); static void run_checks(void); static void set_source_ip(char *); static int add_target(char *); @@ -1880,59 +1881,66 @@ get_threshold(char *str, threshold *th) static bool get_threshold2(char *str, size_t length, threshold *warn, threshold *crit, threshold_mode mode) { if (!str || !length || !warn || !crit) return false; - char *p = NULL; - bool first_iteration = true; // p points to the last char in str - p = &str[length - 1]; + char *p = &str[length - 1]; // first_iteration is bof-stop on stupid libc's + bool first_iteration = true; + while(p != &str[0]) { if( (*p == 'm') || (*p == '%') ) { *p = '\0'; } else if(*p == ',' && !first_iteration) { *p = '\0'; /* reset it so get_timevar(str) works nicely later */ - switch (mode) { - case const_rta_mode: - crit->rta = atof(p+1)*1000; - break; - case const_packet_loss_mode: - crit->pl = (unsigned char)strtoul(p+1, NULL, 0); - break; - case const_jitter_mode: - crit->jitter = atof(p+1); - break; - case const_mos_mode: - crit->mos = atof(p+1); - break; - case const_score_mode: - crit->score = atof(p+1); - break; + char *start_of_value = p + 1; + + if (!parse_threshold2_helper(start_of_value, strlen(start_of_value), crit, mode)){ + return false; } + } first_iteration = false; p--; } - switch (mode) { - case const_rta_mode: - warn->rta = atof(p)*1000; - break; - case const_packet_loss_mode: - warn->pl = (unsigned char)strtoul(p, NULL, 0); - break; - case const_jitter_mode: - warn->jitter = atof(p); - break; - case const_mos_mode: - warn->mos = atof(p); - break; - case const_score_mode: - warn->score = atof(p); - break; - } - return true; + return parse_threshold2_helper(p, strlen(p), warn, mode); +} + +static bool parse_threshold2_helper(char *s, size_t length, threshold *thr, threshold_mode mode) { + char *resultChecker = {0}; + + switch (mode) { + case const_rta_mode: + thr->rta = strtod(s, &resultChecker) * 1000; + break; + case const_packet_loss_mode: + thr->pl = (unsigned char)strtoul(s, &resultChecker, 0); + break; + case const_jitter_mode: + thr->jitter = strtod(s, &resultChecker); + + break; + case const_mos_mode: + thr->mos = strtod(s, &resultChecker); + break; + case const_score_mode: + thr->score = strtod(s, &resultChecker); + break; + } + + if (resultChecker == s) { + // Failed to parse + return false; + } + + if (resultChecker != (s + length)) { + // Trailing symbols + return false; + } + + return true; } unsigned short -- cgit v1.2.3-74-g34f1 From da59856f99815cb86c2b6c633a4a49bc6895fd7b Mon Sep 17 00:00:00 2001 From: RincewindsHat <12514511+RincewindsHat@users.noreply.github.com> Date: Sat, 7 Oct 2023 22:43:44 +0200 Subject: Fix typo --- plugins-root/check_icmp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins-root/check_icmp.c b/plugins-root/check_icmp.c index 7c04ef21..e96fa3ec 100644 --- a/plugins-root/check_icmp.c +++ b/plugins-root/check_icmp.c @@ -1876,7 +1876,7 @@ get_threshold(char *str, threshold *th) * @param[in] length strlen(str) * @param[out] warn Pointer to the warn threshold struct to which the values should be assigned * @param[out] crit Pointer to the crit threshold struct to which the values should be assigned - * @param[in] mode Determines whether this a threshold vor rta, packet_loss, jitter, mos or score (exclusively) + * @param[in] mode Determines whether this a threshold for rta, packet_loss, jitter, mos or score (exclusively) */ static bool get_threshold2(char *str, size_t length, threshold *warn, threshold *crit, threshold_mode mode) { if (!str || !length || !warn || !crit) return false; -- cgit v1.2.3-74-g34f1 From 9426b9a33828c19188d6928ac862dd3179e44e68 Mon Sep 17 00:00:00 2001 From: RincewindsHat <12514511+RincewindsHat@users.noreply.github.com> Date: Sun, 8 Oct 2023 22:48:39 +0200 Subject: Initialise threshold variables properly --- plugins-root/check_icmp.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/plugins-root/check_icmp.c b/plugins-root/check_icmp.c index e96fa3ec..abc55952 100644 --- a/plugins-root/check_icmp.c +++ b/plugins-root/check_icmp.c @@ -234,7 +234,22 @@ extern char **environ; /** global variables **/ static struct rta_host **table, *cursor, *list; -static threshold crit = {80, 500000}, warn = {40, 200000}; + +static threshold crit = { + .pl = 80, + .rta = 500000, + .jitter = 0.0, + .mos = 0.0, + .score = 0.0 +}; +static threshold warn = { + .pl = 40, + .rta = 200000, + .jitter = 0.0, + .mos = 0.0, + .score = 0.0 +}; + static int mode, protocols, sockets, debug = 0, timeout = 10; static unsigned short icmp_data_size = DEFAULT_PING_DATA_SIZE; static unsigned short icmp_pkt_size = DEFAULT_PING_DATA_SIZE + ICMP_MINLEN; -- cgit v1.2.3-74-g34f1 From b053278b186b4b9dfacff53b30cc2c7967923724 Mon Sep 17 00:00:00 2001 From: RincewindsHat <12514511+RincewindsHat@users.noreply.github.com> Date: Sun, 8 Oct 2023 22:49:45 +0200 Subject: fix sign compare compiler warnings --- plugins-root/check_icmp.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins-root/check_icmp.c b/plugins-root/check_icmp.c index abc55952..f21bf3be 100644 --- a/plugins-root/check_icmp.c +++ b/plugins-root/check_icmp.c @@ -1053,9 +1053,9 @@ wait_for_reply(int sock, u_int t) host->time_waited += tdiff; host->icmp_recv++; icmp_recv++; - if (tdiff > (int)host->rtmax) + if (tdiff > (unsigned int)host->rtmax) host->rtmax = tdiff; - if (tdiff < (int)host->rtmin) + if (tdiff < (unsigned int)host->rtmin) host->rtmin = tdiff; if(debug) { -- cgit v1.2.3-74-g34f1 From 6a4b9927cb8bf3ca96c83735c97ccb4ca9ddd4e8 Mon Sep 17 00:00:00 2001 From: RincewindsHat <12514511+RincewindsHat@users.noreply.github.com> Date: Sun, 8 Oct 2023 22:50:17 +0200 Subject: fix unused variables compiler warning --- plugins-root/check_icmp.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/plugins-root/check_icmp.c b/plugins-root/check_icmp.c index f21bf3be..06c8b782 100644 --- a/plugins-root/check_icmp.c +++ b/plugins-root/check_icmp.c @@ -1216,7 +1216,9 @@ recvfrom_wto(int sock, void *buf, unsigned int len, struct sockaddr *saddr, int n, ret; struct timeval to, then, now; fd_set rd, wr; +#ifdef HAVE_MSGHDR_MSG_CONTROL char ans_data[4096]; +#endif // HAVE_MSGHDR_MSG_CONTROL struct msghdr hdr; struct iovec iov; #ifdef SO_TIMESTAMP -- cgit v1.2.3-74-g34f1 From b6fea24c3deaf73ee4fa8052fe435ece445fdc4f Mon Sep 17 00:00:00 2001 From: RincewindsHat <12514511+RincewindsHat@users.noreply.github.com> Date: Mon, 9 Oct 2023 01:17:44 +0200 Subject: More consequent booleans --- plugins-root/check_icmp.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins-root/check_icmp.c b/plugins-root/check_icmp.c index 06c8b782..99bd667f 100644 --- a/plugins-root/check_icmp.c +++ b/plugins-root/check_icmp.c @@ -1347,8 +1347,8 @@ finish(int sig) /* if no new mode selected, use old schema */ if (!rta_mode && !pl_mode && !jitter_mode && !score_mode && !mos_mode && !order_mode) { - rta_mode=1; - pl_mode=1; + rta_mode = true; + pl_mode = true; } #define THIS_STATUS_WARNING this_status = (this_status <= STATE_WARNING ? STATE_WARNING : this_status) -- cgit v1.2.3-74-g34f1 From f7df88dac3528b0834c897dfdfff07b9f56fd8d3 Mon Sep 17 00:00:00 2001 From: RincewindsHat <12514511+RincewindsHat@users.noreply.github.com> Date: Mon, 9 Oct 2023 01:18:04 +0200 Subject: Do some code formatting --- plugins-root/check_icmp.c | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/plugins-root/check_icmp.c b/plugins-root/check_icmp.c index 99bd667f..39ca3024 100644 --- a/plugins-root/check_icmp.c +++ b/plugins-root/check_icmp.c @@ -1327,21 +1327,24 @@ finish(int sig) if (host->icmp_recv>1) { host->jitter=(host->jitter / (host->icmp_recv - 1)/1000); host->EffectiveLatency = (rta/1000) + host->jitter * 2 + 10; - if (host->EffectiveLatency < 160) + + if (host->EffectiveLatency < 160) { R = 93.2 - (host->EffectiveLatency / 40); - else + } else { R = 93.2 - ((host->EffectiveLatency - 120) / 10); + } + R = R - (pl * 2.5); if (R<0) R=0; host->score = R; host->mos= 1 + ((0.035) * R) + ((.000007) * R * (R-60) * (100-R)); - } - else { + } else { host->jitter=0; host->jitter_min=0; host->jitter_max=0; host->mos=0; } + host->pl = pl; host->rta = rta; @@ -1358,56 +1361,55 @@ finish(int sig) this_status = STATE_CRITICAL; status = STATE_CRITICAL; host->rta_status=STATE_CRITICAL; - } - else if(status!=STATE_CRITICAL && (rta >= warn.rta)) { + } else if(status!=STATE_CRITICAL && (rta >= warn.rta)) { THIS_STATUS_WARNING; status = STATE_WARNING; host->rta_status=STATE_WARNING; } } + if (pl_mode) { if(pl >= crit.pl) { this_status = STATE_CRITICAL; status = STATE_CRITICAL; host->pl_status=STATE_CRITICAL; - } - else if(status!=STATE_CRITICAL && (pl >= warn.pl)) { + } else if(status!=STATE_CRITICAL && (pl >= warn.pl)) { THIS_STATUS_WARNING; status = STATE_WARNING; host->pl_status=STATE_WARNING; } } + if (jitter_mode) { if(host->jitter >= crit.jitter) { this_status = STATE_CRITICAL; status = STATE_CRITICAL; host->jitter_status=STATE_CRITICAL; - } - else if(status!=STATE_CRITICAL && (host->jitter >= warn.jitter)) { + } else if(status!=STATE_CRITICAL && (host->jitter >= warn.jitter)) { THIS_STATUS_WARNING; status = STATE_WARNING; host->jitter_status=STATE_WARNING; } } + if (mos_mode) { if(host->mos <= crit.mos) { this_status = STATE_CRITICAL; status = STATE_CRITICAL; host->mos_status=STATE_CRITICAL; - } - else if(status!=STATE_CRITICAL && (host->mos <= warn.mos)) { + } else if(status!=STATE_CRITICAL && (host->mos <= warn.mos)) { THIS_STATUS_WARNING; status = STATE_WARNING; host->mos_status=STATE_WARNING; } } + if (score_mode) { if(host->score <= crit.score) { this_status = STATE_CRITICAL; status = STATE_CRITICAL; host->score_status=STATE_CRITICAL; - } - else if(status!=STATE_CRITICAL && (host->score <= warn.score)) { + } else if(status!=STATE_CRITICAL && (host->score <= warn.score)) { THIS_STATUS_WARNING; status = STATE_WARNING; host->score_status=STATE_WARNING; @@ -1416,8 +1418,7 @@ finish(int sig) if (this_status == STATE_WARNING) { hosts_warn++; - } - else if (this_status == STATE_OK) { + } else if (this_status == STATE_OK) { hosts_ok++; } -- cgit v1.2.3-74-g34f1 From c568ad207c7284f301120698d20aec57ed4f24f6 Mon Sep 17 00:00:00 2001 From: RincewindsHat <12514511+RincewindsHat@users.noreply.github.com> Date: Mon, 9 Oct 2023 01:31:52 +0200 Subject: Remove preprocessor macro --- plugins-root/check_icmp.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/plugins-root/check_icmp.c b/plugins-root/check_icmp.c index 39ca3024..5a9485df 100644 --- a/plugins-root/check_icmp.c +++ b/plugins-root/check_icmp.c @@ -1354,7 +1354,6 @@ finish(int sig) pl_mode = true; } -#define THIS_STATUS_WARNING this_status = (this_status <= STATE_WARNING ? STATE_WARNING : this_status) /* Check which mode is on and do the warn / Crit stuff */ if (rta_mode) { if(rta >= crit.rta) { @@ -1362,7 +1361,7 @@ finish(int sig) status = STATE_CRITICAL; host->rta_status=STATE_CRITICAL; } else if(status!=STATE_CRITICAL && (rta >= warn.rta)) { - THIS_STATUS_WARNING; + this_status = (this_status <= STATE_WARNING ? STATE_WARNING : this_status) status = STATE_WARNING; host->rta_status=STATE_WARNING; } @@ -1374,7 +1373,7 @@ finish(int sig) status = STATE_CRITICAL; host->pl_status=STATE_CRITICAL; } else if(status!=STATE_CRITICAL && (pl >= warn.pl)) { - THIS_STATUS_WARNING; + this_status = (this_status <= STATE_WARNING ? STATE_WARNING : this_status) status = STATE_WARNING; host->pl_status=STATE_WARNING; } @@ -1386,7 +1385,7 @@ finish(int sig) status = STATE_CRITICAL; host->jitter_status=STATE_CRITICAL; } else if(status!=STATE_CRITICAL && (host->jitter >= warn.jitter)) { - THIS_STATUS_WARNING; + this_status = (this_status <= STATE_WARNING ? STATE_WARNING : this_status) status = STATE_WARNING; host->jitter_status=STATE_WARNING; } @@ -1398,7 +1397,7 @@ finish(int sig) status = STATE_CRITICAL; host->mos_status=STATE_CRITICAL; } else if(status!=STATE_CRITICAL && (host->mos <= warn.mos)) { - THIS_STATUS_WARNING; + this_status = (this_status <= STATE_WARNING ? STATE_WARNING : this_status) status = STATE_WARNING; host->mos_status=STATE_WARNING; } @@ -1410,7 +1409,7 @@ finish(int sig) status = STATE_CRITICAL; host->score_status=STATE_CRITICAL; } else if(status!=STATE_CRITICAL && (host->score <= warn.score)) { - THIS_STATUS_WARNING; + this_status = (this_status <= STATE_WARNING ? STATE_WARNING : this_status) status = STATE_WARNING; host->score_status=STATE_WARNING; } -- cgit v1.2.3-74-g34f1 From 9da06d562515d6b443e4bbb54652a88f6a1cb4ca Mon Sep 17 00:00:00 2001 From: RincewindsHat <12514511+RincewindsHat@users.noreply.github.com> Date: Mon, 9 Oct 2023 01:57:37 +0200 Subject: Do some more formatting --- plugins-root/check_icmp.c | 214 +++++++++++++++++++++++----------------------- 1 file changed, 107 insertions(+), 107 deletions(-) diff --git a/plugins-root/check_icmp.c b/plugins-root/check_icmp.c index 5a9485df..1573dcae 100644 --- a/plugins-root/check_icmp.c +++ b/plugins-root/check_icmp.c @@ -109,24 +109,24 @@ typedef struct rta_host { unsigned char icmp_type, icmp_code; /* type and code from errors */ unsigned short flags; /* control/status flags */ double rta; /* measured RTA */ - int rta_status; + int rta_status; // check result for RTA checks double rtmax; /* max rtt */ double rtmin; /* min rtt */ - double jitter; /* measured jitter */ - int jitter_status; - double jitter_max; /* jitter rtt */ - double jitter_min; /* jitter rtt */ + double jitter; /* measured jitter */ + int jitter_status; // check result for Jitter checks + double jitter_max; /* jitter rtt maximum */ + double jitter_min; /* jitter rtt minimum */ double EffectiveLatency; - double mos; /* Mean opnion score */ - int mos_status; - double score; /* score */ - int score_status; + double mos; /* Mean opnion score */ + int mos_status; // check result for MOS checks + double score; /* score */ + int score_status; // check result for score checks u_int last_tdiff; - u_int last_icmp_seq; /* Last ICMP_SEQ to check out of order pkts */ + u_int last_icmp_seq; /* Last ICMP_SEQ to check out of order pkts */ unsigned char pl; /* measured packet loss */ - int pl_status; + int pl_status; // check result for packet loss checks struct rta_host *next; /* linked list */ - int order_status; + int order_status; // check result for packet order checks } rta_host; #define FLAG_LOST_CAUSE 0x01 /* decidedly dead target. */ @@ -228,7 +228,7 @@ static void finish(int); static void crash(const char *, ...); /** external **/ -extern int optind, opterr, optopt; +extern int optind; extern char *optarg; extern char **environ; @@ -459,7 +459,7 @@ main(int argc, char **argv) * that before pointer magic (esp. on network data) */ icmp_sockerrno = udp_sockerrno = tcp_sockerrno = sockets = 0; - address_family = -1; + address_family = -1; int icmp_proto = IPPROTO_ICMP; /* get calling name the old-fashioned way for portability instead @@ -1361,7 +1361,7 @@ finish(int sig) status = STATE_CRITICAL; host->rta_status=STATE_CRITICAL; } else if(status!=STATE_CRITICAL && (rta >= warn.rta)) { - this_status = (this_status <= STATE_WARNING ? STATE_WARNING : this_status) + this_status = (this_status <= STATE_WARNING ? STATE_WARNING : this_status); status = STATE_WARNING; host->rta_status=STATE_WARNING; } @@ -1373,7 +1373,7 @@ finish(int sig) status = STATE_CRITICAL; host->pl_status=STATE_CRITICAL; } else if(status!=STATE_CRITICAL && (pl >= warn.pl)) { - this_status = (this_status <= STATE_WARNING ? STATE_WARNING : this_status) + this_status = (this_status <= STATE_WARNING ? STATE_WARNING : this_status); status = STATE_WARNING; host->pl_status=STATE_WARNING; } @@ -1385,7 +1385,7 @@ finish(int sig) status = STATE_CRITICAL; host->jitter_status=STATE_CRITICAL; } else if(status!=STATE_CRITICAL && (host->jitter >= warn.jitter)) { - this_status = (this_status <= STATE_WARNING ? STATE_WARNING : this_status) + this_status = (this_status <= STATE_WARNING ? STATE_WARNING : this_status); status = STATE_WARNING; host->jitter_status=STATE_WARNING; } @@ -1397,7 +1397,7 @@ finish(int sig) status = STATE_CRITICAL; host->mos_status=STATE_CRITICAL; } else if(status!=STATE_CRITICAL && (host->mos <= warn.mos)) { - this_status = (this_status <= STATE_WARNING ? STATE_WARNING : this_status) + this_status = (this_status <= STATE_WARNING ? STATE_WARNING : this_status); status = STATE_WARNING; host->mos_status=STATE_WARNING; } @@ -1409,7 +1409,7 @@ finish(int sig) status = STATE_CRITICAL; host->score_status=STATE_CRITICAL; } else if(status!=STATE_CRITICAL && (host->score <= warn.score)) { - this_status = (this_status <= STATE_WARNING ? STATE_WARNING : this_status) + this_status = (this_status <= STATE_WARNING ? STATE_WARNING : this_status); status = STATE_WARNING; host->score_status=STATE_WARNING; } @@ -1763,7 +1763,7 @@ add_target(char *arg) } break; } - freeaddrinfo(res); + freeaddrinfo(res); return 0; } @@ -1985,91 +1985,91 @@ icmp_checksum(uint16_t *p, size_t n) void print_help(void) { - /*print_revision (progname);*/ /* FIXME: Why? */ - printf ("Copyright (c) 2005 Andreas Ericsson \n"); - - printf (COPYRIGHT, copyright, email); - - printf ("\n\n"); - - print_usage (); - - printf (UT_HELP_VRSN); - printf (UT_EXTRA_OPTS); - - printf (" %s\n", "-H"); - printf (" %s\n", _("specify a target")); - printf (" %s\n", "[-4|-6]"); - printf (" %s\n", _("Use IPv4 (default) or IPv6 to communicate with the targets")); - printf (" %s\n", "-w"); - printf (" %s", _("warning threshold (currently ")); - printf ("%0.3fms,%u%%)\n", (float)warn.rta / 1000, warn.pl); - printf (" %s\n", "-c"); - printf (" %s", _("critical threshold (currently ")); - printf ("%0.3fms,%u%%)\n", (float)crit.rta / 1000, crit.pl); - - printf (" %s\n", "-R"); - printf (" %s\n", _("RTA, round trip average, mode warning,critical, ex. 100ms,200ms unit in ms")); - printf (" %s\n", "-P"); - printf (" %s\n", _("packet loss mode, ex. 40%,50% , unit in %")); - printf (" %s\n", "-J"); - printf (" %s\n", _("jitter mode warning,critical, ex. 40.000ms,50.000ms , unit in ms ")); - printf (" %s\n", "-M"); - printf (" %s\n", _("MOS mode, between 0 and 4.4 warning,critical, ex. 3.5,3.0")); - printf (" %s\n", "-S"); - printf (" %s\n", _("score mode, max value 100 warning,critical, ex. 80,70 ")); - printf (" %s\n", "-O"); - printf (" %s\n", _("detect out of order ICMP packts ")); - printf (" %s\n", "-H"); - printf (" %s\n", _("specify a target")); - printf (" %s\n", "-s"); - printf (" %s\n", _("specify a source IP address or device name")); - printf (" %s\n", "-n"); - printf (" %s", _("number of packets to send (currently ")); - printf ("%u)\n",packets); - printf (" %s\n", "-p"); - printf (" %s", _("number of packets to send (currently ")); - printf ("%u)\n",packets); - printf (" %s\n", "-i"); - printf (" %s", _("max packet interval (currently ")); - printf ("%0.3fms)\n",(float)pkt_interval / 1000); - printf (" %s\n", "-I"); - printf (" %s", _("max target interval (currently ")); - printf ("%0.3fms)\n", (float)target_interval / 1000); - printf (" %s\n", "-m"); - printf (" %s",_("number of alive hosts required for success")); - printf ("\n"); - printf (" %s\n", "-l"); - printf (" %s", _("TTL on outgoing packets (currently ")); - printf ("%u)\n", ttl); - printf (" %s\n", "-t"); - printf (" %s",_("timeout value (seconds, currently ")); - printf ("%u)\n", timeout); - printf (" %s\n", "-b"); - printf (" %s\n", _("Number of icmp data bytes to send")); - printf (" %s %u + %d)\n", _("Packet size will be data bytes + icmp header (currently"),icmp_data_size, ICMP_MINLEN); - printf (" %s\n", "-v"); - printf (" %s\n", _("verbose")); - printf ("\n"); - printf ("%s\n", _("Notes:")); - printf (" %s\n", _("If none of R,P,J,M,S or O is specified, default behavior is -R -P")); - printf (" %s\n", _("The -H switch is optional. Naming a host (or several) to check is not.")); - printf ("\n"); - printf (" %s\n", _("Threshold format for -w and -c is 200.25,60% for 200.25 msec RTA and 60%")); - printf (" %s\n", _("packet loss. The default values should work well for most users.")); - printf (" %s\n", _("You can specify different RTA factors using the standardized abbreviations")); - printf (" %s\n", _("us (microseconds), ms (milliseconds, default) or just plain s for seconds.")); -/* -d not yet implemented */ -/* printf ("%s\n", _("Threshold format for -d is warn,crit. 12,14 means WARNING if >= 12 hops")); - printf ("%s\n", _("are spent and CRITICAL if >= 14 hops are spent.")); - printf ("%s\n\n", _("NOTE: Some systems decrease TTL when forming ICMP_ECHOREPLY, others do not."));*/ - printf ("\n"); - printf (" %s\n", _("The -v switch can be specified several times for increased verbosity.")); -/* printf ("%s\n", _("Long options are currently unsupported.")); - printf ("%s\n", _("Options marked with * require an argument")); -*/ - - printf (UT_SUPPORT); + /*print_revision (progname);*/ /* FIXME: Why? */ + printf ("Copyright (c) 2005 Andreas Ericsson \n"); + + printf (COPYRIGHT, copyright, email); + + printf ("\n\n"); + + print_usage (); + + printf (UT_HELP_VRSN); + printf (UT_EXTRA_OPTS); + + printf (" %s\n", "-H"); + printf (" %s\n", _("specify a target")); + printf (" %s\n", "[-4|-6]"); + printf (" %s\n", _("Use IPv4 (default) or IPv6 to communicate with the targets")); + printf (" %s\n", "-w"); + printf (" %s", _("warning threshold (currently ")); + printf ("%0.3fms,%u%%)\n", (float)warn.rta / 1000, warn.pl); + printf (" %s\n", "-c"); + printf (" %s", _("critical threshold (currently ")); + printf ("%0.3fms,%u%%)\n", (float)crit.rta / 1000, crit.pl); + + printf (" %s\n", "-R"); + printf (" %s\n", _("RTA, round trip average, mode warning,critical, ex. 100ms,200ms unit in ms")); + printf (" %s\n", "-P"); + printf (" %s\n", _("packet loss mode, ex. 40%,50% , unit in %")); + printf (" %s\n", "-J"); + printf (" %s\n", _("jitter mode warning,critical, ex. 40.000ms,50.000ms , unit in ms ")); + printf (" %s\n", "-M"); + printf (" %s\n", _("MOS mode, between 0 and 4.4 warning,critical, ex. 3.5,3.0")); + printf (" %s\n", "-S"); + printf (" %s\n", _("score mode, max value 100 warning,critical, ex. 80,70 ")); + printf (" %s\n", "-O"); + printf (" %s\n", _("detect out of order ICMP packts ")); + printf (" %s\n", "-H"); + printf (" %s\n", _("specify a target")); + printf (" %s\n", "-s"); + printf (" %s\n", _("specify a source IP address or device name")); + printf (" %s\n", "-n"); + printf (" %s", _("number of packets to send (currently ")); + printf ("%u)\n",packets); + printf (" %s\n", "-p"); + printf (" %s", _("number of packets to send (currently ")); + printf ("%u)\n",packets); + printf (" %s\n", "-i"); + printf (" %s", _("max packet interval (currently ")); + printf ("%0.3fms)\n",(float)pkt_interval / 1000); + printf (" %s\n", "-I"); + printf (" %s", _("max target interval (currently ")); + printf ("%0.3fms)\n", (float)target_interval / 1000); + printf (" %s\n", "-m"); + printf (" %s",_("number of alive hosts required for success")); + printf ("\n"); + printf (" %s\n", "-l"); + printf (" %s", _("TTL on outgoing packets (currently ")); + printf ("%u)\n", ttl); + printf (" %s\n", "-t"); + printf (" %s",_("timeout value (seconds, currently ")); + printf ("%u)\n", timeout); + printf (" %s\n", "-b"); + printf (" %s\n", _("Number of icmp data bytes to send")); + printf (" %s %u + %d)\n", _("Packet size will be data bytes + icmp header (currently"),icmp_data_size, ICMP_MINLEN); + printf (" %s\n", "-v"); + printf (" %s\n", _("verbose")); + printf ("\n"); + printf ("%s\n", _("Notes:")); + printf (" %s\n", _("If none of R,P,J,M,S or O is specified, default behavior is -R -P")); + printf (" %s\n", _("The -H switch is optional. Naming a host (or several) to check is not.")); + printf ("\n"); + printf (" %s\n", _("Threshold format for -w and -c is 200.25,60% for 200.25 msec RTA and 60%")); + printf (" %s\n", _("packet loss. The default values should work well for most users.")); + printf (" %s\n", _("You can specify different RTA factors using the standardized abbreviations")); + printf (" %s\n", _("us (microseconds), ms (milliseconds, default) or just plain s for seconds.")); + /* -d not yet implemented */ + /* printf ("%s\n", _("Threshold format for -d is warn,crit. 12,14 means WARNING if >= 12 hops")); + printf ("%s\n", _("are spent and CRITICAL if >= 14 hops are spent.")); + printf ("%s\n\n", _("NOTE: Some systems decrease TTL when forming ICMP_ECHOREPLY, others do not."));*/ + printf ("\n"); + printf (" %s\n", _("The -v switch can be specified several times for increased verbosity.")); + /* printf ("%s\n", _("Long options are currently unsupported.")); + printf ("%s\n", _("Options marked with * require an argument")); + */ + + printf (UT_SUPPORT); } @@ -2077,6 +2077,6 @@ print_help(void) void print_usage (void) { - printf ("%s\n", _("Usage:")); - printf(" %s [options] [-H] host1 host2 hostN\n", progname); + printf ("%s\n", _("Usage:")); + printf(" %s [options] [-H] host1 host2 hostN\n", progname); } -- cgit v1.2.3-74-g34f1 From eb6c83a6501151fcd4e01256e71415c25b25b7da Mon Sep 17 00:00:00 2001 From: RincewindsHat <12514511+RincewindsHat@users.noreply.github.com> Date: Mon, 9 Oct 2023 13:32:04 +0200 Subject: Even more code formatting and cleanup --- plugins-root/check_icmp.c | 47 ++++++++++++++++++++++++++--------------------- 1 file changed, 26 insertions(+), 21 deletions(-) diff --git a/plugins-root/check_icmp.c b/plugins-root/check_icmp.c index 1573dcae..915710bd 100644 --- a/plugins-root/check_icmp.c +++ b/plugins-root/check_icmp.c @@ -609,7 +609,6 @@ main(int argc, char **argv) break; case 'R': /* RTA mode */ err = get_threshold2(optarg, strlen(optarg), &warn, &crit, const_rta_mode); - if (!err) { crash("Failed to parse RTA threshold"); } @@ -618,7 +617,6 @@ main(int argc, char **argv) break; case 'P': /* packet loss mode */ err = get_threshold2(optarg, strlen(optarg), &warn, &crit, const_packet_loss_mode); - if (!err) { crash("Failed to parse packet loss threshold"); } @@ -627,7 +625,6 @@ main(int argc, char **argv) break; case 'J': /* jitter mode */ err = get_threshold2(optarg, strlen(optarg), &warn, &crit, const_jitter_mode); - if (!err) { crash("Failed to parse jitter threshold"); } @@ -636,7 +633,6 @@ main(int argc, char **argv) break; case 'M': /* MOS mode */ err = get_threshold2(optarg, strlen(optarg), &warn, &crit, const_mos_mode); - if (!err) { crash("Failed to parse MOS threshold"); } @@ -645,7 +641,6 @@ main(int argc, char **argv) break; case 'S': /* score mode */ err = get_threshold2(optarg, strlen(optarg), &warn, &crit, const_score_mode); - if (!err) { crash("Failed to parse score threshold"); } @@ -675,10 +670,10 @@ main(int argc, char **argv) add_target(*argv); argv++; } + if(!targets) { errno = 0; crash("No hosts to check"); - exit(3); } // add_target might change address_family @@ -1023,21 +1018,24 @@ wait_for_reply(int sock, u_int t) /* Calculate jitter */ if (host->last_tdiff > tdiff) { jitter_tmp = host->last_tdiff - tdiff; - } - else { + } else { jitter_tmp = tdiff - host->last_tdiff; } + if (host->jitter==0) { host->jitter=jitter_tmp; host->jitter_max=jitter_tmp; host->jitter_min=jitter_tmp; - } - else { + } else { host->jitter+=jitter_tmp; - if (jitter_tmp < host->jitter_min) + + if (jitter_tmp < host->jitter_min) { host->jitter_min=jitter_tmp; - if (jitter_tmp > host->jitter_max) + } + + if (jitter_tmp > host->jitter_max) { host->jitter_max=jitter_tmp; + } } /* Check if packets in order */ @@ -1048,8 +1046,6 @@ wait_for_reply(int sock, u_int t) host->last_icmp_seq=packet.icp->icmp_seq; - //printf("%d tdiff %d host->jitter %u host->last_tdiff %u\n", icp.icmp_seq, tdiff, host->jitter, host->last_tdiff); - host->time_waited += tdiff; host->icmp_recv++; icmp_recv++; @@ -1311,6 +1307,7 @@ finish(int sig) while(host) { this_status = STATE_OK; + if(!host->icmp_recv) { /* rta 0 is ofcourse not entirely correct, but will still show up * conspicuously as missing entries in perfparse and cacti */ @@ -1319,11 +1316,11 @@ finish(int sig) status = STATE_CRITICAL; /* up the down counter if not already counted */ if(!(host->flags & FLAG_LOST_CAUSE) && targets_alive) targets_down++; - } - else { + } else { pl = ((host->icmp_sent - host->icmp_recv) * 100) / host->icmp_sent; rta = (double)host->time_waited / host->icmp_recv; } + if (host->icmp_recv>1) { host->jitter=(host->jitter / (host->icmp_recv - 1)/1000); host->EffectiveLatency = (rta/1000) + host->jitter * 2 + 10; @@ -1335,7 +1332,11 @@ finish(int sig) } R = R - (pl * 2.5); - if (R<0) R=0; + + if (R < 0) { + R = 0; + } + host->score = R; host->mos= 1 + ((0.035) * R) + ((.000007) * R * (R-60) * (100-R)); } else { @@ -1454,12 +1455,10 @@ finish(int sig) get_icmp_error_msg(host->icmp_type, host->icmp_code), address, 100); - } - else { /* not marked as lost cause, so we have no flags for it */ + } else { /* not marked as lost cause, so we have no flags for it */ printf("%s: rta nan, lost 100%%", host->name); } - } - else { /* !icmp_recv */ + } else { /* !icmp_recv */ printf("%s", host->name); /* rta text output */ if (rta_mode) { @@ -1525,6 +1524,7 @@ finish(int sig) host = list; while(host) { if(debug) puts(""); + if (rta_mode && host->pl<100) { printf("%srta=%0.3fms;%0.3f;%0.3f;0; %srtmax=%0.3fms;;;; %srtmin=%0.3fms;;;; ", (targets > 1) ? host->name : "", @@ -1532,9 +1532,11 @@ finish(int sig) (targets > 1) ? host->name : "", (float)host->rtmax / 1000, (targets > 1) ? host->name : "", (host->rtmin < INFINITY) ? (float)host->rtmin / 1000 : (float)0); } + if (pl_mode) { printf("%spl=%u%%;%u;%u;0;100 ", (targets > 1) ? host->name : "", host->pl, warn.pl, crit.pl); } + if (jitter_mode && host->pl<100) { printf("%sjitter_avg=%0.3fms;%0.3f;%0.3f;0; %sjitter_max=%0.3fms;;;; %sjitter_min=%0.3fms;;;; ", (targets > 1) ? host->name : "", @@ -1546,6 +1548,7 @@ finish(int sig) (float)host->jitter_min / 1000 ); } + if (mos_mode && host->pl<100) { printf("%smos=%0.1f;%0.1f;%0.1f;0;5 ", (targets > 1) ? host->name : "", @@ -1554,6 +1557,7 @@ finish(int sig) (float)crit.mos ); } + if (score_mode && host->pl<100) { printf("%sscore=%u;%u;%u;0;100 ", (targets > 1) ? host->name : "", @@ -1562,6 +1566,7 @@ finish(int sig) (int)crit.score ); } + host = host->next; } -- cgit v1.2.3-74-g34f1 From 0de0daccec8cb1ac4b54f0d9b981cf89c1961209 Mon Sep 17 00:00:00 2001 From: RincewindsHat <12514511+RincewindsHat@users.noreply.github.com> Date: Fri, 13 Oct 2023 01:25:22 +0200 Subject: Add some more comments about the MOS score --- plugins-root/check_icmp.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/plugins-root/check_icmp.c b/plugins-root/check_icmp.c index 915710bd..12fb7b79 100644 --- a/plugins-root/check_icmp.c +++ b/plugins-root/check_icmp.c @@ -1322,7 +1322,27 @@ finish(int sig) } if (host->icmp_recv>1) { + /* + * This algorithm is probably pretty much blindly copied from + * locations like this one: https://www.slac.stanford.edu/comp/net/wan-mon/tutorial.html#mos + * It calucates a MOS value (range of 1 to 5, where 1 is bad and 5 really good). + * According to some quick research MOS originates from the Audio/Video transport network area. + * Whether it can and should be computed from ICMP data, I can not say. + * + * Anyway the basic idea is to map a value "R" with a range of 0-100 to the MOS value + * + * MOS stands likely for Mean Opinion Score ( https://en.wikipedia.org/wiki/Mean_Opinion_Score ) + * + * More links: + * - https://confluence.slac.stanford.edu/display/IEPM/MOS + */ host->jitter=(host->jitter / (host->icmp_recv - 1)/1000); + + /* + * Take the average round trip latency (in milliseconds), add + * round trip jitter, but double the impact to latency + * then add 10 for protocol latencies (in milliseconds). + */ host->EffectiveLatency = (rta/1000) + host->jitter * 2 + 10; if (host->EffectiveLatency < 160) { @@ -1331,6 +1351,8 @@ finish(int sig) R = 93.2 - ((host->EffectiveLatency - 120) / 10); } + // Now, let us deduct 2.5 R values per percentage of packet loss (i.e. a + // loss of 5% will be entered as 5). R = R - (pl * 2.5); if (R < 0) { -- cgit v1.2.3-74-g34f1 From f5074ac7f01ba95469748531b503c56b31e55cc3 Mon Sep 17 00:00:00 2001 From: RincewindsHat <12514511+RincewindsHat@users.noreply.github.com> Date: Fri, 13 Oct 2023 01:29:31 +0200 Subject: Fix spelling stuff --- .github/workflows/test.yml | 2 +- plugins-root/check_icmp.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 0f845de7..ea0b38be 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -21,7 +21,7 @@ jobs: uses: codespell-project/actions-codespell@v2 with: skip: "./.git,./.gitignore,./ABOUT-NLS,*.po,./gl,./po,./tools/squid.conf,./build-aux/ltmain.sh" - ignore_words_list: allright,gord,didi,hda,nd,alis,clen,scrit,ser,fot,te,parm,isnt,consol,oneliners,esponse + ignore_words_list: allright,gord,didi,hda,nd,alis,clen,scrit,ser,fot,te,parm,isnt,consol,oneliners,esponse,slac check_filenames: true check_hidden: true # super-linter: diff --git a/plugins-root/check_icmp.c b/plugins-root/check_icmp.c index 12fb7b79..303241d3 100644 --- a/plugins-root/check_icmp.c +++ b/plugins-root/check_icmp.c @@ -1325,7 +1325,7 @@ finish(int sig) /* * This algorithm is probably pretty much blindly copied from * locations like this one: https://www.slac.stanford.edu/comp/net/wan-mon/tutorial.html#mos - * It calucates a MOS value (range of 1 to 5, where 1 is bad and 5 really good). + * It calculates a MOS value (range of 1 to 5, where 1 is bad and 5 really good). * According to some quick research MOS originates from the Audio/Video transport network area. * Whether it can and should be computed from ICMP data, I can not say. * -- cgit v1.2.3-74-g34f1