[Nagiosplug-checkins] CVS: nagiosplug/plugins Makefile.am,1.31,1.32 check_ide-smart.c,1.2,1.3

Karl DeBisschop kdebisschop at users.sourceforge.net
Sat Aug 2 23:04:01 CEST 2003


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

Modified Files:
	Makefile.am check_ide-smart.c 
Log Message:
markup for translation, use common.h, fix problems compiling

Index: Makefile.am
===================================================================
RCS file: /cvsroot/nagiosplug/nagiosplug/plugins/Makefile.am,v
retrieving revision 1.31
retrieving revision 1.32
diff -C2 -r1.31 -r1.32
*** Makefile.am	1 Aug 2003 02:11:31 -0000	1.31
--- Makefile.am	3 Aug 2003 06:03:31 -0000	1.32
***************
*** 22,26 ****
  EXTRA_PROGRAMS = check_mysql check_radius check_pgsql check_snmp check_hpjd \
  	check_swap check_fping check_ldap check_game check_dig \
! 	check_nagios check_by_ssh check_dns check_nt
  
  EXTRA_DIST = t utils.c netutils.c popen.c utils.h netutils.h popen.h common.h \
--- 22,26 ----
  EXTRA_PROGRAMS = check_mysql check_radius check_pgsql check_snmp check_hpjd \
  	check_swap check_fping check_ldap check_game check_dig \
! 	check_nagios check_by_ssh check_dns check_nt check_ide-smart
  
  EXTRA_DIST = t utils.c netutils.c popen.c utils.h netutils.h popen.h common.h \

Index: check_ide-smart.c
===================================================================
RCS file: /cvsroot/nagiosplug/nagiosplug/plugins/check_ide-smart.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -r1.2 -r1.3
*** check_ide-smart.c	11 Mar 2003 22:22:10 -0000	1.2
--- check_ide-smart.c	3 Aug 2003 06:03:31 -0000	1.3
***************
*** 17,21 ****
   *	     - Returns -1 not too often
   *
!  *  ide-smart 1.3 - IDE S.M.A.R.T. cheking tool
   *  Copyright (C) 1998-1999 Ragnar Hojland Espinosa <ragnar at lightside.dhis.org>
   *		  1998	    Gadi Oxman <gadio at netvision.net.il>
--- 17,21 ----
   *	     - Returns -1 not too often
   *
!  *  ide-smart 1.3 - IDE S.M.A.R.T. checking tool
   *  Copyright (C) 1998-1999 Ragnar Hojland Espinosa <ragnar at lightside.dhis.org>
   *		  1998	    Gadi Oxman <gadio at netvision.net.il>
***************
*** 34,46 ****
   *  along with this program; if not, write to the Free Software
   *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
!  */  
  	
! #include <stdio.h>
! #include <sys/types.h>
  #include <sys/stat.h>
  #include <sys/ioctl.h>
  #include <fcntl.h>
- #include <string.h>
- #include <unistd.h>
  #include <linux/hdreg.h>
  #include <linux/types.h>
--- 34,44 ----
   *  along with this program; if not, write to the Free Software
   *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
!  */
  	
! #include "common.h"
! #include "utils.h"
  #include <sys/stat.h>
  #include <sys/ioctl.h>
  #include <fcntl.h>
  #include <linux/hdreg.h>
  #include <linux/types.h>
***************
*** 57,61 ****
  #define OPERATIONAL 0
  #define UNKNOWN -1
