check_load.t 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. #! /usr/bin/perl -w -I ..
  2. #
  3. # Load Average Tests via check_load
  4. #
  5. #
  6. use strict;
  7. use Test::More;
  8. use NPTest;
  9. my $res;
  10. my $loadValue = "[0-9]+\.?[0-9]+";
  11. my $successOutput = "/^OK - load average: $loadValue, $loadValue, $loadValue/";
  12. my $failureOutput = "/^CRITICAL - load average: $loadValue, $loadValue, $loadValue/";
  13. my $failureOutputPerCPU = "/^CRITICAL - load average per CPU: $loadValue, $loadValue, $loadValue/";
  14. plan tests => 11;
  15. $res = NPTest->testCmd( "./check_load -w 100,100,100 -c 100,100,100" );
  16. cmp_ok( $res->return_code, 'eq', 0, "load not over 100");
  17. like( $res->output, $successOutput, "Output OK");
  18. $res = NPTest->testCmd( "./check_load -w 0,0,0 -c 0,0,0" );
  19. cmp_ok( $res->return_code, 'eq', 2, "Load over 0");
  20. like( $res->output, $failureOutput, "Output OK");
  21. $res = NPTest->testCmd( "./check_load -r -w 0,0,0 -c 0,0,0" );
  22. cmp_ok( $res->return_code, 'eq', 2, "Load over 0 with per cpu division");
  23. like( $res->output, $failureOutputPerCPU, "Output OK");
  24. $res = NPTest->testCmd( "./check_load -w 100 -c 100,110" );
  25. cmp_ok( $res->return_code, 'eq', 0, "Plugin can handle non-triplet-arguments");
  26. like( $res->output, $successOutput, "Output OK");
  27. like( $res->perf_output, "/load1=$loadValue;100.000;100.000/", "Test handling of non triplet thresholds (load1)");
  28. like( $res->perf_output, "/load5=$loadValue;100.000;110.000/", "Test handling of non triplet thresholds (load5)");
  29. like( $res->perf_output, "/load15=$loadValue;100.000;110.000/", "Test handling of non triplet thresholds (load15)");