[Nagiosplug-checkins] SF.net SVN: nagiosplug:[2152] nagiosplug/trunk

dermoth at users.sourceforge.net dermoth at users.sourceforge.net
Fri Feb 20 00:45:19 CET 2009


Revision: 2152
          http://nagiosplug.svn.sourceforge.net/nagiosplug/?rev=2152&view=rev
Author:   dermoth
Date:     2009-02-19 23:45:18 +0000 (Thu, 19 Feb 2009)

Log Message:
-----------
Fixed coredump from check_nt when drive not found (Olli Hauer - SF 2179754)

From: Ton Voon <tonvoon at macbook.local>

Modified Paths:
--------------
    nagiosplug/trunk/NEWS
    nagiosplug/trunk/THANKS.in
    nagiosplug/trunk/plugins/check_nt.c

Added Paths:
-----------
    nagiosplug/trunk/plugins/tests/check_nt.t

Modified: nagiosplug/trunk/NEWS
===================================================================
--- nagiosplug/trunk/NEWS	2009-02-06 13:07:20 UTC (rev 2151)
+++ nagiosplug/trunk/NEWS	2009-02-19 23:45:18 UTC (rev 2152)
@@ -21,6 +21,7 @@
 	Fixed check_mrtg returning UNKNOWN instead of OK (bug #2378068)
 	Fixed check_http behaviour: all check are now performed as long as a valid response is returned (sf.net #1460312)
 	check_http --onredirect=sticky follows using the same IP address (sf.net #2550208).
+	Fixed coredump from check_nt when invalid drive is specified (#2179754 - Olli Hauer)
 
 1.4.13 25th Sept 2008
 	Fix Debian bug #460097: check_http --max-age broken (Hilko Bengen)

Modified: nagiosplug/trunk/THANKS.in
===================================================================
--- nagiosplug/trunk/THANKS.in	2009-02-06 13:07:20 UTC (rev 2151)
+++ nagiosplug/trunk/THANKS.in	2009-02-19 23:45:18 UTC (rev 2152)
@@ -245,3 +245,4 @@
 Jan Lipphaus
 Erik Welch
 Nik Soggia
+Olli Hauer

Modified: nagiosplug/trunk/plugins/check_nt.c
===================================================================
--- nagiosplug/trunk/plugins/check_nt.c	2009-02-06 13:07:20 UTC (rev 2151)
+++ nagiosplug/trunk/plugins/check_nt.c	2009-02-19 23:45:18 UTC (rev 2152)
@@ -93,6 +93,7 @@
 	char *temp_string_perf=NULL;
 	char *description=NULL,*counter_unit = NULL;
 	char *minval = NULL, *maxval = NULL, *errcvt = NULL;
+	char *fds=NULL, *tds=NULL;
 
 	double total_disk_space=0;
 	double free_disk_space=0;
@@ -214,13 +215,18 @@
 		else {
 			asprintf(&send_buffer,"%s&4&%s", req_password, value_list);
 			fetch_data (server_address, server_port, send_buffer);
-			free_disk_space=atof(strtok(recv_buffer,"&"));
-			total_disk_space=atof(strtok(NULL,"&"));
-			percent_used_space = ((total_disk_space - free_disk_space) / total_disk_space) * 100;
-			warning_used_space = ((float)warning_value / 100) * total_disk_space;
-			critical_used_space = ((float)critical_value / 100) * total_disk_space;
+			fds=strtok(recv_buffer,"&");
+			tds=strtok(NULL,"&");
+			if(fds!=NULL)
+				free_disk_space=atof(fds);
+			if(tds!=NULL)
+				total_disk_space=atof(tds);
 
-			if (free_disk_space>=0) {
+			if (total_disk_space>0 && free_disk_space>=0) {
+				percent_used_space = ((total_disk_space - free_disk_space) / total_disk_space) * 100;
+				warning_used_space = ((float)warning_value / 100) * total_disk_space;
+				critical_used_space = ((float)critical_value / 100) * total_disk_space;
+
 				asprintf(&temp_string,_("%s:\\ - total: %.2f Gb - used: %.2f Gb (%.0f%%) - free %.2f Gb (%.0f%%)"),
 				  value_list, total_disk_space / 1073741824, (total_disk_space - free_disk_space) / 1073741824,
 				  percent_used_space, free_disk_space / 1073741824, (free_disk_space / total_disk_space)*100);
@@ -238,7 +244,7 @@
 				output_message = strdup (temp_string);
 				perfdata = temp_string_perf;
 			} else {
-				output_message = strdup (_("Free disk space : Invalid drive "));
+				output_message = strdup (_("Free disk space : Invalid drive"));
 				return_code=STATE_UNKNOWN;
 			}
 		}

Added: nagiosplug/trunk/plugins/tests/check_nt.t
===================================================================
--- nagiosplug/trunk/plugins/tests/check_nt.t	                        (rev 0)
+++ nagiosplug/trunk/plugins/tests/check_nt.t	2009-02-19 23:45:18 UTC (rev 2152)
@@ -0,0 +1,77 @@
+#! /usr/bin/perl -w -I ..
+#
+# Test check_nt by having a stub check_nt daemon
+#
+
+use strict;
+use Test::More;
+use NPTest;
+use FindBin qw($Bin);
+
+use IO::Socket;
+use IO::Select;
+use POSIX;
+
+my $port = 50000 + int(rand(1000));
+
+my $pid = fork();
+if ($pid) {
+	# Parent
+	#print "parent\n";
+	# give our webserver some time to startup
+	sleep(1);
+} else {
+	# Child
+	#print "child\n";
+
+	my $server = IO::Socket::INET->new(
+		LocalPort => $port,
+		Type => SOCK_STREAM,
+		Reuse => 1,
+		Proto => "tcp",
+		Listen => 10,
+	) or die "Cannot be a tcp server on port $port: $@";
+
+	$server->autoflush(1);
+
+	print "Please contact me at port $port\n";
+	while (my $client = $server->accept ) {
+		my $data = "";
+		my $rv = $client->recv($data, POSIX::BUFSIZ, 0);
+
+		my ($password, $command, $arg) = split('&', $data);
+		
+		if ($command eq "4") {
+			if ($arg eq "c") {
+				print $client "930000000&1000000000";
+			} elsif ($arg eq "d") {
+				print $client "UNKNOWN: Drive is not a fixed drive";
+			}
+		}
+	}
+	exit;
+}
+
+END { if ($pid) { print "Killing $pid\n"; kill "INT", $pid } };
+
+if ($ARGV[0] && $ARGV[0] eq "-d") {
+	sleep 1000;
+}
+
+if (-x "./check_nt") {
+	plan tests => 4;
+} else {
+	plan skip_all => "No check_nt compiled";
+}
+
+my $result;
+my $command = "./check_nt -H 127.0.0.1 -p $port";
+
+$result = NPTest->testCmd( "$command -v USEDDISKSPACE -l c" );
+is( $result->return_code, 0, "USEDDISKSPACE c");
+is( $result->output, q{c:\ - total: 0.93 Gb - used: 0.07 Gb (7%) - free 0.87 Gb (93%) | 'c:\ Used Space'=0.07Gb;0.00;0.00;0.00;0.93}, "Output right" );
+
+$result = NPTest->testCmd( "$command -v USEDDISKSPACE -l d" );
+is( $result->return_code, 3, "USEDDISKSPACE d - invalid");
+is( $result->output, "Free disk space : Invalid drive", "Output right" );
+


Property changes on: nagiosplug/trunk/plugins/tests/check_nt.t
___________________________________________________________________
Added: svn:executable
   + *


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Commits mailing list