! 	typedef struct threshold_s
  {
  	__u8 id;
--- 55,60 ----
  #define OPERATIONAL 0
  #define UNKNOWN -1
! 
! typedef struct threshold_s
  {
  	__u8 id;
***************
*** 64,67 ****
--- 63,67 ----
  }
  __attribute__ ((packed)) threshold_t;
+ 
  typedef struct thresholds_s
  {
***************
*** 73,76 ****
--- 73,77 ----
  }
  __attribute__ ((packed)) thresholds_t;
+ 
  typedef struct value_s
  {
***************
*** 81,84 ****
--- 82,86 ----
  }
  __attribute__ ((packed)) value_t;
+ 
  typedef struct values_s
  {
***************
*** 96,142 ****
  }
  __attribute__ ((packed)) values_t;
  struct
  {
  	__u8 value;
  	char *text;
!  }
  offline_status_text[] =
! {
! 	 {
! 	0x00, "NeverStarted"}
! 	,  {
! 	0x02, "Completed"}
! 	,  {
! 	0x04, "Suspended"}
! 	,  {
! 	0x05, "Aborted"}
! 	,  {
! 	0x06, "Failed"}
! 	,  {
! 	0, 0}
! };
  struct
  {
  	__u8 value;
  	char *text;
!  }
  smart_command[] =
! {
! 	 {
! 	SMART_ENABLE, "SMART_ENABLE"}
! 	,  {
! 	SMART_DISABLE, "SMART_DISABLE"}
! 	,  {
! 	SMART_IMMEDIATE_OFFLINE, "SMART_IMMEDIATE_OFFLINE"}
! 	,  {
! 	SMART_AUTO_OFFLINE, "SMART_AUTO_OFFLINE"}
! , };
  
  
  /* Index to smart_command table, keep in order */ 
  enum SmartCommand 
! { SMART_CMD_ENABLE, SMART_CMD_DISABLE, SMART_CMD_IMMEDIATE_OFFLINE,
  		SMART_CMD_AUTO_OFFLINE 
! };
  char *
  get_offline_text (int status) 
--- 98,141 ----
  }
  __attribute__ ((packed)) values_t;
+ 
  struct
  {
  	__u8 value;
  	char *text;
! }
! 
  offline_status_text[] =
! 	{
! 		{0x00, "NeverStarted"},
! 		{0x02, "Completed"},
! 		{0x04, "Suspended"},
! 		{0x05, "Aborted"},
! 		{0x06, "Failed"},
! 		{0, 0}
! 	};
! 
  struct
  {
  	__u8 value;
  	char *text;
! }
! 
  smart_command[] =
! 	{
! 		{SMART_ENABLE, "SMART_ENABLE"},
! 		{SMART_DISABLE, "SMART_DISABLE"},
! 		{SMART_IMMEDIATE_OFFLINE, "SMART_IMMEDIATE_OFFLINE"},
! 		{SMART_AUTO_OFFLINE, "SMART_AUTO_OFFLINE"}
! 	};
  
  
  /* Index to smart_command table, keep in order */ 
  enum SmartCommand 
! 	{ SMART_CMD_ENABLE,
! 		SMART_CMD_DISABLE,
! 		SMART_CMD_IMMEDIATE_OFFLINE,
  		SMART_CMD_AUTO_OFFLINE 
! 	};
! 
  char *
  get_offline_text (int status) 
***************
*** 150,161 ****
  	return "unknown";
  }
  int
  smart_read_values (int fd, values_t * values) 
  {
! 	__u8 args[4 + 512] = {
! 	WIN_SMART, 0, SMART_READ_VALUES, 1,};
  	if (ioctl (fd, HDIO_DRIVE_CMD, &args)) {
! 		int e = errno;
! 		printf ("Critical: SMART_READ_VALUES: %s\n", strerror (errno));
  		return e;
  	}
--- 149,165 ----
  	return "unknown";
  }
+ 
  int
  smart_read_values (int fd, values_t * values) 
  {
! 	int e;
! 	__u8 args[4 + 512];
! 	args[0] = WIN_SMART;
! 	args[1] = 0;
! 	args[2] = SMART_READ_VALUES;
! 	args[3] = 1;
  	if (ioctl (fd, HDIO_DRIVE_CMD, &args)) {
! 		e = errno;
! 		printf (_("Critical: SMART_READ_VALUES: %s\n"), strerror (errno));
  		return e;
  	}
***************
*** 163,166 ****
--- 167,171 ----
  	return 0;
  }
+ 
  int
  values_not_passed (values_t * p, thresholds_t * t) 
***************
*** 185,188 ****
--- 190,194 ----
  	return (passed ? -failed : 2);
  }
+ 
  int
  net_saint (values_t * p, thresholds_t * t) 
***************
*** 220,238 ****
  	switch (status) {
  	case PREFAILURE:
! 		printf ("Critical: %d Harddrive PreFailure%cDetected! " 
! 						 "%d/%d tests failed.\n", prefailure, prefailure > 1 ? 's' : ' ',
! 						 failed, total);
  		break;
  	case ADVISORY:
! 		printf ("Warning: %d Harddrive Advisor%s Detected. " 
! 						 "%d/%d tests failed.\n", advisory, advisory > 1 ? "ies" : "y",
! 						 failed, total);
  		break;
  	case OPERATIONAL:
! 		printf ("Status: Operational (%d/%d tests passed)\n", passed, total);
  		break;
  	default:
! 		printf ("Error: Status '%d' uknown. %d/%d tests passed\n", status,
! 						 passed, total);
  		status = -1;
  		break;
--- 226,248 ----
  	switch (status) {
  	case PREFAILURE:
! 		printf (_("Critical: %d Harddrive PreFailure%cDetected! %d/%d tests failed.\n"),
! 		        prefailure,
! 		        prefailure > 1 ? 's' : ' ',
! 		        failed,
! 	          total);
  		break;
  	case ADVISORY:
! 		printf (_("Warning: %d Harddrive Advisor%s Detected. %d/%d tests failed.\n"),
! 		        advisory,
! 		        advisory > 1 ? "ies" : "y",
! 		        failed,
! 		        total);
  		break;
  	case OPERATIONAL:
! 		printf (_("Status: Operational (%d/%d tests passed)\n"), passed, total);
  		break;
  	default:
! 		printf (_("Error: Status '%d' uknown. %d/%d tests passed\n"), status,
! 						passed, total);
  		status = -1;
  		break;
***************
*** 240,251 ****
  	return status;
  }
  void
  print_value (value_t * p, threshold_t * t) 
  {
  	printf ("Id=%3d, Status=%2d {%s , %s}, Value=%3d, Threshold=%3d, %s\n",
! 					 p->id, p->status, p->status & 1 ? "PreFailure" : "Advisory   ",
! 					 p->status & 2 ? "OnLine " : "OffLine", p->value, t->threshold,
! 					 p->value > t->threshold ? "Passed" : "Failed");
  }
  void
  print_values (values_t * p, thresholds_t * t) 
--- 250,263 ----
  	return status;
  }
+ 
  void
  print_value (value_t * p, threshold_t * t) 
  {
  	printf ("Id=%3d, Status=%2d {%s , %s}, Value=%3d, Threshold=%3d, %s\n",
! 					p->id, p->status, p->status & 1 ? "PreFailure" : "Advisory   ",
! 					p->status & 2 ? "OnLine " : "OffLine", p->value, t->threshold,
! 					p->value > t->threshold ? "Passed" : "Failed");
  }
+ 
  void
  print_values (values_t * p, thresholds_t * t) 
***************
*** 260,275 ****
  	}
  	printf
! 		("OffLineStatus=%d {%s}, AutoOffLine=%s, OffLineTimeout=%d minutes\n",
! 		 p->offline_status, get_offline_text (p->offline_status & 0x7f),
! 		 (p->offline_status & 0x80 ? "Yes" : "No"), p->offline_timeout / 60);
! 	printf ("OffLineCapability=%d {%s %s %s}\n", p->offline_capability,
! 					 p->offline_capability & 1 ? "Immediate" : "",
! 					 p->offline_capability & 2 ? "Auto" : "",
! 					 p->offline_capability & 4 ? "AbortOnCmd" : "SuspendOnCmd");
! 	printf ("SmartRevision=%d, CheckSum=%d, SmartCapability=%d {%s %s}\n",
! 					 p->revision, p->checksum, p->smart_capability,
! 					 p->smart_capability & 1 ? "SaveOnStandBy" : "",
! 					 p->smart_capability & 2 ? "AutoSave" : "");
  }
  void
  print_thresholds (thresholds_t * p) 
