4
0

check_flexlm.pl 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. #!@PERL@ -w
  2. #
  3. # usage:
  4. # check_flexlm.pl license_file
  5. #
  6. # Check available flexlm license managers.
  7. # Use lmstat to check the status of the license server
  8. # described by the license file given as argument.
  9. # Check and interpret the output of lmstat
  10. # and create returncodes and output.
  11. #
  12. # Contrary to the nagios concept, this script takes
  13. # a file, not a hostname as an argument and returns
  14. # the status of hosts and services described in that
  15. # file. Use these hosts.cfg entries as an example
  16. #
  17. #host[anchor]=any host will do;some.address.com;;check-host-alive;3;120;24x7;1;1;1;
  18. #service[anchor]=yodel;24x7;3;5;5;unix-admin;60;24x7;1;1;1;;check_flexlm!/opt/lic/licfiles/yodel_lic
  19. #service[anchor]=yeehaw;24x7;3;5;5;unix-admin;60;24x7;1;1;1;;check_flexlm!/opt/lic/licfiles/yeehaw_lic
  20. #command[check_flexlm]=/some/path/libexec/check_flexlm.pl $ARG1$
  21. #
  22. # Notes:
  23. # - you need the lmstat utility which comes with flexlm.
  24. # - set the correct path in the variable $lmstat.
  25. #
  26. # initial version: 9-10-99 Ernst-Dieter Martin edmt@infineon.com
  27. #
  28. # License: GPL
  29. #
  30. # lmstat output patches from Steve Rigler/Cliff Rice 13-Apr-2002
  31. # srigler@marathonoil.com,cerice@marathonoil.com
  32. use strict;
  33. use Getopt::Long;
  34. use vars qw($opt_V $opt_h $opt_F $opt_t $verbose $PROGNAME);
  35. use FindBin;
  36. use lib "$FindBin::Bin";
  37. use lib '@libexecdir@';
  38. use utils qw(%ERRORS &print_revision &support &usage);
  39. $PROGNAME="check_flexlm";
  40. sub print_help ();
  41. sub print_usage ();
  42. $ENV{'PATH'}='@TRUSTED_PATH@';
  43. $ENV{'BASH_ENV'}='';
  44. $ENV{'ENV'}='';
  45. Getopt::Long::Configure('bundling');
  46. GetOptions
  47. ("V" => \$opt_V, "version" => \$opt_V,
  48. "h" => \$opt_h, "help" => \$opt_h,
  49. "v" => \$verbose, "verbose" => \$verbose,
  50. "F=s" => \$opt_F, "filename=s" => \$opt_F,
  51. "t=i" => \$opt_t, "timeout=i" => \$opt_t);
  52. if ($opt_V) {
  53. print_revision($PROGNAME,'@NP_VERSION@');
  54. exit $ERRORS{'OK'};
  55. }
  56. unless (defined $opt_t) {
  57. $opt_t = $utils::TIMEOUT ; # default timeout
  58. }
  59. if ($opt_h) {print_help(); exit $ERRORS{'OK'};}
  60. unless (defined $opt_F) {
  61. print "Missing license.dat file\n";
  62. print_usage();
  63. exit $ERRORS{'UNKNOWN'};
  64. }
  65. # Just in case of problems, let's not hang Nagios
  66. $SIG{'ALRM'} = sub {
  67. print "Timeout: No Answer from Client\n";
  68. exit $ERRORS{'UNKNOWN'};
  69. };
  70. alarm($opt_t);
  71. my $lmstat = $utils::PATH_TO_LMSTAT ;
  72. unless (-x $lmstat ) {
  73. print "Cannot find \"lmstat\"\n";
  74. exit $ERRORS{'UNKNOWN'};
  75. }
  76. ($opt_F) || ($opt_F = shift) || usage("License file not specified\n");
  77. my $licfile = $1 if ($opt_F =~ /^(.*)$/);
  78. ($licfile) || usage("Invalid filename: $opt_F\n");
  79. print "$licfile\n" if $verbose;
  80. if ( ! open(CMD,"$lmstat -c $licfile |") ) {
  81. print "ERROR: Could not open \"$lmstat -c $licfile\" ($!)\n";
  82. exit exit $ERRORS{'UNKNOWN'};
  83. }
  84. my $serverup = 0;
  85. my @upsrv;
  86. my @downsrv; # list of servers up and down
  87. #my ($ls1,$ls2,$ls3,$lf1,$lf2,$lf3,$servers);
  88. # key off of the term "license server" and
  89. # grab the status. Keep going until "Vendor" is found
  90. #
  91. #
  92. # Collect list of license servers by their status
  93. # Vendor daemon status is ignored for the moment.
  94. while ( <CMD> ) {
  95. next if (/^lmstat/); # ignore 1st line - copyright
  96. next if (/^Flexible/); # ignore 2nd line - timestamp
  97. (/^Vendor/) && last; # ignore Vendor daemon status
  98. print $_ if $verbose;
  99. if ($_ =~ /license server /) { # matched 1 (of possibly 3) license server
  100. s/^\s*//; #some servers start at col 1, other have whitespace
  101. # strip staring whitespace if any
  102. if ( $_ =~ /UP/) {
  103. $_ =~ /^(.*):/ ;
  104. push(@upsrv, $1);
  105. print "up:$1:\n" if $verbose;
  106. } else {
  107. $_ =~ /^(.*):/;
  108. push(@downsrv, $1);
  109. print "down:$1:\n" if $verbose;
  110. }
  111. }
  112. # if ( /^License server status: [0-9]*@([-0-9a-zA-Z_]*),[0-9]*@([-0-9a-zA-Z_]*),[0-9]*@([-0-9a-zA-Z_]*)/ ) {
  113. # $ls1 = $1;
  114. # $ls2 = $2;
  115. # $ls3 = $3;
  116. # $lf1 = $lf2 = $lf3 = 0;
  117. # $servers = 3;
  118. # } elsif ( /^License server status: [0-9]*@([-0-9a-zA-Z_]*)/ ) {
  119. # $ls1 = $1;
  120. # $ls2 = $ls3 = "";
  121. # $lf1 = $lf2 = $lf3 = 0;
  122. # $servers = 1;
  123. # } elsif ( / *$ls1: license server UP/ ) {
  124. # print "$ls1 UP, ";
  125. # $lf1 = 1
  126. # } elsif ( / *$ls2: license server UP/ ) {
  127. # print "$ls2 UP, ";
  128. # $lf2 = 1
  129. # } elsif ( / *$ls3: license server UP/ ) {
  130. # print "$ls3 UP, ";
  131. # $lf3 = 1
  132. # } elsif ( / *([^:]*: UP .*)/ ) {
  133. # print " license server for $1\n";
  134. # $serverup = 1;
  135. # }
  136. }
  137. #if ( $serverup == 0 ) {
  138. # print " license server not running\n";
  139. # exit 2;
  140. #}
  141. close CMD;
  142. if ($verbose) {
  143. print "License Servers running: ".scalar(@upsrv) ."\n";
  144. foreach my $upserver (@upsrv) {
  145. print "$upserver\n";
  146. }
  147. print "License servers not running: ".scalar(@downsrv)."\n";
  148. foreach my $downserver (@downsrv) {
  149. print "$downserver\n";
  150. }
  151. }
  152. #
  153. # print list of servers which are up.
  154. #
  155. if (scalar(@upsrv) > 0) {
  156. print "License Servers running:";
  157. foreach my $upserver (@upsrv) {
  158. print "$upserver,";
  159. }
  160. }
  161. #
  162. # Ditto for those which are down.
  163. #
  164. if (scalar(@downsrv) > 0) {
  165. print "License servers NOT running:";
  166. foreach my $downserver (@downsrv) {
  167. print "$downserver,";
  168. }
  169. }
  170. # perfdata
  171. print "\n|flexlm::up:".scalar(@upsrv).";down:".scalar(@downsrv)."\n";
  172. exit $ERRORS{'OK'} if ( scalar(@downsrv) == 0 );
  173. exit $ERRORS{'WARNING'} if ( (scalar(@upsrv) > 0) && (scalar(@downsrv) > 0));
  174. #exit $ERRORS{'OK'} if ( $servers == $lf1 + $lf2 + $lf3 );
  175. #exit $ERRORS{'WARNING'} if ( $servers == 3 && $lf1 + $lf2 + $lf3 == 2 );
  176. exit $ERRORS{'CRITICAL'};
  177. sub print_usage () {
  178. print "Usage:
  179. $PROGNAME -F <filename> [-v] [-t] [-V] [-h]
  180. $PROGNAME --help
  181. $PROGNAME --version
  182. ";
  183. }
  184. sub print_help () {
  185. print_revision($PROGNAME,'@NP_VERSION@');
  186. print "Copyright (c) 2000 Ernst-Dieter Martin/Karl DeBisschop
  187. Check available flexlm license managers
  188. ";
  189. print_usage();
  190. print "
  191. -F, --filename=FILE
  192. Name of license file (usually \"license.dat\")
  193. -v, --verbose
  194. Print some extra debugging information (not advised for normal operation)
  195. -t, --timeout
  196. Plugin time out in seconds (default = $utils::TIMEOUT )
  197. -V, --version
  198. Show version and license information
  199. -h, --help
  200. Show this help screen
  201. Flexlm license managers usually run as a single server or three servers and a
  202. quorum is needed. The plugin return OK if 1 (single) or 3 (triple) servers
  203. are running, CRITICAL if 1(single) or 3 (triple) servers are down, and WARNING
  204. if 1 or 2 of 3 servers are running\n
  205. ";
  206. support();
  207. }