check_disk_smb.t 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. #! /usr/bin/perl -w -I ..
  2. #
  3. # test cases for check_disk_smb
  4. #
  5. use strict;
  6. use Test::More;
  7. use NPTest;
  8. my $tests = 14;
  9. plan tests => $tests;
  10. my $res;
  11. my $plugin = "check_disk_smb";
  12. SKIP: {
  13. skip "$plugin is not created", $tests if ( ! -x $plugin );
  14. my $auth = "";
  15. my $host = getTestParameter("NP_HOST_SMB", "A host providing an SMB Service",
  16. "localhost");
  17. my $smb_share = getTestParameter("NP_SMB_SHARE",
  18. "An SMB share name the host provides",
  19. "public");
  20. my $smb_share_spc = getTestParameter("NP_SMB_SHARE_SPC",
  21. "An SMB share name containing one or more spaces the host provides",
  22. "pub lic");
  23. my $smb_share_deny = getTestParameter("NP_SMB_SHARE_DENY",
  24. "An access denying SMB share name the host provides",
  25. "private");
  26. my $host_nonresponsive = getTestParameter( "NP_HOST_NONRESPONSIVE",
  27. "The hostname of system not responsive to network requests", "10.0.0.1" );
  28. my $hostname_invalid = getTestParameter( "NP_HOSTNAME_INVALID",
  29. "An invalid (not known to DNS) hostname",
  30. "nosuchhost" );
  31. my $user = getTestParameter( "NP_SMB_VALID_USER", "A valid smb user", "" );
  32. my $pass = getTestParameter( "NP_SMB_VALID_USER_PASS", "A valid password for valid smb user", "" );
  33. $auth .= "-u $user " if ($user);
  34. $auth .= "-p $pass " if ($pass);
  35. $res = NPTest->testCmd( "./$plugin" );
  36. is( $res->return_code, 3, "No arguments" );
  37. $res = NPTest->testCmd( "./$plugin -H fakehostname" );
  38. is( $res->return_code, 3, "No share specified" );
  39. $res = NPTest->testCmd( "./$plugin -H fakehostname -s share -w 100G -c 101G" );
  40. is( $res->return_code, 3, "warn is less than critical" );
  41. SKIP: {
  42. skip "no smb host defined", 6 if ( ! $host );
  43. SKIP: {
  44. skip "no share name defined", 2 if ( ! $smb_share );
  45. $res = NPTest->testCmd( "./$plugin -H $host $auth -s $smb_share -w 2k -c 1k" );
  46. cmp_ok( $res->return_code, '==', 0, "Exit OK if $smb_share has > 1k free space");
  47. like($res->output, '/free/i', "String contains the word 'free'");
  48. $res = NPTest->testCmd( "./$plugin -H $host $auth -s $smb_share -w 10001G -c 10000G" );
  49. cmp_ok( $res->return_code, '==', 2, "Exit CRIT if $smb_share has < 10000G free space");
  50. like($res->output, '/free/i', "String contains the word 'free'");
  51. $res = NPTest->testCmd( "./$plugin -H $host $auth -s $smb_share -w 10000G -c 1k" );
  52. cmp_ok( $res->return_code, '==', 1, "Exit WARN if $smb_share has > 10000G and <1k free space");
  53. like($res->output, '/free/i', "String contains the word 'free'");
  54. }
  55. SKIP: {
  56. skip "no share name containing spaces defined", 2 if ( ! $smb_share_spc );
  57. $res = NPTest->testCmd( "./$plugin -H $host $auth -s '$smb_share_spc' -w 2k -c 1k" );
  58. cmp_ok( $res->return_code, '==', 0, "Exit OK if '$smb_share_spc' has > 1k free space");
  59. like($res->output, '/free/i', "String contains the word 'free'");
  60. }
  61. SKIP: {
  62. skip "no share name without permissions ", 2 if ( ! $smb_share_deny );
  63. $res = NPTest->testCmd( "./$plugin -H $host $auth -s $smb_share_deny -w 2k -c 1k" );
  64. cmp_ok( $res->return_code, '==', 2, "Exit CRIT if $smb_share_deny has > 1k free space");
  65. unlike($res->output, '/free/i', "String does not contain the word 'free'");
  66. }
  67. }
  68. SKIP: {
  69. skip "no non responsive host defined", 1 if ( ! $host_nonresponsive );
  70. $res = NPTest->testCmd( "./$plugin -H $host_nonresponsive -s np_foobar ");
  71. cmp_ok( $res->return_code, '==', 3, "Exit UNKNOWN with non responsive host" );
  72. }
  73. }