--- 272,295 ----
  	}
  	printf
! 		(_("OffLineStatus=%d {%s}, AutoOffLine=%s, OffLineTimeout=%d minutes\n"),
! 		 p->offline_status,
! 		 get_offline_text (p->offline_status & 0x7f),
! 		 (p->offline_status & 0x80 ? "Yes" : "No"),
! 		 p->offline_timeout / 60);
! 	printf
! 		(_("OffLineCapability=%d {%s %s %s}\n"),
! 		 p->offline_capability,
! 		 p->offline_capability & 1 ? "Immediate" : "",
! 		 p->offline_capability & 2 ? "Auto" : "",
! 		 p->offline_capability & 4 ? "AbortOnCmd" : "SuspendOnCmd");
! 	printf
! 		(_("SmartRevision=%d, CheckSum=%d, SmartCapability=%d {%s %s}\n"),
! 		 p->revision,
! 		 p->checksum,
! 		 p->smart_capability,
! 		 p->smart_capability & 1 ? "SaveOnStandBy" : "",
! 		 p->smart_capability & 2 ? "AutoSave" : "");
  }
+ 
  void
  print_thresholds (thresholds_t * p) 
***************
*** 282,313 ****
  		if (threshold->id) {
  			printf ("Id=%3d, Threshold=%3d\n", threshold->id,
! 							 threshold->threshold); }
  		++threshold;
  	}
  	printf ("CheckSum=%d\n", p->checksum);
  }
  int
  smart_cmd_simple (int fd, enum SmartCommand command, __u8 val0,
  									char show_error) 
  {
- 	__u8 args[4] = {
- 	WIN_SMART, val0, smart_command[command].value, 0};
  	int e = 0;
  	if (ioctl (fd, HDIO_DRIVE_CMD, &args)) {
  		e = errno;
  		if (show_error) {
! 			printf ("Critical: %s: %s\n", smart_command[command].text,
! 							 strerror (errno)); }
  	}
  	return e;
  }
  int
  smart_read_thresholds (int fd, thresholds_t * thresholds) 
  {
! 	__u8 args[4 + 512] = {
! 	WIN_SMART, 0, SMART_READ_THRESHOLDS, 1,};
  	if (ioctl (fd, HDIO_DRIVE_CMD, &args)) {
! 		int e = errno;
! 		printf ("Critical: SMART_READ_THRESHOLDS: %s\n", strerror (errno));
  		return e;
  	}
--- 302,342 ----
  		if (threshold->id) {
  			printf ("Id=%3d, Threshold=%3d\n", threshold->id,
! 							threshold->threshold); }
  		++threshold;
  	}
  	printf ("CheckSum=%d\n", p->checksum);
  }
+ 
  int
  smart_cmd_simple (int fd, enum SmartCommand command, __u8 val0,
  									char show_error) 
  {
  	int e = 0;
+ 	__u8 args[4];
+ 	args[0] = WIN_SMART;
+ 	args[1] = val0;
+ 	args[2] = smart_command[command].value;
+ 	args[3] = 0;
  	if (ioctl (fd, HDIO_DRIVE_CMD, &args)) {
  		e = errno;
  		if (show_error) {
! 			printf (_("Critical: %s: %s\n"), smart_command[command].text, strerror (errno));
! 		}
  	}
  	return e;
  }
