From nobody@FreeBSD.org  Tue Mar 18 14:04:00 2008
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id 054C5106566B
	for <freebsd-gnats-submit@FreeBSD.org>; Tue, 18 Mar 2008 14:04:00 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (www.freebsd.org [IPv6:2001:4f8:fff6::21])
	by mx1.freebsd.org (Postfix) with ESMTP id 055BD8FC1C
	for <freebsd-gnats-submit@FreeBSD.org>; Tue, 18 Mar 2008 14:04:00 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.14.2/8.14.2) with ESMTP id m2IE3x9I011328
	for <freebsd-gnats-submit@FreeBSD.org>; Tue, 18 Mar 2008 14:03:59 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.14.2/8.14.1/Submit) id m2IE3xtb011327;
	Tue, 18 Mar 2008 14:03:59 GMT
	(envelope-from nobody)
Message-Id: <200803181403.m2IE3xtb011327@www.freebsd.org>
Date: Tue, 18 Mar 2008 14:03:59 GMT
From: Maxim Shakhab <maxim.shakhab@gmail.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: port nagios-plugins: check_disk plugin works incorrectly
X-Send-Pr-Version: www-3.1
X-GNATS-Notify: jarrod@netleader.com.au

>Number:         121830
>Category:       ports
>Synopsis:       net-mgmt/nagios-plugins: check_disk plugin works incorrectly
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    freebsd-ports-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Tue Mar 18 14:10:04 UTC 2008
>Closed-Date:    Mon Apr 28 10:37:29 UTC 2008
>Last-Modified:  Mon Apr 28 10:38:23 UTC 2008
>Originator:     Maxim Shakhab
>Release:        FreeBSD-CURRENT
>Organization:
KL
>Environment:
>Description:
I investigated the situation, when check_disk plugin
works incorrectly.

When any filesystem is full like this:

Filesystem        1K-blocks    Used   Avail Capacity
Mounted on
100%    /dev
/dev/mirror/m0s1d    118766  109548    -282
100%    /tmp

check_disk plugin lies:

# ./check_disk -p /dev/mirror/m0s1d -w 20% -c 10%
DISK CRITICAL - free space: /tmp 36028797018963968 MB
(31064015077900328%
inode=99%);| /tmp=116MB;92;103;98;115

You see the sign of signed operand is ignored, and as
a result we have incorrect size of filesystem's free
space.

I took a look at two files: check_disk.c and fsusage.h
and found several errors. I corrected them, built
check_disk, and afterwards everything is ok: it shows
correct information about free space and works
properly:

# ./check_disk -p /dev/mirror/m0s1d -w 20% -c 10%
DISK CRITICAL - free space: /tmp -0 MB (-0%
inode=99%);| /tmp=116MB;92;103;98;115

>How-To-Repeat:
any filesystem is full

>Fix:
These are diffs:

# diff fsusage.h.new  fsusage.h.orig
28,29c28,29
<   intmax_t fsu_bfree;         /* Free blocks
available to superuser. */
<   intmax_t fsu_bavail;                /* Free blocks
available to non-superuser. */
---
>   uintmax_t fsu_bfree;                /* Free blocks
available to superuser. */
>   uintmax_t fsu_bavail;               /* Free blocks
available to non-superuser. */

# diff check_disk.c.new  check_disk.c.orig
160c160
<   double free_space, free_space_pct, total_space,
inode_space_pct;
---
>   float free_space, free_space_pct, total_space,
inode_space_pct;
256,258c256,258
<       free_space = (double)
fsp.fsu_bavail*fsp.fsu_blocksize/mult;
<       free_space_pct = (double)
fsp.fsu_bavail*100/fsp.fsu_blocks;
<       total_space = (double)
fsp.fsu_blocks*fsp.fsu_blocksize/mult;
---
>       free_space = (float)
fsp.fsu_bavail*fsp.fsu_blocksize/mult;
>       free_space_pct = (float)
fsp.fsu_bavail*100/fsp.fsu_blocks;
>       total_space = (float)
fsp.fsu_blocks*fsp.fsu_blocksize/mult;


>Release-Note:
>Audit-Trail:
Class-Changed-From-To: maintainer-update->change-request 
Class-Changed-By: edwin 
Class-Changed-When: Tue Mar 18 14:36:40 UTC 2008 
Class-Changed-Why:  
Fix category (submitter is not maintainer) (via the GNATS Auto Assign 
Tool) 

http://www.freebsd.org/cgi/query-pr.cgi?pr=121830 
State-Changed-From-To: open->feedback 
State-Changed-By: edwin 
State-Changed-When: Tue Mar 18 14:36:45 UTC 2008 
State-Changed-Why:  
Awaiting maintainers feedback (via the GNATS Auto Assign Tool) 

http://www.freebsd.org/cgi/query-pr.cgi?pr=121830 

From: Jarrod Sayers <jarrod@netleader.com.au>
To: maxim.shakhab@gmail.com
Cc: bug-followup@FreeBSD.org
Subject: Re: ports/121830: net-mgmt/nagios-plugins: check_disk plugin works incorrectly
Date: Wed, 19 Mar 2008 22:48:02 +1030

 What version of net-mgmt/nagios-plugins are you running?  I believe  
 the error you're referring to was resolved in ports/118799 with the  
 bump to 1.4.11.  Also note that the -w and -c arguments must precede - 
 p on the command line.
 
 wallace# /usr/local/libexec/nagios/check_disk -w 20% -c 10% -p /var/ 
 named/dev
 DISK CRITICAL - free space: /var/named/dev 0 MB (0% inode=-);| /var/ 
 named/dev=0MB;0;0;0;0
 wallace#
 
 Jarrod.
State-Changed-From-To: feedback->closed 
State-Changed-By: miwi 
State-Changed-When: Mon Apr 28 10:37:27 UTC 2008 
State-Changed-Why:  
Feedback timeout. If this problem still exists, please feel
free to follow-up this PR so that we can re-open it and find a
solution for the problem. Thanks!

http://www.freebsd.org/cgi/query-pr.cgi?pr=121830 
>Unformatted:
