check_procs.t 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #! /usr/bin/perl -w -I ..
  2. #
  3. # Process Tests via check_procs
  4. #
  5. #
  6. use strict;
  7. use Test::More;
  8. use NPTest;
  9. my $t;
  10. if (`uname -s` eq "SunOS\n" && ! -x "/usr/local/nagios/libexec/pst3") {
  11. plan skip_all => "Ignoring tests on solaris because of pst3";
  12. } else {
  13. plan tests => 14;
  14. }
  15. my $result;
  16. $result = NPTest->testCmd( "./check_procs -w 100000 -c 100000" );
  17. is( $result->return_code, 0, "Checking less than 10000 processes" );
  18. like( $result->output, '/^PROCS OK: [0-9]+ process(es)? | procs=[0-9]+;100000;100000;0;$/', "Output correct" );
  19. $result = NPTest->testCmd( "./check_procs -w 100000 -c 100000 -s Z" );
  20. is( $result->return_code, 0, "Checking less than 100000 zombie processes" );
  21. like( $result->output, '/^PROCS OK: [0-9]+ process(es)? with /', "Output correct" );
  22. SKIP: {
  23. skip "No bash available", 2 unless(system("which bash > /dev/null") == 0);
  24. $result = NPTest->testCmd( "bash -c './check_procs -a '/sbin/init'; true'" );
  25. is( $result->return_code, 0, "Parent process is ignored" );
  26. like( $result->output, '/^PROCS OK: 1 process?/', "Output correct" );
  27. }
  28. $result = NPTest->testCmd( "./check_procs -w 0 -c 100000" );
  29. is( $result->return_code, 1, "Checking warning if processes > 0" );
  30. like( $result->output, '/^PROCS WARNING: [0-9]+ process(es)? | procs=[0-9]+;0;100000;0;$/', "Output correct" );
  31. $result = NPTest->testCmd( "./check_procs -w 0 -c 0" );
  32. is( $result->return_code, 2, "Checking critical if processes > 0" );
  33. like( $result->output, '/^PROCS CRITICAL: [0-9]+ process(es)? | procs=[0-9]+;0;0;0;$/', "Output correct" );
  34. $result = NPTest->testCmd( "./check_procs -w 0 -c 0 -s Ss" );
  35. is( $result->return_code, 2, "Checking critical if sleeping processes" );
  36. like( $result->output, '/^PROCS CRITICAL: [0-9]+ process(es)? with /', "Output correct" );
  37. $result = NPTest->testCmd( "./check_procs -w 0 -c 100000 -p 1" );
  38. is( $result->return_code, 1, "Checking warning for processes by parentid = 1" );
  39. like( $result->output, '/^PROCS WARNING: [0-9]+ process(es)? with PPID = 1/', "Output correct" );