[Nagiosplug-checkins] nagiosplug/plugins check_ide_smart.c,1.8,1.9

Stanley Hopcroft stanleyhopcroft at users.sourceforge.net
Tue Feb 1 21:46:17 CET 2005


Update of /cvsroot/nagiosplug/nagiosplug/plugins
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30529/nagiosplug/plugins

Modified Files:
	check_ide_smart.c 
Log Message:
restructure main() to stop looping on -n

Index: check_ide_smart.c
===================================================================
RCS file: /cvsroot/nagiosplug/nagiosplug/plugins/check_ide_smart.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- check_ide_smart.c	25 Jan 2005 22:15:00 -0000	1.8
+++ check_ide_smart.c	2 Feb 2005 05:44:26 -0000	1.9
@@ -216,56 +216,56 @@
 		default:
 			usage2 (_("Unknown argument"), optarg);
 		}
+	}
 
-		if (optind < argc) {
-			device = argv[optind];
-		}
+	if (optind < argc) {
+		device = argv[optind];
+	}
 
-		if (!device) {
-			print_help ();
-			return -1;
-		}
+	if (!device) {
+		print_help ();
+		return STATE_OK;
+	}
 
-		fd = open (device, O_RDONLY);
+	fd = open (device, O_RDONLY);
 
-		if (fd < 0) {
-			printf (_("CRITICAL - Couldn't open device %s: %s\n"), device, strerror (errno));
-			return 2;
-		}
+	if (fd < 0) {
+		printf (_("CRITICAL - Couldn't open device %s: %s\n"), device, strerror (errno));
+		return STATE_CRITICAL;
+	}
 
-		if (smart_cmd_simple (fd, SMART_CMD_ENABLE, 0, TRUE)) {
-			printf (_("CRITICAL - SMART_CMD_ENABLE\n"));
-			return 2;
-		}
+	if (smart_cmd_simple (fd, SMART_CMD_ENABLE, 0, TRUE)) {
+		printf (_("CRITICAL - SMART_CMD_ENABLE\n"));
+		return STATE_CRITICAL;
+	}
 
-		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 = nagios (&values, &thresholds);
-			break;
-		default:
-			smart_read_values (fd, &values);
-			smart_read_thresholds (fd, &thresholds);
-			print_values (&values, &thresholds);
-			break;
-		}
-		close (fd);
+	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 = nagios (&values, &thresholds);
+		break;
+	default:
+		smart_read_values (fd, &values);
+		smart_read_thresholds (fd, &thresholds);
+		print_values (&values, &thresholds);
+		break;
 	}
+	close (fd);
 	return retval;
 }
 
@@ -370,6 +370,7 @@
 		        prefailure > 1 ? 's' : ' ',
 		        failed,
 	          total);
+		status=STATE_CRITICAL;
 		break;
 	case ADVISORY:
 		printf (_("WARNING - %d Harddrive Advisor%s Detected. %d/%d tests failed.\n"),
@@ -377,14 +378,16 @@
 		        advisory > 1 ? "ies" : "y",
 		        failed,
 		        total);
+		status=STATE_WARNING;
 		break;
 	case OPERATIONAL:
 		printf (_("OK - Operational (%d/%d tests passed)\n"), passed, total);
+		status=STATE_OK;
 		break;
 	default:
-		printf (_("ERROR - Status '%d' uknown. %d/%d tests passed\n"), status,
+		printf (_("ERROR - Status '%d' unkown. %d/%d tests passed\n"), status,
 						passed, total);
-		status = -1;
+		status = STATE_UNKNOWN;
 		break;
 	}
 	return status;





More information about the Commits mailing list