summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xplugins-scripts/check_rpc.pl436
1 files changed, 271 insertions, 165 deletions
diff --git a/plugins-scripts/check_rpc.pl b/plugins-scripts/check_rpc.pl
index 2e25f41..623d6ab 100755
--- a/plugins-scripts/check_rpc.pl
+++ b/plugins-scripts/check_rpc.pl
@@ -1,4 +1,4 @@
1#! /usr/bin/perl -wT 1#! /usr/local/bin/perl -w
2# 2#
3# check_rpc plugin for nagios 3# check_rpc plugin for nagios
4# 4#
@@ -14,22 +14,26 @@
14# service[check_nfs]=NFS;24x7;3;5;5;unix-admin;60;24x7;1;1;1;;check_rpc 14# service[check_nfs]=NFS;24x7;3;5;5;unix-admin;60;24x7;1;1;1;;check_rpc
15# 15#
16# initial version: 3 May 2000 by Truongchinh Nguyen and Karl DeBisschop 16# initial version: 3 May 2000 by Truongchinh Nguyen and Karl DeBisschop
17# Modified May 2002 Subhendu Ghosh - support for ePN and patches
17# current status: $Revision$ 18# current status: $Revision$
18# 19#
19# Copyright Notice: GPL 20# Copyright Notice: GPL
21# $Id$
20# 22#
21 23
22
23use strict; 24use strict;
24use FindBin; 25use lib utils.pm;
25use lib "$FindBin::Bin";
26use utils qw($TIMEOUT %ERRORS &print_revision &support); 26use utils qw($TIMEOUT %ERRORS &print_revision &support);
27use vars qw($PROGNAME); 27use vars qw($PROGNAME);
28my ($verbose,@proto,%prognum,$host,$response,$prognum,$port,$cmd); 28my ($verbose,@proto,%prognum,$host,$response,$prognum,$port,$cmd,$progver,$state);
29my ($array_ref,$test,$element,@progkeys,$proto,$a,$b); 29my ($array_ref,$test,$element,@progkeys,$proto,$a,$b);
30my ($opt_V,$opt_h,$opt_C,$opt_p,$opt_H); 30my ($opt_V,$opt_h,$opt_C,$opt_p,$opt_H,$opt_c,$opt_u,$opt_t);
31$opt_V = $opt_h = $opt_C = $opt_p = $opt_H = ''; 31my ($line, @progvers, $response2,$response3);
32$opt_V = $opt_h = $opt_C = $opt_p = $opt_H = $opt_c = $opt_u = $opt_t ='';
33$state = 'OK';
34$progver = $response=$response2= $response3 ='';
32 35
36$PROGNAME = "check_rpc";
33sub print_help (); 37sub print_help ();
34sub print_usage (); 38sub print_usage ();
35sub in ($$); 39sub in ($$);
@@ -46,48 +50,196 @@ $proto[10007]='u';
46 50
47use Getopt::Long; 51use Getopt::Long;
48Getopt::Long::Configure('bundling'); 52Getopt::Long::Configure('bundling');
49GetOptions 53GetOptions(
50 ("V" => \$opt_V, "version" => \$opt_V, 54 "V" => \$opt_V, "version" => \$opt_V,
51 "h" => \$opt_h, "help" => \$opt_h, 55 "h" => \$opt_h, "help" => \$opt_h,
52 "C=s" => \$opt_C, "command=s" => \$opt_C, 56 "C=s" => \$opt_C, "command=s" => \$opt_C,
53 "p=i" => \$opt_p, "port=i" => \$opt_p, 57 "p=i" => \$opt_p, "port=i" => \$opt_p,
54 "H=s" => \$opt_H, "hostname=s" => \$opt_H); 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
63 );
55 64
56# -h means display verbose help screen 65# -h means display verbose help screen
57if ($opt_h) { print_help(); exit 0; } 66if ($opt_h) { print_help(); exit $ERRORS{'OK'}; }
58 67
59# -V means display version number 68# -V means display version number
60if ($opt_V) { print_revision($PROGNAME,'$Revision$ '); exit 0; } 69if ($opt_V) {
70 print_revision($PROGNAME,'$Revision$ ');
71 exit $ERRORS{'Ok'};
72}
73
74# Hash containing all RPC program names and numbers
75# Add to the hash if support for new RPC program is required
76
77%prognum = (
78 "portmapper" => 100000 ,
79 "portmap" => 100000 ,
80 "sunrpc" => 100000 ,
81 "rpcbind" => 100000 ,
82 "rstatd" => 100001 ,
83 "rstat" => 100001 ,
84 "rup" => 100001 ,
85 "perfmeter" => 100001 ,
86 "rstat_svc" => 100001 ,
87 "rusersd" => 100002 ,
88 "rusers" => 100002 ,
89 "nfs" => 100003 ,
90 "nfsprog" => 100003 ,
91 "ypserv" => 100004 ,
92 "ypprog" => 100004 ,
93 "mountd" => 100005 ,
94 "mount" => 100005 ,
95 "showmount" => 100005 ,
96 "ypbind" => 100007 ,
97 "walld" => 100008 ,
98 "rwall" => 100008 ,
99 "shutdown" => 100008 ,
100 "yppasswdd" => 100009 ,
101 "yppasswd" => 100009 ,
102 "etherstatd" => 100010 ,
103 "etherstat" => 100010 ,
104 "rquotad" => 100011 ,
105 "rquotaprog" => 100011 ,
106 "quota" => 100011 ,
107 "rquota" => 100011 ,
108 "sprayd" => 100012 ,
109 "spray" => 100012 ,
110 "3270_mapper" => 100013 ,
111 "rje_mapper" => 100014 ,
112 "selection_svc" => 100015 ,
113 "selnsvc" => 100015 ,
114 "database_svc" => 100016 ,
115 "rexd" => 100017 ,
116 "rex" => 100017 ,
117 "alis" => 100018 ,
118 "sched" => 100019 ,
119 "llockmgr" => 100020 ,
120 "nlockmgr" => 100021 ,
121 "x25_inr" => 100022 ,
122 "statmon" => 100023 ,
123 "status" => 100024 ,
124 "bootparam" => 100026 ,
125 "ypupdated" => 100028 ,
126 "ypupdate" => 100028 ,
127 "keyserv" => 100029 ,
128 "keyserver" => 100029 ,
129 "sunlink_mapper" => 100033 ,
130 "tfsd" => 100037 ,
131 "nsed" => 100038 ,
132 "nsemntd" => 100039 ,
133 "showfhd" => 100043 ,
134 "showfh" => 100043 ,
135 "ioadmd" => 100055 ,
136 "rpc.ioadmd" => 100055 ,
137 "NETlicense" => 100062 ,
138 "sunisamd" => 100065 ,
139 "debug_svc" => 100066 ,
140 "dbsrv" => 100066 ,
141 "ypxfrd" => 100069 ,
142 "rpc.ypxfrd" => 100069 ,
143 "bugtraqd" => 100071 ,
144 "kerbd" => 100078 ,
145 "event" => 100101 ,
146 "na.event" => 100101 ,
147 "logger" => 100102 ,
148 "na.logger" => 100102 ,
149 "sync" => 100104 ,
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 ,
157 "sample" => 100113 ,
158 "na.sample" => 100113 ,
159 "x25" => 100114 ,
160 "na.x25" => 100114 ,
161 "ping" => 100115 ,
162 "na.ping" => 100115 ,
163 "rpcnfs" => 100116 ,
164 "na.rpcnfs" => 100116 ,
165 "hostif" => 100117 ,
166 "na.hostif" => 100117 ,
167 "etherif" => 100118 ,
168 "na.etherif" => 100118 ,
169 "iproutes" => 100120 ,
170 "na.iproutes" => 100120 ,
171 "layers" => 100121 ,
172 "na.layers" => 100121 ,
173 "snmp" => 100122 ,
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 ,
183 "nisd" => 100300 ,
184 "rpc.nisd" => 100300 ,
185 "nispasswd" => 100303 ,
186 "rpc.nispasswdd" => 100303 ,
187 "ufsd" => 100233 ,
188 "ufsd" => 100233 ,
189 "pcnfsd" => 150001 ,
190 "pcnfs" => 150001 ,
191 "amd" => 300019 ,
192 "amq" => 300019 ,
193 "bwnfsd" => 545580417 ,
194 "fypxfrd" => 600100069 ,
195 "freebsd-ypxfrd" => 600100069 ,
196);
197
198# -v means verbose, -v-v means verbose twice = print above hash
199if (defined $verbose && ($verbose > 1) ){
200 my $key;
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";
206 }
207 print "\n\n";
208 print_usage();
209 exit $ERRORS{'OK'};
210}
61 211
62# -H means host name 212# -H means host name
63$opt_H = shift unless ($opt_H); 213unless ($opt_H) { print_usage(); exit $ERRORS{'UNKNOWN'}; }
64unless ($opt_H) { print_usage(); exit -1; } 214
65if($opt_H && $opt_H =~ m/^([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+|[a-zA-Z][-a-zA-Z0-9]+(\.[a-zA-Z][-a-zA-Z0-9]+)*)$/) { 215if (! utils::is_hostname($opt_H)){
66 $host = $1; 216 print "$opt_H is not a valid host name\n";
67} else { 217 print_usage();
68 print "$opt_H is not a valid host name\n"; 218 exit $ERRORS{"UNKNOWN"};
69 exit -1; 219}else{
220 $host = $opt_H;
70} 221}
71 222
72while (<DATA>) { 223if ($opt_t && $opt_u) {
73 ($a,$b) = split; 224 print "Cannot define tcp AND udp\n";
74 $prognum{$a} = $b; 225 print_usage();
226 exit $ERRORS{'UNKNOWN'};
75} 227}
76close DATA; 228
77 229
78# -C means command name or number 230# -C means command name or number
79$opt_C = shift unless ($opt_C); 231$opt_C = shift unless ($opt_C);
80unless ($opt_C) { print_usage(); exit -1; } 232unless ($opt_C) { print_usage(); exit -1; }
81@progkeys = keys %prognum; 233@progkeys = keys %prognum;
82if ($opt_C =~ m/^([0-9]+)$/){ 234if ($opt_C =~ m/^([0-9]+)$/){
83 $response = "RPC ok: program $opt_p (version "; 235# $response = "RPC ok: program $opt_C (version ";
84 $prognum = $1; 236 $prognum = $1;
85} elsif ( in( \@progkeys, $opt_C)) { 237} elsif ( in( \@progkeys, $opt_C)) {
86 $response = "RPC ok: $opt_C (version "; 238# $response = "RPC ok: $opt_C (version ";
87 $prognum = $prognum{$opt_C}; 239 $prognum = $prognum{$opt_C};
88} else { 240} else {
89 print "Program $opt_C is not defined\n"; 241 print "Program $opt_C is not defined\n";
90 exit -1; 242 exit $ERRORS{'UNKNOWN'};
91} 243}
92 244
93# -p means port number 245# -p means port number
@@ -99,42 +251,115 @@ if($opt_p =~ /^([0-9]+)$/){
99 251
100$proto = 'u'; 252$proto = 'u';
101$proto = $proto[$prognum] if ($proto[$prognum]); 253$proto = $proto[$prognum] if ($proto[$prognum]);
102$cmd = "/usr/sbin/rpcinfo $port -" . "$proto $host $prognum 2>&1 |"; 254$proto = 't' if ($opt_t);
103print "$cmd\n" if ($verbose); 255$proto = 'u' if ($opt_u);
104open CMD, $cmd; 256
105 257
106while ( <CMD> ) { 258# Just in case of problems, let's not hang Nagios
107 chomp; 259$SIG{'ALRM'} = sub {
108 if ( /program $prognum version ([0-9]*) ready and waiting/ ) { 260 print ("ERROR: No response from RPC server (alarm)\n");
109 $response .= "$1) is running"; 261 exit $ERRORS{"UNKNOWN"};
110 print "$response\n"; 262};
111 exit 0; 263alarm($TIMEOUT);
112 } 264
265# -c is progver - if we need to check multiple specified versions.
266if (defined $opt_c ) {
267 my $vers;
268 @progvers = split(/,/ ,$opt_c );
269 foreach $vers (sort @progvers) {
270 if($vers =~ /^([0-9]+)$/){
271 $progver = "$1";
272 print "Checking $opt_C version $progver proto $proto\n" if $verbose;
273 get_rpcinfo();
274 }else{
275 print "Version $vers is not an integer\n" if $verbose;
276 }
277
278 }
279}else{
280 get_rpcinfo();
281}
282
283
284## translate proto for output
285if ($proto eq "u" ){
286 $proto = "udp";
287}else{
288 $proto = "tcp";
289}
290
291if ($state eq 'OK') {
292 print "$state: RPC program $opt_C".$response." $proto running\n";
293}else{
294 if($response){
295 print "$state: RPC program $opt_C".$response2." $proto is not running,".$response." $proto is running\n";
296 }else{
297 print "$state: RPC program $opt_C $response2 $proto is not running\n";
298 }
113} 299}
300exit $ERRORS{$state};
114 301
115print "RPC CRITICAL: Program $opt_C not registered\n";
116exit 2;
117 302
303######## Subroutines ==========================
304
305sub get_rpcinfo {
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" ;
309
310 while ( $line = <CMD> ) {
311 printf "$line " if $verbose;
312 chomp $line;
313
314 if ( $line =~ /program $prognum version ([0-9]*) ready and waiting/ ) {
315 $response .= " version $1";
316 $state = 'OK' unless $state ne 'OK';
317 print "1:$response \n" if $verbose;
318 }
319
320 if ( $line =~ /program $prognum version ([0-9]*) is not available/ ) {
321 $response2 .= " version $1";
322 $state = 'CRITICAL';
323 print "2:$response2 \n" if $verbose;
324 }
325 if ( $line =~ /program $prognum is not available/ ) {
326 $response3 = "";
327 $response3 = "tcp" if $opt_t;
328 $response3 = "udp" if $opt_u;
329 $state = 'CRITICAL';
330 print "3:$response3 \n" if $verbose;
331 }
332 }
333 close CMD;
334}
118 335
119 336
120sub print_help() { 337sub print_help() {
121 print_revision($PROGNAME,'$Revision$ '); 338 print_revision($PROGNAME,'$Revision$ ');
122 print "Copyright (c) 2000 Karl DeBisschop/Truongchinh Nguyen\n"; 339 print "Copyright (c) 2002 Karl DeBisschop/Truongchinh Nguyen/Subhendu Ghosh\n";
123 print "\n"; 340 print "\n";
124 print "Check if a rpc service is registered and running using\n"; 341 print "Check if a rpc service is registered and running using\n";
125 print " rpcinfo -<protocol> <host> <program number>\n"; 342 print " rpcinfo -H host -C rpc_command \n";
126 print "\n"; 343 print "\n";
127 print_usage(); 344 print_usage();
128 print "\n"; 345 print "\n";
129 print "<host> The server providing the rpc service\n"; 346 print " <host> The server providing the rpc service\n";
130 print "<program> The program name (or number).\n\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";
354 print "\n";
131 support(); 355 support();
132} 356}
133 357
134sub print_usage () { 358sub print_usage () {
135 print "$PROGNAME -H host -C rpc_command [-p port]\n"; 359 print "Usage: \n";
136 print "$PROGNAME [-h | --help]\n"; 360 print " $PROGNAME -H host -C rpc_command [-p port] [-c program_version] [-u|-t] [-v]\n";
137 print "$PROGNAME [-V | --version]\n"; 361 print " $PROGNAME [-h | --help]\n";
362 print " $PROGNAME [-V | --version]\n";
138} 363}
139 364
140sub in ($$) { 365sub in ($$) {
@@ -149,122 +374,3 @@ sub in ($$) {
149 return 0; 374 return 0;
150} 375}
151 376
152__DATA__
153portmapper 100000
154portmap 100000
155sunrpc 100000
156rpcbind 100000
157rstatd 100001
158rstat 100001
159rup 100001
160perfmeter 100001
161rstat_svc 100001
162rusersd 100002
163rusers 100002
164nfs 100003
165nfsprog 100003
166ypserv 100004
167ypprog 100004
168mountd 100005
169mount 100005
170showmount 100005
171ypbind 100007
172walld 100008
173rwall 100008
174shutdown 100008
175yppasswdd 100009
176yppasswd 100009
177etherstatd 100010
178etherstat 100010
179rquotad 100011
180rquotaprog 100011
181quota 100011
182rquota 100011
183sprayd 100012
184spray 100012
1853270_mapper 100013
186rje_mapper 100014
187selection_svc 100015
188selnsvc 100015
189database_svc 100016
190rexd 100017
191rex 100017
192alis 100018
193sched 100019
194llockmgr 100020
195nlockmgr 100021
196x25_inr 100022
197statmon 100023
198status 100024
199bootparam 100026
200ypupdated 100028
201ypupdate 100028
202keyserv 100029
203keyserver 100029
204sunlink_mapper 100033
205tfsd 100037
206nsed 100038
207nsemntd 100039
208showfhd 100043
209showfh 100043
210ioadmd 100055
211rpc.ioadmd 100055
212NETlicense 100062
213sunisamd 100065
214debug_svc 100066
215dbsrv 100066
216ypxfrd 100069
217rpc.ypxfrd 100069
218bugtraqd 100071
219kerbd 100078
220event 100101
221na.event 100101
222logger 100102
223na.logger 100102
224sync 100104
225na.sync 100104
226hostperf 100107
227na.hostperf 100107
228activity 100109
229na.activity 100109
230hostmem 100112
231na.hostmem 100112
232sample 100113
233na.sample 100113
234x25 100114
235na.x25 100114
236ping 100115
237na.ping 100115
238rpcnfs 100116
239na.rpcnfs 100116
240hostif 100117
241na.hostif 100117
242etherif 100118
243na.etherif 100118
244iproutes 100120
245na.iproutes 100120
246layers 100121
247na.layers 100121
248snmp 100122
249na.snmp 100122
250snmp-cmc 100122
251snmp-synoptics 100122
252snmp-unisys 100122
253snmp-utk 100122
254traffic 100123
255na.traffic 100123
256nfs_acl 100227
257sadmind 100232
258nisd 100300
259rpc.nisd 100300
260nispasswd 100303
261rpc.nispasswdd 100303
262ufsd 100233
263ufsd 100233
264pcnfsd 150001
265pcnfs 150001
266amd 300019
267amq 300019
268bwnfsd 545580417
269fypxfrd 600100069
270freebsd-ypxfrd 600100069