[check_postgres] [commit] Add tests for disk_space; added missing msg name.

check_postgres at bucardo.org check_postgres at bucardo.org
Mon Apr 27 21:10:21 UTC 2009


Committed by Jeff Boes <jeff at endpoint.com>

Add tests for disk_space; added missing msg name.

---
 check_postgres.pl |    6 +++---
 t/02_disk_space.t |   46 ++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 49 insertions(+), 3 deletions(-)

diff --git a/check_postgres.pl b/check_postgres.pl
index 85c5539..c49b965 100755
--- a/check_postgres.pl
+++ b/check_postgres.pl
@@ -2663,7 +2663,7 @@ sub check_disk_space {
 	my %seenfs;
 	for $db (@{$info->{db}}) {
 		my %i;
-		while ($db->{slurp} =~ /([ST])\s+\| (\w+)\s+\| (\S*)\s*/g) {
+		while ($db->{slurp} =~ /([ST])\s+\| (\w+)\s+\| (.*?)\n/g) {
 			my ($st,$name,$val) = ($1,$2,$3);
 			$i{$st}{$name} = $val;
 		}
@@ -2717,7 +2717,7 @@ sub check_disk_space {
 
 			$dir{$dir} = 1;
 
-			$COM = "/bin/df -kP $dir 2>&1";
+			$COM = qq{/bin/df -kP "$dir" 2>&1};
 			$res = qx{$COM};
 
 			if ($res !~ /^.+\n(\S+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\%\s+(\S+)/) {
@@ -2741,7 +2741,7 @@ sub check_disk_space {
 			my $prettyused = pretty_size($used);
 			my $prettytotal = pretty_size($total);
 
-			my $msg = msg('', $fs, $mount, $prettyused, $prettytotal, $percent);
+			my $msg = msg('diskspace-msg', $fs, $mount, $prettyused, $prettytotal, $percent);
 
 			$db->{perf} = "$fs=$used";
 
diff --git a/t/02_disk_space.t b/t/02_disk_space.t
new file mode 100644
index 0000000..6eeff2c
--- /dev/null
+++ b/t/02_disk_space.t
@@ -0,0 +1,46 @@
+#!perl
+
+## Test the "disk_space" action
+
+use strict;
+use warnings;
+use Data::Dumper;
+use DBI;
+use Test::More qw(no_plan);
+END { diag "Don't forget to make a plan!" }
+use lib 't','.';
+use CP_Testing;
+
+use vars qw/$dbh $result $t $host $dbname/;
+
+my $cp = CP_Testing->new( {default_action => 'disk_space'} );
+
+$dbh = $cp->test_database_handle();
+$dbh->{AutoCommit} = 1;
+$dbname = $cp->get_dbname;
+$host = $cp->get_host();
+my $label = q{POSTGRES_DISK_SPACE};
+
+my $S = q{Action 'disk_space'};
+
+$t = qq{$S identifies self};
+$result = $cp->run('-w 999z');
+like($result, qr{$label}, $t);
+
+$t = qq{$S identifies host};
+like ($result, qr{host:$host}, $t);
+
+$t = qq{$S reports file system};
+like ($result, qr{FS /.*? mounted on /.*? is using }, $t);
+
+$t = qq{$S reports usage};
+like ($result, qr{ is using \d*\.\d+ [A-Z]B of \d*\.\d+ [A-Z]B}, $t);
+
+$t = qq{$S notes plenty of available space};
+like ($result, qr{$label OK}, $t);
+
+$t = qq{$S flags insufficient space};
+like ($cp->run('-w 1b'), qr{$label WARNING:}, $t);
+
+$t = qq{$S reports MRTG output};
+like ($cp->run('--output=mrtg'), qr{\A\d+\n0\n\n/.*\n}, $t);
-- 
1.6.0.5



More information about the Check_postgres mailing list