check_rpc.pl 5.3 KB

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