+ 
  int
  smart_read_thresholds (int fd, thresholds_t * thresholds) 
  {
! 	int e;
! 	__u8 args[4 + 512];
! 	args[0] = WIN_SMART;
!   args[1] = 0;
!   args[2] = SMART_READ_THRESHOLDS;
!   args[3] = 1;
  	if (ioctl (fd, HDIO_DRIVE_CMD, &args)) {
! 		e = errno;
! 		printf (_("Critical: SMART_READ_THRESHOLDS: %s\n"), strerror (errno));
  		return e;
  	}
***************
*** 315,318 ****
--- 344,348 ----
  	return 0;
  }
+ 
  void
  show_version () 
***************
*** 322,337 ****
  	printf ("(C) 1999 Ragnar Hojland Espinosa <ragnar at lightside.dhis.org>\n");
  }
  void
  show_help () 
  {
! 	printf ("Usage: check_ide-smart [DEVICE] [OPTION]\n" 
! 					 "	   -d, --device=DEVICE	Select device DEVICE\n" 
! 					 "	   -i, --immediate	Perform immediately offline tests\n" 
! 					 "	   -q, --quiet-check	Returns the number of failed tests\n" 
! 					 "	   -1, --auto-on	Turn on automatic offline tests\n" 
! 					 "	   -0, --auto-off	Turn off automatic offline tests\n" 
! 					 "	   -n, --net-saint	Output suitable for Net Saint\n" 
! 					 "	   -h, --help\n"  "	   -V, --version\n");
  }
  int
  main (int argc, char *argv[]) 
--- 352,377 ----
  	printf ("(C) 1999 Ragnar Hojland Espinosa <ragnar at lightside.dhis.org>\n");
  }
+ 
  void
  show_help () 
  {
! 	printf (_("\
! Usage: check_ide-smart [DEVICE] [OPTION]\n\
!  -d, --device=DEVICE\n\
!     Select device DEVICE\n\
!  -i, --immediate\n\
!     Perform immediately offline tests\n\
!  -q, --quiet-check\n\
!     Returns the number of failed tests\n\
!  -1, --auto-on\n\
!     Turn on automatic offline tests\n\
!  -0, --auto-off\n\
!     Turn off automatic offline tests\n\
!  -n, --net-saint\n\
!     Output suitable for Net Saint\n\
!  -h, --help\n\
!  -V, --version\n"));
  }
+ 
  int
  main (int argc, char *argv[]) 
***************
*** 341,347 ****
  	int o, longindex;
  	int retval = 0;
