Code

moved updated check_ifstatus to standard plugin
[nagiosplug.git] / plugins-scripts / check_rpc.pl
1 #! /usr/bin/perl -wT
2 #
3 # check_rpc plugin for nagios
4 #
5 # usage:
6 #    check_rpc host service
7 #
8 # Check if an rpc serice is registered and running
9 # using rpcinfo - $proto $host $prognum 2>&1 |";
10 #
11 # Use these hosts.cfg entries as examples
12 #
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
15 #
16 # initial version: 3 May 2000 by Truongchinh Nguyen and Karl DeBisschop
17 # current status: $Revision$
18 #
19 # Copyright Notice: GPL
20 #
23 use strict;
24 use FindBin;
25 use lib "$FindBin::Bin";
26 use utils qw($TIMEOUT %ERRORS &print_revision &support);
27 use vars qw($PROGNAME);
28 my ($verbose,@proto,%prognum,$host,$response,$prognum,$port,$cmd);
29 my ($array_ref,$test,$element,@progkeys,$proto,$a,$b);
30 my ($opt_V,$opt_h,$opt_C,$opt_p,$opt_H);
31 $opt_V = $opt_h = $opt_C = $opt_p = $opt_H = '';
33 sub print_help ();
34 sub print_usage ();
35 sub in ($$);
37 $ENV{'BASH_ENV'}=''; 
38 $ENV{'ENV'}='';
39 $ENV{'PATH'}='';
41 #Initialise protocol for each progname number
42 # 'u' for UDP, 't' for TCP 
43 $proto[10003]='u';
44 $proto[10004]='u';
45 $proto[10007]='u';
47 use Getopt::Long;
48 Getopt::Long::Configure('bundling');
49 GetOptions
50                 ("V"   => \$opt_V, "version"    => \$opt_V,
51            "h"   => \$opt_h, "help"       => \$opt_h,
52            "C=s" => \$opt_C, "command=s"  => \$opt_C,
53            "p=i" => \$opt_p, "port=i"     => \$opt_p,
54            "H=s" => \$opt_H, "hostname=s" => \$opt_H);
56 # -h means display verbose help screen
57 if ($opt_h) { print_help(); exit 0; }
59 # -V means display version number
60 if ($opt_V) { print_revision($PROGNAME,'$Revision$ '); exit 0; }
62 # -H means host name
63 $opt_H = shift unless ($opt_H);
64 unless ($opt_H) { print_usage(); exit -1; }
65 if($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]+)*)$/) {
66     $host = $1;
67 } else {
68     print "$opt_H is not a valid host name\n";
69     exit -1;
70 }
72 while (<DATA>) {
73         ($a,$b) = split;
74         $prognum{$a} = $b;
75 }
76 close DATA;
78 # -C means command name or number
79 $opt_C = shift unless ($opt_C);
80 unless ($opt_C) { print_usage(); exit -1; }
81 @progkeys = keys %prognum;
82 if ($opt_C =~ m/^([0-9]+)$/){
83     $response = "RPC ok: program $opt_p (version ";
84     $prognum = $1;
85 } elsif ( in( \@progkeys, $opt_C)) {
86     $response = "RPC ok: $opt_C (version ";
87     $prognum = $prognum{$opt_C};
88 } else {
89     print "Program $opt_C is not defined\n";
90     exit -1;
91 }
93 # -p means port number
94 if($opt_p =~ /^([0-9]+)$/){
95     $port = "-n $1";
96 } else {
97     $port = "";
98 }
100 $proto = 'u';
101 $proto = $proto[$prognum] if ($proto[$prognum]);
102 $cmd = "/usr/sbin/rpcinfo $port -" . "$proto $host $prognum 2>&1 |";
103 print "$cmd\n" if ($verbose);
104 open CMD, $cmd;
106 while ( <CMD> ) {
107     chomp;
108     if ( /program $prognum version ([0-9]*) ready and waiting/ ) {
109         $response .= "$1) is running";
110         print "$response\n";
111         exit 0;
112     }
115 print "RPC CRITICAL: Program $opt_C not registered\n";
116 exit 2;
120 sub print_help() {
121         print_revision($PROGNAME,'$Revision$ ');
122         print "Copyright (c) 2000 Karl DeBisschop/Truongchinh Nguyen\n";
123         print "\n";
124         print "Check if a rpc service is registered and running using\n";
125         print "      rpcinfo -<protocol> <host> <program number>\n";
126         print "\n";
127         print_usage();
128         print "\n";
129         print "<host>    The server providing the rpc service\n";
130         print "<program> The program name (or number).\n\n";
131         support();
134 sub print_usage () {
135         print "$PROGNAME -H host -C rpc_command [-p port]\n";
136         print "$PROGNAME [-h | --help]\n";
137         print "$PROGNAME [-V | --version]\n";
140 sub in ($$) {
141         $array_ref = shift;
142         $test = shift;
144         while ( $element = shift @{$array_ref} ) {
145                 if ($test eq $element) {
146             return 1;
147                 }
148         }
149         return 0;
152 __DATA__
153 portmapper 100000
154 portmap 100000
155 sunrpc 100000
156 rpcbind 100000
157 rstatd 100001
158 rstat 100001
159 rup 100001
160 perfmeter 100001
161 rstat_svc 100001
162 rusersd 100002
163 rusers 100002
164 nfs 100003
165 nfsprog 100003
166 ypserv 100004
167 ypprog 100004
168 mountd 100005
169 mount 100005
170 showmount 100005
171 ypbind 100007
172 walld 100008
173 rwall 100008
174 shutdown 100008
175 yppasswdd 100009
176 yppasswd 100009
177 etherstatd 100010
178 etherstat 100010
179 rquotad 100011
180 rquotaprog 100011
181 quota 100011
182 rquota 100011 
183 sprayd 100012
184 spray 100012
185 3270_mapper 100013
186 rje_mapper 100014
187 selection_svc 100015
188 selnsvc 100015
189 database_svc 100016
190 rexd 100017
191 rex 100017
192 alis 100018
193 sched 100019
194 llockmgr 100020
195 nlockmgr 100021
196 x25_inr 100022
197 statmon 100023
198 status 100024
199 bootparam 100026
200 ypupdated 100028
201 ypupdate 100028
202 keyserv 100029
203 keyserver 100029 
204 sunlink_mapper 100033
205 tfsd 100037
206 nsed 100038
207 nsemntd 100039
208 showfhd 100043
209 showfh 100043
210 ioadmd 100055
211 rpc.ioadmd 100055
212 NETlicense 100062
213 sunisamd 100065
214 debug_svc 100066
215 dbsrv 100066
216 ypxfrd 100069
217 rpc.ypxfrd 100069
218 bugtraqd 100071
219 kerbd 100078
220 event 100101
221 na.event 100101
222 logger 100102
223 na.logger 100102
224 sync 100104
225 na.sync 100104
226 hostperf 100107
227 na.hostperf 100107
228 activity 100109
229 na.activity 100109
230 hostmem 100112
231 na.hostmem 100112
232 sample 100113
233 na.sample 100113
234 x25 100114
235 na.x25 100114
236 ping 100115
237 na.ping 100115
238 rpcnfs 100116
239 na.rpcnfs 100116
240 hostif 100117
241 na.hostif 100117
242 etherif 100118
243 na.etherif 100118
244 iproutes 100120
245 na.iproutes 100120
246 layers 100121
247 na.layers 100121
248 snmp 100122
249 na.snmp 100122
250 snmp-cmc 100122
251 snmp-synoptics 100122
252 snmp-unisys 100122
253 snmp-utk 100122
254 traffic 100123
255 na.traffic 100123
256 nfs_acl 100227
257 sadmind 100232
258 nisd 100300
259 rpc.nisd 100300
260 nispasswd 100303
261 rpc.nispasswdd 100303
262 ufsd 100233
263 ufsd 100233
264 pcnfsd 150001
265 pcnfs 150001
266 amd 300019
267 amq 300019
268 bwnfsd 545580417
269 fypxfrd 600100069
270 freebsd-ypxfrd 600100069