summaryrefslogtreecommitdiffstats
path: root/contrib/check_vcs.pl
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/check_vcs.pl')
-rw-r--r--contrib/check_vcs.pl165
1 files changed, 165 insertions, 0 deletions
diff --git a/contrib/check_vcs.pl b/contrib/check_vcs.pl
new file mode 100644
index 0000000..7ee0072
--- /dev/null
+++ b/contrib/check_vcs.pl
@@ -0,0 +1,165 @@
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
46
47BEGIN {
48 if ($0 =~ s/^(.*?)[\/\\]([^\/\\]+)$//) {
49 $prog_dir = $1;
50 $prog_name = $2;
51 }
52}
53
54require 5.004;
55
56use lib $main::prog_dir;
57use utils qw($TIMEOUT %ERRORS &print_revision &support);
58use Getopt::Long;
59
60sub print_usage ();
61sub print_version ();
62sub print_help ();
63
64 # Initialize strings
65 $vcs_bin = '/opt/VRTSvcs/bin';
66 $vcs_command = '';
67 $vcs_arg = '';
68 $vcs_group = '';
69 $vcs_resource = '';
70 $vcs_system = '';
71 $vcs_negate = '';
72 $vcs_result = '';
73 $vcs_expected_result = 'ONLINE';
74 $plugin_revision = '$Revision$ ';
75
76 # Grab options from command line
77 GetOptions
78 ("g|group:s" => \$vcs_group,
79 "r|resouce:s" => \$vcs_resource,
80 "s|system=s" => \$vcs_system,
81 "n|negate" => \$vcs_negate,
82 "v|version" => \$version,
83 "h|help" => \$help);
84
85 (!$version) || print_version ();
86 (!$help) || print_help ();
87 (!$vcs_negate) || ($vcs_expected_result = 'OFFLINE');
88
89 # Make sure group and resource is not specified
90 !($vcs_group && $vcs_resource) || usage("Please specify either a group or a resource, but not both.\n");
91 # Make sure group or resource is specified
92 ($vcs_group || $vcs_resource) || usage("HA group or resource not specified.\n");
93 # Make sure system is specified
94 ($vcs_system) || usage("HA system not specified.\n");
95
96 # Specify proper command
97 if ($vcs_group) {
98 $vcs_command = 'hagrp';
99 $vcs_arg = $vcs_group;
100 } else {
101 $vcs_command = 'hares';
102 $vcs_arg = $vcs_resource;
103 }
104
105 # Run command and save output
106 $vcs_result = `$vcs_bin/$vcs_command -state $vcs_arg -sys $vcs_system`;
107 chomp ($vcs_result);
108
109 # If empty result, return UNKNOWN
110 if (!$vcs_result) {
111 print "UNKNOWN: Problem running $vcs_command...\n";
112 exit $ERRORS{'UNKNOWN'};
113 }
114
115 # If result is expected, return OK
116 # If result is not expected, return CRITICAL
117 if ($vcs_result eq $vcs_expected_result) {
118 print "OK: $vcs_command $vcs_arg is $vcs_result\n";
119 exit $ERRORS{'OK'};
120 } else {
121 print "CRITICAL: $vcs_command $vcs_arg is $vcs_result\n";
122 exit $ERRORS{'CRITICAL'};
123 }
124
125
126#
127# Subroutines
128#
129
130sub usage () {
131 print @_;
132 print_usage();
133 exit $ERRORS{'OK'};
134}
135
136sub print_usage () {
137 print "\nUsage: $prog_name { -g <vcs_group> | -r <vcs_resource> } -s <vcs_system> [-n]\n";
138 print "Usage: $prog_name [ -v | --version ]\n";
139 print "Usage: $prog_name [ -h | --help ]\n";
140}
141
142sub print_version () {
143 print_revision($prog_name, $plugin_revision);
144 exit $ERRORS{'OK'};
145}
146
147sub print_help () {
148 print_revision($prog_name, $plugin_revision);
149 print "\n";
150 print "Validate output from hagrp/hares command.\n";
151 print "\n";
152 print_usage();
153 print "\n";
154 print "-g, --group=<vcs_group>\n";
155 print " The HA group to be validated\n";
156 print "-r, --resource=<vcs_resource>\n";
157 print " The HA resource to be validated\n";
158 print "-s, --system=<vcs_system>\n";
159 print " The HA system where the group/resource lives\n";
160 print "-n, --negate=<negate>\n";
161 print " Set expected result to OFFLINE instead of ONLINE\n";
162 print "\n";
163 support();
164 exit $ERRORS{'OK'};
165}