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