[Nagiosplug-devel] check_icmp min and max

Andreas Ericsson ae at op5.se
Tue Oct 28 19:14:02 CET 2008


rader at hep.wisc.edu wrote:
> Attached please find a patch that causes check_icmp to report
> min and max round trip time perfdata.
> 
> It'd be nice if it got folded in.
> 
> I'm not sure if it'll apply cleanly to the latest in CVS.
> (See my previous msg.)
> 
> steve
> --
> 
> 
> 
> ------------------------------------------------------------------------
> 
> --- check_icmp.c.orig	2007-09-15 06:55:12.000000000 -0500
> +++ check_icmp.c	2008-10-28 06:09:05.000000000 -0500
> @@ -118,6 +118,8 @@
>  	unsigned char icmp_type, icmp_code; /* type and code from errors */
>  	unsigned short flags;        /* control/status flags */
>  	double rta;                  /* measured RTA */
> +	double rtmax;                /* max rtt */
> +	double rtmin;                /* min rtt */
>  	unsigned char pl;            /* measured packet loss */
>  	struct rta_host *next;       /* linked list */
>  } rta_host;
> @@ -764,13 +766,13 @@
>  		host->time_waited += tdiff;
>  		host->icmp_recv++;
>  		icmp_recv++;
> -
> +		if ( tdiff > host->rtmax ) { host->rtmax = tdiff; }
> +		if ( tdiff < host->rtmin ) { host->rtmin = tdiff; }


Please re-send with indentation matching that of the surrounding
code. That is:
* Don't put space after opening parentheses or before closing
  parentheses.
* Put newlines after if() statements.
* Put closing curlies on their own lines.

This hunk should have looked like this:
		if(tdiff > host->rtmax)
			host->rtmax = tdiff;
		if(tdiff < host->rtmin)
			host->rtmin = tdiff;


>  		if(debug) {
> -			printf("%0.3f ms rtt from %s, outgoing ttl: %u, incoming ttl: %u\n",
> +			printf("%0.3f ms rtt from %s, outgoing ttl: %u, incoming ttl: %u, max: %0.3f, min: %0.3f\n",
>  				   (float)tdiff / 1000, inet_ntoa(resp_addr.sin_addr),
> -				   ttl, ip->ip_ttl);
> +				   ttl, ip->ip_ttl, (float)host->rtmax / 1000, (float)host->rtmin / 1000);
>  		}
> -
>  		/* if we're in hostcheck mode, exit with limited printouts */
>  		if(mode == MODE_HOSTCHECK) {
>  			printf("OK - %s responds to ICMP. Packet %u, rta %0.3fms|"
> @@ -882,6 +884,8 @@
>  	u_int i = 0;
>  	unsigned char pl;
>  	double rta;
> +	double rtmax;
> +	double rtmin;
>  	struct rta_host *host;
>  	char *status_string[] =
>  	{"OK", "WARNING", "CRITICAL", "UNKNOWN", "DEPENDENT"};
> @@ -975,9 +979,10 @@
>  	host = list;
>  	while(host) {
>  		if(debug) puts("");
> -		printf("%srta=%0.3fms;%0.3f;%0.3f;0; %spl=%u%%;%u;%u;; ",
> +		printf("%srta=%0.3fms;rtmax=%0.3fms;rtmin=%0.3fms;%0.3f;%0.3f;0; %spl=%u%%;%u;%u;; ",
>  			   (targets > 1) ? host->name : "",
> -			   host->rta / 1000, (float)warn.rta / 1000, (float)crit.rta / 1000,
> +			   host->rta / 1000, host->rtmax / 1000, host->rtmin / 1000,
> +			   (float)warn.rta / 1000, (float)crit.rta / 1000,
>  			   (targets > 1) ? host->name : "",
>  			   host->pl, warn.pl, crit.pl);
>  
> @@ -1056,6 +1061,8 @@
>  	host->saddr_in.sin_family = AF_INET;
>  	host->saddr_in.sin_addr.s_addr = in->s_addr;
>  
> +        host->rtmin = 0xffffffff;
> +

This should generate a warning, as it would generate bogus assembly
without compiler interference. Assign it to a really huge double
value instead. Feel free to use scientific notation, like so:
#define RTMIN_MAGIC_CONSTANT 50e200
host->rtmin = RTMIN_MAGIC_CONSTANT

rest assured that that particular magic constant will always be
larger than any rtmin you can possibly get, so it won't interfere
with the actual setting of the value.

-- 
Andreas Ericsson                   andreas.ericsson at op5.se
OP5 AB                             www.op5.se
Tel: +46 8-230225                  Fax: +46 8-230231




More information about the Devel mailing list