[Nagiosplug-checkins] CVS: nagiosplug/plugins check_disk.c,1.9,1.10

Karl DeBisschop kdebisschop at users.sourceforge.net
Mon Mar 10 22:45:08 CET 2003


Update of /cvsroot/nagiosplug/nagiosplug/plugins
In directory sc8-pr-cvs1:/tmp/cvs-serv30071/plugins

Modified Files:
	check_disk.c 
Log Message:
use statfs for check_disk (still needs fs scan)

Index: check_disk.c
===================================================================
RCS file: /cvsroot/nagiosplug/nagiosplug/plugins/check_disk.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -C2 -r1.9 -r1.10
*** check_disk.c	9 Mar 2003 10:39:49 -0000	1.9
--- check_disk.c	11 Mar 2003 06:44:22 -0000	1.10
***************
*** 37,40 ****
--- 37,48 ----
  #include <stdarg.h>
  
+ #ifdef _AIX
+  #pragma alloca
+ #endif
+ 
+ #if HAVE_INTTYPES_H
+ # include <inttypes.h>
+ #endif
+ 
  #define REVISION "$Revision$"
  #define COPYRIGHT "2000-2002"
***************
*** 74,80 ****
--- 82,131 ----
  	char *output = "";
  
+ #ifdef HAVE_STRUCT_STATFS
+ #ifdef HAVE_SYS_VFS_H
+ #include <sys/vfs.h>
+ #else
+ #include <sys/param.h>
+ #include <sys/mount.h>
+ #endif
+ 	struct statfs buf;
+ #endif
+ 
  	if (process_arguments (argc, argv) != OK)
  		usage ("Could not parse arguments\n");
  
+ #ifdef HAVE_STRUCT_STATFS
+ 
+ 	if (statfs (path, &buf) == -1) {
+ 		switch (errno)
+ 			{
+ 			case ENOTDIR:
+ 				terminate (STATE_UNKNOWN, "A component of the path prefix is not a directory.\n");
+ 			case ENAMETOOLONG:
+ 				terminate (STATE_UNKNOWN, "path is too long.\n");
+ 			case ENOENT:
+ 				terminate (STATE_UNKNOWN, "The file referred to by path does not exist.\n");
+ 			case EACCES:
+ 				terminate (STATE_UNKNOWN, "Search permission is denied for a component of the path prefix of path.\n");
+ 			case ELOOP:
+ 				terminate (STATE_UNKNOWN, "Too many symbolic links were encountered in translating path.\n");
+ 			case EFAULT:
+ 				terminate (STATE_UNKNOWN, "Buf or path points to an invalid address.\n");
+ 			case EIO:
+ 				terminate (STATE_UNKNOWN, "An I/O error occurred while reading from or writing to the file system.\n");
+ 			case ENOMEM:
+ 				terminate (STATE_UNKNOWN, "Insufficient kernel memory was available.\n");
+ 			case ENOSYS:
+ 				terminate (STATE_UNKNOWN, "The  filesystem path is on does not support statfs.\n");
+ 			}
+ 	}
+ 	usp = (buf.f_blocks - buf.f_bavail) / buf.f_blocks;
+ 	disk_result = check_disk (usp, buf.f_bavail);
+ 	result = disk_result;
+ 	asprintf (&output, "%ld of %ld kB free (%ld-byte blocks)",
+ 	          buf.f_bavail*buf.f_bsize/1024, buf.f_blocks*buf.f_bsize/1024, buf.f_bsize);
+ 
+ #else
+ 
  	asprintf (&command_line, "%s %s", DF_COMMAND, path);
  
***************
*** 152,162 ****
  
  	if (usp < 0)
! 		printf ("Disk \"%s\" not mounted or nonexistant\n", path);
  	else if (result == STATE_UNKNOWN)
! 		printf ("Unable to read output\n%s\n%s\n", command_line, input_buffer);
! 	else
! 		printf ("DISK %s%s\n", state_text (result), output);
  
! 	return result;
  }
  
--- 203,213 ----
  
  	if (usp < 0)
! 		terminate (result, "Disk \"%s\" not mounted or nonexistant\n", path);
  	else if (result == STATE_UNKNOWN)
! 		terminate (result, "Unable to read output\n%s\n%s\n", command_line, input_buffer);
! 
! #endif
  
! 	terminate (result, "DISK %s %s\n", state_text (result), output);
  }
  





More information about the Commits mailing list