4
0

check_procs.t 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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. is( $result->output, "PROCS OK: 95 processes | procs=95;;;0;", "Output correct" );
  18. $result = NPTest->testCmd( "$command -w 5" );
  19. is( $result->return_code, 1, "Checking > 5 processes" );
  20. is( $result->output, "PROCS WARNING: 95 processes | procs=95;5;;0;", "Output correct" );
  21. $result = NPTest->testCmd( "$command -w 4 -c 44" );
  22. is( $result->return_code, 2, "Checking critical" );
  23. is( $result->output, "PROCS CRITICAL: 95 processes | procs=95;4;44;0;", "Output correct" );
  24. $result = NPTest->testCmd( "$command -w 100 -c 200" );
  25. is( $result->return_code, 0, "Checking no threshold breeched" );
  26. is( $result->output, "PROCS OK: 95 processes | procs=95;100;200;0;", "Output correct" );
  27. $result = NPTest->testCmd( "$command -C launchd -c 5" );
  28. is( $result->return_code, 2, "Checking processes filtered by command name" );
  29. is( $result->output, "PROCS CRITICAL: 6 processes with command name 'launchd' | procs=6;;5;0;", "Output correct" );
  30. SKIP: {
  31. skip 'user with uid 501 required', 4 unless getpwuid(501);
  32. $result = NPTest->testCmd( "$command -u 501 -w 39 -c 41" );
  33. is( $result->return_code, 1, "Checking processes filtered by userid" );
  34. like( $result->output, '/^PROCS WARNING: 40 processes with UID = 501 (.*)$/', "Output correct" );
  35. $result = NPTest->testCmd( "$command -C launchd -u 501" );
  36. is( $result->return_code, 0, "Checking processes filtered by command name and userid" );
  37. like( $result->output, '/^PROCS OK: 1 process with command name \'launchd\', UID = 501 (.*)$/', "Output correct" );
  38. }
  39. SKIP: {
  40. skip 'user with uid -2 required', 8 unless getpwuid(-2);
  41. $result = NPTest->testCmd( "$command -u -2 -w 2:2" );
  42. is( $result->return_code, 1, "Checking processes with userid=-2" );
  43. like( $result->output, '/^PROCS WARNING: 3 processes with UID = -2 \(nobody\)$/', "Output correct" );
  44. $result = NPTest->testCmd( "$command -u -2 -w 3:3" );
  45. is( $result->return_code, 0, "Checking processes with userid=-2 past threshold" );
  46. like( $result->output, '/^PROCS OK: 3 processes with UID = -2 \(nobody\)$/', "Output correct" );
  47. $result = NPTest->testCmd( "$command -u -2 -a usb" );
  48. is( $result->return_code, 0, "Checking processes with userid=-2 and usb in arguments" );
  49. like( $result->output, '/^PROCS OK: 1 process with UID = -2 \(nobody\), args \'usb\'/', "Output correct" );
  50. $result = NPTest->testCmd( "$command -u -2 -a UsB" );
  51. is( $result->return_code, 0, "Checking case sensitivity of args" );
  52. like( $result->output, '/^PROCS OK: 0 processes with UID = -2 \(nobody\), args \'UsB\'/', "Output correct" );
  53. }
  54. $result = NPTest->testCmd( "$command --ereg-argument-array='com\.apple.*501'" );
  55. is( $result->return_code, 0, "Checking regexp search of arguments" );
  56. is( $result->output, "PROCS OK: 1 process with regex args 'com\.apple.*501' | procs=1;;;0;", "Output correct" );
  57. $result = NPTest->testCmd( "$command --vsz 1000000" );
  58. is( $result->return_code, 0, "Checking filter by VSZ" );
  59. is( $result->output, 'PROCS OK: 24 processes with VSZ >= 1000000 | procs=24;;;0;', "Output correct" );
  60. $result = NPTest->testCmd( "$command --rss 100000" );
  61. is( $result->return_code, 0, "Checking filter by RSS" );
  62. is( $result->output, 'PROCS OK: 3 processes with RSS >= 100000 | procs=3;;;0;', "Output correct" );
  63. $result = NPTest->testCmd( "$command -s S" );
  64. is( $result->return_code, 0, "Checking filter for sleeping processes" );
  65. like( $result->output, '/^PROCS OK: 44 processes with STATE = S/', "Output correct" );
  66. $result = NPTest->testCmd( "$command -s Z" );
  67. is( $result->return_code, 0, "Checking filter for zombies" );
  68. like( $result->output, '/^PROCS OK: 1 process with STATE = Z/', "Output correct" );
  69. $result = NPTest->testCmd( "$command -p 1 -c 30" );
  70. is( $result->return_code, 2, "Checking filter for parent id = 1" );
  71. like( $result->output, '/^PROCS CRITICAL: 39 processes with PPID = 1/', "Output correct" );
  72. $result = NPTest->testCmd( "$command -P 0.71" );
  73. is( $result->return_code, 0, "Checking filter for percentage cpu > 0.71" );
  74. is( $result->output, 'PROCS OK: 7 processes with PCPU >= 0.71 | procs=7;;;0;', "Output correct" );
  75. $result = NPTest->testCmd( "$command -P 0.70" );
  76. is( $result->return_code, 0, "Checking filter for percentage cpu > 0.70" );
  77. is( $result->output, 'PROCS OK: 8 processes with PCPU >= 0.70 | procs=8;;;0;', "Output correct" );
  78. $result = NPTest->testCmd( "$command --metric=CPU -w 8" );
  79. is( $result->return_code, 1, "Checking against metric of CPU > 8" );
  80. is( $result->output, 'CPU WARNING: 1 warn out of 95 processes | procs=95;;;0; procs_warn=1;;;0; procs_crit=0;;;0; procpcpu=23.000000;', "Output correct" );
  81. # TODO: Because of a conversion to int, if CPU is 1.45%, will not alert, but 2.01% will.
  82. SKIP: {
  83. skip 'user with uid 501 required', 2 unless getpwuid(501);
  84. $result = NPTest->testCmd( "$command --metric=CPU -w 1 -u 501 -v" );
  85. is( $result->return_code, 1, "Checking against metric of CPU > 1 with uid=501 - TODO" );
  86. is( $result->output, 'CPU WARNING: 2 warn out of 40 processes with UID = 501 (tonvoon) [Skype, PubSubAgent]', "Output correct" );
  87. };
  88. $result = NPTest->testCmd( "$command --metric=VSZ -w 1200000 -v" );
  89. is( $result->return_code, 1, "Checking against VSZ > 1.2GB" );
  90. is( $result->output, 'VSZ WARNING: 4 warn out of 95 processes [WindowServer, Safari, Mail, Skype] | procs=95;;;0; procs_warn=4;;;0; procs_crit=0;;;0; procvsz=74520456;', "Output correct" );
  91. $result = NPTest->testCmd( "$command --metric=VSZ -w 1200000 -v" );
  92. is( $result->return_code, 1, "Checking against VSZ > 1.2GB" );
  93. is( $result->output, 'VSZ WARNING: 4 warn out of 95 processes [WindowServer, Safari, Mail, Skype] | procs=95;;;0; procs_warn=4;;;0; procs_crit=0;;;0; procvsz=74520456;', "Output correct" );
  94. $result = NPTest->testCmd( "$command --metric=RSS -c 70000 -v" );
  95. is( $result->return_code, 2, "Checking against RSS > 70MB" );
  96. is( $result->output, 'RSS CRITICAL: 5 crit, 0 warn out of 95 processes [WindowServer, SystemUIServer, Safari, Mail, Safari] | procs=95;;;0; procs_warn=0;;;0; procs_crit=5;;;0; procrss=2381476;', "Output correct" );
  97. $result = NPTest->testCmd( "$command --ereg-argument-array='(nosuchname|nosuch2name)'" );
  98. is( $result->return_code, 0, "Checking no pipe symbol in output" );
  99. is( $result->output, "PROCS OK: 0 processes with regex args '(nosuchname,nosuch2name)' | procs=0;;;0;", "Output correct" );