4
0

check_rpc.pl 5.4 KB

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