aboutsummaryrefslogtreecommitdiff
path: root/plugins-scripts/t/check_disk_smb.t
blob: c2e8bbb27c493572dcd59c13fab7cfd5fe40dd47 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#! /usr/bin/perl -w -I ..
#
# test cases for check_disk_smb
#

use strict;
use Test::More;
use NPTest;

my $tests = 14;
plan tests => $tests;
my $res;

my $plugin = "check_disk_smb";
SKIP: {
	skip "$plugin is not created", $tests if ( ! -x $plugin );
	my $auth = "";

	my $host = getTestParameter("NP_HOST_SMB", "A host providing an SMB Service",
	                            "localhost");

	my $smb_share = getTestParameter("NP_SMB_SHARE",
	                                 "An SMB share name the host provides",
	                                 "public");

	my $smb_share_spc = getTestParameter("NP_SMB_SHARE_SPC",
	                                     "An SMB share name containing one or more spaces the host provides",
	                                     "pub lic");

	my $smb_share_deny = getTestParameter("NP_SMB_SHARE_DENY",
	                                      "An access denying SMB share name the host provides",
	                                      "private");

	my $host_nonresponsive = getTestParameter( "NP_HOST_NONRESPONSIVE",
	                                           "The hostname of system not responsive to network requests", "10.0.0.1" );

	my $hostname_invalid   = getTestParameter( "NP_HOSTNAME_INVALID",
	                                           "An invalid (not known to DNS) hostname",
	                                           "nosuchhost" );
	my $user = getTestParameter( "NP_SMB_VALID_USER", "A valid smb user", "" );
	my $pass = getTestParameter( "NP_SMB_VALID_USER_PASS", "A valid password for valid smb user", "" );
	$auth .= "-u $user " if ($user);
	$auth .= "-p $pass " if ($pass);



	$res = NPTest->testCmd( "./$plugin" );
	is( $res->return_code, 3, "No arguments" );

	$res = NPTest->testCmd( "./$plugin -H fakehostname" );
	is( $res->return_code, 3, "No share specified" );

	$res = NPTest->testCmd( "./$plugin -H fakehostname -s share -w 100G -c 101G" );
	is( $res->return_code, 3, "warn is less than critical" );

	SKIP: {
		skip "no smb host defined", 10 if ( ! $host );

		SKIP: {
			skip "no share name defined", 2 if ( ! $smb_share );
			$res = NPTest->testCmd( "./$plugin -H $host $auth -s $smb_share -w 2k -c 1k" );
			cmp_ok( $res->return_code, '==', 0, "Exit OK if $smb_share has > 1k free space");
			like($res->output, '/free/i', "String contains the word 'free'");

			$res = NPTest->testCmd( "./$plugin -H $host $auth -s $smb_share -w 10001G -c 10000G" );
			cmp_ok( $res->return_code, '==', 2, "Exit CRIT if $smb_share has < 10000G free space");
			like($res->output, '/free/i', "String contains the word 'free'");

			$res = NPTest->testCmd( "./$plugin -H $host $auth -s $smb_share -w 10000G -c 1k" );
			cmp_ok( $res->return_code, '==', 1, "Exit WARN if $smb_share has > 10000G and <1k free space");
			like($res->output, '/free/i', "String contains the word 'free'");
		}

		SKIP: {
			skip "no share name containing spaces defined", 2 if ( ! $smb_share_spc );
			$res = NPTest->testCmd( "./$plugin -H $host $auth -s '$smb_share_spc' -w 2k -c 1k" );
			cmp_ok( $res->return_code, '==', 0, "Exit OK if '$smb_share_spc' has > 1k free space");
			like($res->output, '/free/i', "String contains the word 'free'");

		}
		SKIP: {
			skip "no share name without permissions ", 2 if ( ! $smb_share_deny );
			$res = NPTest->testCmd( "./$plugin -H $host $auth -s $smb_share_deny -w 2k -c 1k" );
			cmp_ok( $res->return_code, '==', 2, "Exit CRIT if $smb_share_deny has > 1k free space");
			unlike($res->output, '/free/i', "String does not contain the word 'free'");

		}
	}

	SKIP: {
		skip "no non responsive host defined", 1 if ( ! $host_nonresponsive );
		$res = NPTest->testCmd( "./$plugin -H $host_nonresponsive -s np_foobar ");
		cmp_ok( $res->return_code, '>=', 2, "Exit CRITICAL/UNKNOWN with non responsive host" );
	}

}