4
0

check_procs.t 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. #! /usr/bin/perl -w -I ..
  2. #
  3. # Test check_procs using input files
  4. #
  5. use strict;
  6. use Test::More;
  7. use NPTest;
  8. if (-x "./check_procs") {
  9. plan tests => 50;
  10. } else {
  11. plan skip_all => "No check_procs compiled";
  12. }
  13. my $result;
  14. my $command = "./check_procs --input-file=tests/var/ps-axwo.darwin";
  15. $result = NPTest->testCmd( "$command" );
  16. is( $result->return_code, 0, "Run with no options" );
  17. like( $result->output, '/^PROCS OK: 95 processes$/', "Output correct" );
  18. $result = NPTest->testCmd( "$command -w 5" );
  19. is( $result->return_code, 1, "Checking > 5 processes" );
  20. like( $result->output, '/^PROCS WARNING: 95 processes$/', "Output correct" );
  21. $result = NPTest->testCmd( "$command -w 4 -c 44" );
  22. is( $result->return_code, 2, "Checking critical" );
  23. like( $result->output, '/^PROCS CRITICAL: 95 processes$/', "Output correct" );
  24. $result = NPTest->testCmd( "$command -w 100 -c 200" );
  25. is( $result->return_code, 0, "Checking no threshold breeched" );
  26. like( $result->output, '/^PROCS OK: 95 processes$/', "Output correct" );
  27. $result = NPTest->testCmd( "$command -C launchd -c 5" );
  28. is( $result->return_code, 2, "Checking processes filtered by command name" );
  29. like( $result->output, '/^PROCS CRITICAL: 6 processes with command name \'launchd\'$/', "Output correct" );
  30. $result = NPTest->testCmd( "$command -u 501 -w 39 -c 41" );
  31. is( $result->return_code, 1, "Checking processes filtered by userid" );
  32. like( $result->output, '/^PROCS WARNING: 40 processes with UID = 501 (.*)$/', "Output correct" );
  33. $result = NPTest->testCmd( "$command -C launchd -u 501" );
  34. is( $result->return_code, 0, "Checking processes filtered by command name and userid" );
  35. like( $result->output, '/^PROCS OK: 1 process with command name \'launchd\', UID = 501 (.*)$/', "Output correct" );
  36. $result = NPTest->testCmd( "$command -u -2 -w 2:2" );
  37. is( $result->return_code, 1, "Checking processes with userid=-2" );
  38. like( $result->output, '/^PROCS WARNING: 3 processes with UID = -2 \(nobody\)$/', "Output correct" );
  39. $result = NPTest->testCmd( "$command -u -2 -w 3:3" );
  40. is( $result->return_code, 0, "Checking processes with userid=-2 past threshold" );
  41. like( $result->output, '/^PROCS OK: 3 processes with UID = -2 \(nobody\)$/', "Output correct" );
  42. $result = NPTest->testCmd( "$command -u -2 -a usb" );
  43. is( $result->return_code, 0, "Checking processes with userid=-2 and usb in arguments" );
  44. like( $result->output, '/^PROCS OK: 1 process with UID = -2 \(nobody\), args \'usb\'/', "Output correct" );
  45. $result = NPTest->testCmd( "$command -u -2 -a UsB" );
  46. is( $result->return_code, 0, "Checking case sensitivity of args" );
  47. like( $result->output, '/^PROCS OK: 0 processes with UID = -2 \(nobody\), args \'UsB\'/', "Output correct" );
  48. $result = NPTest->testCmd( "$command --ereg-argument-array='mdworker.*501'" );
  49. is( $result->return_code, 0, "Checking regexp search of arguments" );
  50. is( $result->output, "PROCS OK: 1 process with regex args 'mdworker.*501'", "Output correct" );
  51. $result = NPTest->testCmd( "$command --vsz 1000000" );
  52. is( $result->return_code, 0, "Checking filter by VSZ" );
  53. like( $result->output, '/^PROCS OK: 24 processes with VSZ >= 1000000$/', "Output correct" );
  54. $result = NPTest->testCmd( "$command --rss 100000" );
  55. is( $result->return_code, 0, "Checking filter by RSS" );
  56. like( $result->output, '/^PROCS OK: 3 processes with RSS >= 100000$/', "Output correct" );
  57. $result = NPTest->testCmd( "$command -s S" );
  58. is( $result->return_code, 0, "Checking filter for sleeping processes" );
  59. like( $result->output, '/^PROCS OK: 44 processes with STATE = S/', "Output correct" );
  60. $result = NPTest->testCmd( "$command -s Z" );
  61. is( $result->return_code, 0, "Checking filter for zombies" );
  62. like( $result->output, '/^PROCS OK: 1 process with STATE = Z/', "Output correct" );
  63. $result = NPTest->testCmd( "$command -p 1 -c 30" );
  64. is( $result->return_code, 2, "Checking filter for parent id = 1" );
  65. like( $result->output, '/^PROCS CRITICAL: 39 processes with PPID = 1/', "Output correct" );
  66. $result = NPTest->testCmd( "$command -P 0.71" );
  67. is( $result->return_code, 0, "Checking filter for percentage cpu > 0.71" );
  68. is( $result->output, 'PROCS OK: 7 processes with PCPU >= 0.71', "Output correct" );
  69. $result = NPTest->testCmd( "$command -P 0.70" );
  70. is( $result->return_code, 0, "Checking filter for percentage cpu > 0.70" );
  71. is( $result->output, 'PROCS OK: 8 processes with PCPU >= 0.70', "Output correct" );
  72. $result = NPTest->testCmd( "$command --metric=CPU -w 8" );
  73. is( $result->return_code, 1, "Checking against metric of CPU > 8" );
  74. is( $result->output, 'CPU WARNING: 1 warn out of 95 processes', "Output correct" );
  75. # TODO: Because of a conversion to int, if CPU is 1.45%, will not alert, but 2.01% will.
  76. $result = NPTest->testCmd( "$command --metric=CPU -w 1 -u 501 -v" );
  77. is( $result->return_code, 1, "Checking against metric of CPU > 1 with uid=501 - TODO" );
  78. is( $result->output, 'CPU WARNING: 2 warn out of 40 processes with UID = 501 (tonvoon) [Skype, PubSubAgent]', "Output correct" );
  79. $result = NPTest->testCmd( "$command --metric=VSZ -w 1200000 -v" );
  80. is( $result->return_code, 1, "Checking against VSZ > 1.2GB" );
  81. is( $result->output, 'VSZ WARNING: 4 warn out of 95 processes [WindowServer, Safari, Mail, Skype]', "Output correct" );
  82. $result = NPTest->testCmd( "$command --metric=VSZ -w 1200000 -v" );
  83. is( $result->return_code, 1, "Checking against VSZ > 1.2GB" );
  84. is( $result->output, 'VSZ WARNING: 4 warn out of 95 processes [WindowServer, Safari, Mail, Skype]', "Output correct" );
  85. $result = NPTest->testCmd( "$command --metric=RSS -c 70000 -v" );
  86. is( $result->return_code, 2, "Checking against RSS > 70MB" );
  87. is( $result->output, 'RSS CRITICAL: 5 crit, 0 warn out of 95 processes [WindowServer, SystemUIServer, Safari, Mail, Safari]', "Output correct" );
  88. $result = NPTest->testCmd( "$command --ereg-argument-array='(nosuchname|nosuch2name)'" );
  89. is( $result->return_code, 0, "Checking no pipe symbol in output" );
  90. is( $result->output, "PROCS OK: 0 processes with regex args '(nosuchname,nosuch2name)'", "Output correct" );