check_cluster.t 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. #! /usr/bin/perl -w -I ..
  2. #
  3. # check_cluster tests
  4. #
  5. # $Id$
  6. #
  7. use strict;
  8. use Test::More tests => 15;
  9. use NPTest;
  10. my $result;
  11. $result = NPTest->testCmd(
  12. "./check_cluster -s -w 0:0 -c 0:0 -d 0,0,0,0"
  13. );
  14. cmp_ok( $result->return_code, '==', 0, "Exit OK if non-ok services are inside critical and warning ranges" );
  15. like( $result->output, qr/service/i, "Output contains the word 'service' (case insensitive)");
  16. $result = NPTest->testCmd(
  17. "./check_cluster -l LABEL -s -w 0:0 -c 0:0 -d 0,0,0,0"
  18. );
  19. like( $result->output, qr/LABEL/, "Output contains the defined label 'LABEL' (case sensitive)");
  20. $result = NPTest->testCmd(
  21. "./check_cluster -s -w 0:0 -c 0:1 -d 0,0,0,1"
  22. );
  23. cmp_ok( $result->return_code, '==', 1, "Exit WARNING if non-ok services are inside critical and outside warning ranges" );
  24. $result = NPTest->testCmd(
  25. "./check_cluster -s -w 0:0 -c 0:1 -d 0,0,1,1"
  26. );
  27. cmp_ok( $result->return_code, '==', 2, "Exit CRITICAL if non-ok services are inside critical and outside warning ranges" );
  28. $result = NPTest->testCmd(
  29. "./check_cluster -s -w 0 -c 0 -d 0,0,0,0"
  30. );
  31. cmp_ok( $result->return_code, '==', 0, "Exit OK if non-ok services are inside critical and warning (no ranges)" );
  32. $result = NPTest->testCmd(
  33. "./check_cluster -s -w 0 -c 1 -d 0,0,1,0"
  34. );
  35. cmp_ok( $result->return_code, '==', 1, "Exit WARNING if number of non-ok services exceed warning (no ranges)" );
  36. $result = NPTest->testCmd(
  37. "./check_cluster -s -w 0 -c 1 -d 0,0,1,1"
  38. );
  39. cmp_ok( $result->return_code, '==', 2, "Exit Critical if non-ok services exceed critical warning (no ranges)" );
  40. #
  41. # And for hosts..
  42. #
  43. $result = NPTest->testCmd(
  44. "./check_cluster -h -w 0:0 -c 0:0 -d 0,0,0,0"
  45. );
  46. cmp_ok( $result->return_code, '==', 0, "Exit OK if non-ok hosts are inside critical and warning ranges" );
  47. like( $result->output, qr/host/i, "Output contains the word 'host' (case insensitive)");
  48. $result = NPTest->testCmd(
  49. "./check_cluster -h -w 0:0 -c 0:1 -d 0,0,0,1"
  50. );
  51. cmp_ok( $result->return_code, '==', 1, "Exit WARNING if non-ok hosts are inside critical and outside warning ranges" );
  52. $result = NPTest->testCmd(
  53. "./check_cluster -h -w 0:0 -c 0:1 -d 0,0,1,1"
  54. );
  55. cmp_ok( $result->return_code, '==', 2, "Exit CRITICAL if non-ok hosts are inside critical and outside warning ranges" );
  56. $result = NPTest->testCmd(
  57. "./check_cluster -h -w 0 -c 0 -d 0,0,0,0"
  58. );
  59. cmp_ok( $result->return_code, '==', 0, "Exit OK if non-ok hosts are inside critical and warning (no ranges)" );
  60. $result = NPTest->testCmd(
  61. "./check_cluster -h -w 0 -c 1 -d 0,0,1,0"
  62. );
  63. cmp_ok( $result->return_code, '==', 1, "Exit WARNING if number of non-ok hosts exceed warning (no ranges)" );
  64. $result = NPTest->testCmd(
  65. "./check_cluster -h -w 0 -c 1 -d 0,0,1,1"
  66. );
  67. cmp_ok( $result->return_code, '==', 2, "Exit Critical if non-ok hosts exceed critical warning (no ranges)" );