check_vcs.pl 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. #!/usr/bin/perl
  2. #
  3. # Veritas Cluster System monitor for Nagios.
  4. # Written by Aaron Bostick (abostick@mydoconline.com)
  5. # Last modified: 05-22-2002
  6. #
  7. # Usage: check_vcs {-g <vcs_group> | -r <vcs_resource> } -s <vcs_system> [-n]
  8. #
  9. # Description:
  10. #
  11. # This plugin is just a perl wrapper to the vcs commands hagrp and hares.
  12. # You specify what group/resource and system you want the status for, and
  13. # the plugin returns a status code based on the output of either hagrp or
  14. # hares.
  15. #
  16. # Normal hagrp/hares status codes are ONLINE and OFFLINE depending on where the
  17. # cluster service currently lives. I have added an option, -n, which makes
  18. # the expected state to be OFFLINE rather than ONLINE so you can run the
  19. # plugin on both sides of the cluster and will receive critical alerts when
  20. # the cluster fails over i.e. a proper failover will make the standby node
  21. # go from OFFLINE to ONLINE for the group, so an ONLINE status should alert
  22. # you! (You do want to know when the cluster fails over, right? :))
  23. #
  24. # Output:
  25. #
  26. # This plugin returns OK when hagrp/hares -state <grp> -sys <system> returns
  27. # ONLINE (or OFFLINE if -n is specified). Any other hagrp/hares string returns
  28. # CRITICAL... Would a WARNING ever be justified??? UNKNOWN is returned if
  29. # hagrp/hares cannot run for some reason.
  30. #
  31. # Examples:
  32. #
  33. # Make sure group oracle is ONLINE on server dbserver1:
  34. # check_vcs -g oracle -s dbserver1
  35. #
  36. # Make sure group oracle is OFFLINE on server dbserver2:
  37. # check_vcs -g oracle -s dbserver2 -n
  38. #
  39. # Make sure resource oraip is ONLINE on server dbserver1:
  40. # check_vcs -r oraip -s dbserver1
  41. #
  42. # Make sure resource oraip is OFFLINE on server dbserver2:
  43. # check_vcs -r oraip -s dbserver2 -n
  44. #
  45. BEGIN {
  46. if ($0 =~ s/^(.*?)[\/\\]([^\/\\]+)$//) {
  47. $prog_dir = $1;
  48. $prog_name = $2;
  49. }
  50. }
  51. require 5.004;
  52. use lib $main::prog_dir;
  53. use utils qw($TIMEOUT %ERRORS &print_revision &support);
  54. use Getopt::Long;
  55. sub print_usage ();
  56. sub print_version ();
  57. sub print_help ();
  58. # Initialize strings
  59. $vcs_bin = '/opt/VRTSvcs/bin';
  60. $vcs_command = '';
  61. $vcs_arg = '';
  62. $vcs_group = '';
  63. $vcs_resource = '';
  64. $vcs_system = '';
  65. $vcs_negate = '';
  66. $vcs_result = '';
  67. $vcs_expected_result = 'ONLINE';
  68. $plugin_revision = '$Revision: 33 $ ';
  69. # Grab options from command line
  70. GetOptions
  71. ("g|group:s" => \$vcs_group,
  72. "r|resouce:s" => \$vcs_resource,
  73. "s|system=s" => \$vcs_system,
  74. "n|negate" => \$vcs_negate,
  75. "v|version" => \$version,
  76. "h|help" => \$help);
  77. (!$version) || print_version ();
  78. (!$help) || print_help ();
  79. (!$vcs_negate) || ($vcs_expected_result = 'OFFLINE');
  80. # Make sure group and resource is not specified
  81. !($vcs_group && $vcs_resource) || usage("Please specify either a group or a resource, but not both.\n");
  82. # Make sure group or resource is specified
  83. ($vcs_group || $vcs_resource) || usage("HA group or resource not specified.\n");
  84. # Make sure system is specified
  85. ($vcs_system) || usage("HA system not specified.\n");
  86. # Specify proper command
  87. if ($vcs_group) {
  88. $vcs_command = 'hagrp';
  89. $vcs_arg = $vcs_group;
  90. } else {
  91. $vcs_command = 'hares';
  92. $vcs_arg = $vcs_resource;
  93. }
  94. # Run command and save output
  95. $vcs_result = `$vcs_bin/$vcs_command -state $vcs_arg -sys $vcs_system`;
  96. chomp ($vcs_result);
  97. # If empty result, return UNKNOWN
  98. if (!$vcs_result) {
  99. print "UNKNOWN: Problem running $vcs_command...\n";
  100. exit $ERRORS{'UNKNOWN'};
  101. }
  102. # If result is expected, return OK
  103. # If result is not expected, return CRITICAL
  104. if ($vcs_result eq $vcs_expected_result) {
  105. print "OK: $vcs_command $vcs_arg is $vcs_result\n";
  106. exit $ERRORS{'OK'};
  107. } else {
  108. print "CRITICAL: $vcs_command $vcs_arg is $vcs_result\n";
  109. exit $ERRORS{'CRITICAL'};
  110. }
  111. #
  112. # Subroutines
  113. #
  114. sub usage () {
  115. print @_;
  116. print_usage();
  117. exit $ERRORS{'OK'};
  118. }
  119. sub print_usage () {
  120. print "\nUsage: $prog_name { -g <vcs_group> | -r <vcs_resource> } -s <vcs_system> [-n]\n";
  121. print "Usage: $prog_name [ -v | --version ]\n";
  122. print "Usage: $prog_name [ -h | --help ]\n";
  123. }
  124. sub print_version () {
  125. print_revision($prog_name, $plugin_revision);
  126. exit $ERRORS{'OK'};
  127. }
  128. sub print_help () {
  129. print_revision($prog_name, $plugin_revision);
  130. print "\n";
  131. print "Validate output from hagrp/hares command.\n";
  132. print "\n";
  133. print_usage();
  134. print "\n";
  135. print "-g, --group=<vcs_group>\n";
  136. print " The HA group to be validated\n";
  137. print "-r, --resource=<vcs_resource>\n";
  138. print " The HA resource to be validated\n";
  139. print "-s, --system=<vcs_system>\n";
  140. print " The HA system where the group/resource lives\n";
  141. print "-n, --negate=<negate>\n";
  142. print " Set expected result to OFFLINE instead of ONLINE\n";
  143. print "\n";
  144. support();
  145. exit $ERRORS{'OK'};
  146. }