3 # check_rpc plugin for monitoring
6 # check_rpc host service
8 # Check if an rpc service is registered and running
9 # using rpcinfo - $proto $host $prognum 2>&1 |";
11 # Use these hosts.cfg entries as examples
13 # command[check_nfs]=/some/path/libexec/check_rpc $HOSTADDRESS$ nfs
14 # service[check_nfs]=NFS;24x7;3;5;5;unix-admin;60;24x7;1;1;1;;check_rpc
16 # initial version: 3 May 2000 by Truongchinh Nguyen and Karl DeBisschop
17 # Modified May 2002 Subhendu Ghosh - support for ePN and patches
19 # Copyright Notice: GPL
24 use lib
"$FindBin::Bin";
25 use utils
qw($TIMEOUT %ERRORS &print_revision &support);
26 use vars qw($PROGNAME);
27 my ($verbose,@proto,%prognum,$host,$response,$prognum,$port,$cmd,$progver,$state);
28 my ($array_ref,$test,$element,@progkeys,$proto,$a,$b);
29 my ($opt_V,$opt_h,$opt_C,$opt_p,$opt_H,$opt_c,$opt_u,$opt_t);
30 my ($line, @progvers, $response2,$response3);
31 $opt_V = $opt_h = $opt_C = $opt_p = $opt_H = $opt_u = $opt_t ='';
33 $progver = $response=$response2= $response3 ='';
35 $PROGNAME = "check_rpc";
40 $ENV{'PATH'}='@TRUSTED_PATH@';
45 #Initialise protocol for each progname number
46 # 'u' for UDP, 't' for TCP
52 Getopt::Long::Configure('bundling');
54 "V" => \$opt_V, "version" => \$opt_V,
55 "h" => \$opt_h, "help" => \$opt_h,
56 "C=s" => \$opt_C, "command=s" => \$opt_C,
57 "p=i" => \$opt_p, "port=i" => \$opt_p,
58 "H=s" => \$opt_H, "hostname=s" => \$opt_H,
59 "c=s" => \$opt_c, "progver=s" => \$opt_c,
60 "v+" => \$verbose, "verbose+" => \$verbose,
61 "u" => \$opt_u, "udp" => \$opt_u,
62 "t" => \$opt_t, "tcp" => \$opt_t
65 # -h means display verbose help screen
66 if ($opt_h) { print_help(); exit $ERRORS{'UNKNOWN'}; }
68 # -V means display version number
70 print_revision($PROGNAME,'@NP_VERSION@');
71 exit $ERRORS{'UNKNOWN'};
74 # Hash containing all RPC program names and numbers
75 # Add to the hash if support for new RPC program is required
78 "portmapper" => 100000 ,
85 "perfmeter" => 100001 ,
86 "rstat_svc" => 100001 ,
95 "showmount" => 100005 ,
99 "shutdown" => 100008 ,
100 "yppasswdd" => 100009 ,
101 "yppasswd" => 100009 ,
102 "etherstatd" => 100010 ,
103 "etherstat" => 100010 ,
104 "rquotad" => 100011 ,
105 "rquotaprog" => 100011 ,
110 "3270_mapper" => 100013 ,
111 "rje_mapper" => 100014 ,
112 "selection_svc" => 100015 ,
113 "selnsvc" => 100015 ,
114 "database_svc" => 100016 ,
119 "llockmgr" => 100020 ,
120 "nlockmgr" => 100021 ,
121 "x25_inr" => 100022 ,
122 "statmon" => 100023 ,
124 "bootparam" => 100026 ,
125 "ypupdated" => 100028 ,
126 "ypupdate" => 100028 ,
127 "keyserv" => 100029 ,
128 "keyserver" => 100029 ,
129 "sunlink_mapper" => 100033 ,
132 "nsemntd" => 100039 ,
133 "showfhd" => 100043 ,
136 "rpc.ioadmd" => 100055 ,
137 "NETlicense" => 100062 ,
138 "sunisamd" => 100065 ,
139 "debug_svc" => 100066 ,
142 "rpc.ypxfrd" => 100069 ,
143 "bugtraqd" => 100071 ,
146 "na.event" => 100101 ,
148 "na.logger" => 100102 ,
150 "na.sync" => 100104 ,
151 "hostperf" => 100107 ,
152 "na.hostperf" => 100107 ,
153 "activity" => 100109 ,
154 "na.activity" => 100109 ,
155 "hostmem" => 100112 ,
156 "na.hostmem" => 100112 ,
158 "na.sample" => 100113 ,
162 "na.ping" => 100115 ,
164 "na.rpcnfs" => 100116 ,
166 "na.hostif" => 100117 ,
167 "etherif" => 100118 ,
168 "na.etherif" => 100118 ,
169 "iproutes" => 100120 ,
170 "na.iproutes" => 100120 ,
172 "na.layers" => 100121 ,
174 "na.snmp" => 100122 ,
175 "snmp-cmc" => 100122 ,
176 "snmp-synoptics" => 100122 ,
177 "snmp-unisys" => 100122 ,
178 "snmp-utk" => 100122 ,
179 "traffic" => 100123 ,
180 "na.traffic" => 100123 ,
181 "nfs_acl" => 100227 ,
182 "sadmind" => 100232 ,
184 "rpc.nisd" => 100300 ,
185 "nispasswd" => 100303 ,
186 "rpc.nispasswdd" => 100303 ,
193 "bwnfsd" => 545580417 ,
194 "fypxfrd" => 600100069 ,
195 "freebsd-ypxfrd" => 600100069 ,
198 # -v means verbose, -v-v means verbose twice = print above hash
199 if (defined $verbose && ($verbose > 1) ){
201 print "Supported programs:\n";
202 print " name\t=>\tnumber\n";
203 print " ===============================\n";
204 foreach $key (sort keys %prognum) {
205 print " $key \t=>\t$prognum{$key} \n";
213 unless ($opt_H) { print_usage(); exit $ERRORS{'UNKNOWN'}; }
215 if (! utils::is_hostname($opt_H)){
216 print "$opt_H is not a valid host name\n";
218 exit $ERRORS{"UNKNOWN"};
223 if ($opt_t && $opt_u) {
224 print "Cannot define tcp AND udp\n";
226 exit $ERRORS{'UNKNOWN'};
230 # -C means command name or number
231 $opt_C = shift unless ($opt_C);
232 unless ($opt_C) { print_usage(); exit -1; }
233 @progkeys = keys %prognum;
234 if ($opt_C =~ m/^([0-9]+)$/){
235 # $response = "RPC ok: program $opt_C (version ";
237 } elsif ( in( \@progkeys, $opt_C)) {
238 # $response = "RPC ok: $opt_C (version ";
239 $prognum = $prognum{$opt_C};
241 print "Program $opt_C is not defined\n";
242 exit $ERRORS{'UNKNOWN'};
245 # -p means port number
246 if($opt_p =~ /^([0-9]+)$/){
253 $proto = $proto[$prognum] if ($proto[$prognum]);
254 $proto = 't' if ($opt_t);
255 $proto = 'u' if ($opt_u);
258 # Just in case of problems, let's not hang the monitoring system
260 print ("ERROR: No response from RPC server (alarm)\n");
261 exit $ERRORS{"UNKNOWN"};
265 # -c is progver - if we need to check multiple specified versions.
266 if (defined $opt_c ) {
268 @progvers = split(/,/ ,$opt_c );
269 foreach $vers (sort @progvers) {
270 if($vers =~ /^([0-9]+)$/){
272 print "Checking $opt_C version $progver proto $proto\n" if $verbose;
275 print "Version $vers is not an integer\n" if $verbose;
284 ## translate proto for output
291 if ($state eq 'OK') {
292 print "$state: RPC program $opt_C".$response." $proto running\n";
295 print "$state: RPC program $opt_C".$response2." $proto is not running,".$response." $proto is running\n";
297 print "$state: RPC program $opt_C $response2 $proto is not running\n";
300 exit $ERRORS{$state};
303 ######## Subroutines ==========================
306 $cmd = "$utils::PATH_TO_RPCINFO $port -" . "$proto $host $prognum $progver 2>&1 |";
307 print "$cmd\n" if ($verbose);
308 open CMD, $cmd or die "Can't fork for rpcinfo: $!\n" ;
310 while ( $line = <CMD> ) {
311 printf "$line " if $verbose;
314 if ( $line =~ /[Pp]rogram $prognum version ([0-9]*) ready and waiting/ ) {
315 $response .= " version $1";
316 $state = 'OK' unless $state ne 'UNKNOWN';
317 print "1:$response \n" if $verbose;
320 if ( $line =~ /[Pp]rogram $prognum version ([0-9]*) is not available/ ) {
321 $response2 .= " version $1";
323 print "2:$response2 \n" if $verbose;
325 if ( $line =~ /[Pp]rogram $prognum is not available/ ) {
327 $response3 = "tcp" if $opt_t;
328 $response3 = "udp" if $opt_u;
330 print "3:$response3 \n" if $verbose;
338 print_revision($PROGNAME,'@NP_VERSION@');
339 print "Copyright (c) 2002 Karl DeBisschop/Truongchinh Nguyen/Subhendu Ghosh\n";
341 print "Check if a rpc service is registered and running using\n";
342 print " rpcinfo -H host -C rpc_command \n";
346 print " <host> The server providing the rpc service\n";
347 print " <rpc_command> The program name (or number).\n";
348 print " <program_version> The version you want to check for (one or more)\n";
349 print " Should prevent checks of unknown versions being syslogged\n";
350 print " e.g. 2,3,6 to check v2, v3, and v6\n";
351 print " [-u | -t] Test UDP or TCP\n";
352 print " [-v] Verbose \n";
353 print " [-v -v] Verbose - will print supported programs and numbers \n";
360 print " $PROGNAME -H host -C rpc_command [-p port] [-c program_version] [-u|-t] [-v]\n";
361 print " $PROGNAME [-h | --help]\n";
362 print " $PROGNAME [-V | --version]\n";
369 while ( $element = shift @{$array_ref} ) {
370 if ($test eq $element) {