! 	
! 	const struct option longopts[] = { 
! 			{"device", required_argument, 0, 'd'}, 
  		{"immediate", no_argument, 0, 'i'}, 
  		{"quiet-check", no_argument, 0, 'q'}, 
--- 381,391 ----
  	int o, longindex;
  	int retval = 0;
! 
! 	thresholds_t thresholds;
! 	values_t values;
! 	int fd;
! 
! 	static struct option longopts[] = { 
! 		{"device", required_argument, 0, 'd'}, 
  		{"immediate", no_argument, 0, 'i'}, 
  		{"quiet-check", no_argument, 0, 'q'}, 
***************
*** 352,362 ****
  		{"version", no_argument, 0, 'V'}, {0, 0, 0, 0} 
  	};
! 	
! 		while (1) {
  		
! 			o = getopt_long (argc, argv, "+d:iq10nhV", longopts, &longindex);
  		
! 			if (o == -1 || o == EOF)
  			break;
  		switch (o) {
  		case 'd':
--- 396,407 ----
  		{"version", no_argument, 0, 'V'}, {0, 0, 0, 0} 
  	};
! 
! 	while (1) {
  		
! 		o = getopt_long (argc, argv, "+d:iq10nhV", longopts, &longindex);
  		
! 		if (o == -1 || o == EOF)
  			break;
+ 
  		switch (o) {
  		case 'd':
***************
*** 385,394 ****
  			return 0;
  		default:
! 			printf ("Try `%s --help' for more information.\n", argv[0]);
  			return 1;
  		}
  		if (optind < argc) {
  			device = argv[optind];
  		}
  		if (!device) {
  			show_help ();
--- 430,441 ----
  			return 0;
  		default:
! 			printf (_("Try `%s --help' for more information.\n"), argv[0]);
  			return 1;
  		}
+ 
  		if (optind < argc) {
  			device = argv[optind];
  		}
+ 
  		if (!device) {
  			show_help ();
***************
*** 396,440 ****
  			return -1;
  		}
! 		if (1) {
! 			thresholds_t thresholds;
! 			values_t values;
! 			int fd = open (device, O_RDONLY);
! 			if (fd < 0) {
! 				printf ("Critical: Couldn't open device: %s\n", strerror (errno));
! 				return 2;
! 			}
! 			if (smart_cmd_simple (fd, SMART_CMD_ENABLE, 0, TRUE)) {
! 				printf ("Critical: SMART_CMD_ENABLE\n");
! 				return 2;
! 			}
! 			switch (command) {
! 			case 0:
! 				retval = smart_cmd_simple (fd, SMART_CMD_AUTO_OFFLINE, 0, TRUE);
! 				break;
! 			case 1:
! 				retval = smart_cmd_simple (fd, SMART_CMD_AUTO_OFFLINE, 0xF8, TRUE);
! 				break;
! 			case 2:
! 				retval = smart_cmd_simple (fd, SMART_CMD_IMMEDIATE_OFFLINE, 0, TRUE);
! 				break;
! 			case 3:
! 				smart_read_values (fd, &values);
! 				smart_read_thresholds (fd, &thresholds);
! 				retval = values_not_passed (&values, &thresholds);
! 				break;
! 			case 4:
! 				smart_read_values (fd, &values);
! 				smart_read_thresholds (fd, &thresholds);
! 				retval = net_saint (&values, &thresholds);
! 				break;
! 			default:
! 				smart_read_values (fd, &values);
! 				smart_read_thresholds (fd, &thresholds);
! 				print_values (&values, &thresholds);
! 				break;
! 			}
! 			close (fd);
  		}
! 		return retval;
  	}
  	
--- 443,488 ----
  			return -1;
  		}
! 
! 		fd = open (device, O_RDONLY);
! 
! 		if (fd < 0) {
! 			printf (_("Critical: Couldn't open device: %s\n"), strerror (errno));
! 			return 2;
! 		}
! 
! 		if (smart_cmd_simple (fd, SMART_CMD_ENABLE, 0, TRUE)) {
! 			printf (_("Critical: SMART_CMD_ENABLE\n"));
! 			return 2;
! 		}
! 
! 		switch (command) {
! 		case 0:
! 			retval = smart_cmd_simple (fd, SMART_CMD_AUTO_OFFLINE, 0, TRUE);
! 			break;
! 		case 1:
! 			retval = smart_cmd_simple (fd, SMART_CMD_AUTO_OFFLINE, 0xF8, TRUE);
! 			break;
! 		case 2:
! 			retval = smart_cmd_simple (fd, SMART_CMD_IMMEDIATE_OFFLINE, 0, TRUE);
! 			break;
! 		case 3:
! 			smart_read_values (fd, &values);
! 			smart_read_thresholds (fd, &thresholds);
! 			retval = values_not_passed (&values, &thresholds);
! 			break;
! 		case 4:
! 			smart_read_values (fd, &values);
! 			smart_read_thresholds (fd, &thresholds);
! 			retval = net_saint (&values, &thresholds);
! 			break;
! 		default:
! 			smart_read_values (fd, &values);
! 			smart_read_thresholds (fd, &thresholds);
! 			print_values (&values, &thresholds);
! 			break;
  		}
! 		close (fd);
  	}
+ 	return retval;
+ }
  	





More information about the Commits mailing list