4
0

check_procs.t 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. if(fork() == 0) { exec("sleep 7"); } else { sleep(1) } # fork a test process in child and give child time to fork in parent
  23. $result = NPTest->testCmd( "./check_procs -a 'sleep 7'" );
  24. is( $result->return_code, 0, "Parent process is ignored" );
  25. like( $result->output, '/^PROCS OK: 1 process?/', "Output correct" );
  26. $result = NPTest->testCmd( "./check_procs -w 0 -c 100000" );
  27. is( $result->return_code, 1, "Checking warning if processes > 0" );
  28. like( $result->output, '/^PROCS WARNING: [0-9]+ process(es)? | procs=[0-9]+;0;100000;0;$/', "Output correct" );
  29. $result = NPTest->testCmd( "./check_procs -w 0 -c 0" );
  30. is( $result->return_code, 2, "Checking critical if processes > 0" );
  31. like( $result->output, '/^PROCS CRITICAL: [0-9]+ process(es)? | procs=[0-9]+;0;0;0;$/', "Output correct" );
  32. $result = NPTest->testCmd( "./check_procs -w 0 -c 0 -s Ss" );
  33. is( $result->return_code, 2, "Checking critical if sleeping processes" );
  34. like( $result->output, '/^PROCS CRITICAL: [0-9]+ process(es)? with /', "Output correct" );
  35. $result = NPTest->testCmd( "./check_procs -w 0 -c 100000 -p 1" );
  36. is( $result->return_code, 1, "Checking warning for processes by parentid = 1" );
  37. like( $result->output, '/^PROCS WARNING: [0-9]+ process(es)? with PPID = 1/', "Output correct" );