check_flexlm.pl 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  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 utils qw(%ERRORS &print_revision &support &usage);
  38. $PROGNAME="check_flexlm";
  39. sub print_help ();
  40. sub print_usage ();
  41. $ENV{'PATH'}='@TRUSTED_PATH@';
  42. $ENV{'BASH_ENV'}='';
  43. $ENV{'ENV'}='';
  44. Getopt::Long::Configure('bundling');
  45. GetOptions
  46. ("V" => \$opt_V, "version" => \$opt_V,
  47. "h" => \$opt_h, "help" => \$opt_h,
  48. "v" => \$verbose, "verbose" => \$verbose,
  49. "F=s" => \$opt_F, "filename=s" => \$opt_F,
  50. "t=i" => \$opt_t, "timeout=i" => \$opt_t);
  51. if ($opt_V) {
  52. print_revision($PROGNAME,'@NP_VERSION@');
  53. exit $ERRORS{'OK'};
  54. }
  55. unless (defined $opt_t) {
  56. $opt_t = $utils::TIMEOUT ; # default timeout
  57. }
  58. if ($opt_h) {print_help(); exit $ERRORS{'OK'};}
  59. unless (defined $opt_F) {
  60. print "Missing license.dat file\n";
  61. print_usage();
  62. exit $ERRORS{'UNKNOWN'};
  63. }
  64. # Just in case of problems, let's not hang Nagios
  65. $SIG{'ALRM'} = sub {
  66. print "Timeout: No Answer from Client\n";
  67. exit $ERRORS{'UNKNOWN'};
  68. };
  69. alarm($opt_t);
  70. my $lmstat = $utils::PATH_TO_LMSTAT ;
  71. unless (-x $lmstat ) {
  72. print "Cannot find \"lmstat\"\n";
  73. exit $ERRORS{'UNKNOWN'};
  74. }
  75. ($opt_F) || ($opt_F = shift) || usage("License file not specified\n");
  76. my $licfile = $1 if ($opt_F =~ /^(.*)$/);
  77. ($licfile) || usage("Invalid filename: $opt_F\n");
  78. print "$licfile\n" if $verbose;
  79. if ( ! open(CMD,"$lmstat -c $licfile |") ) {
  80. print "ERROR: Could not open \"$lmstat -c $licfile\" ($!)\n";
  81. exit exit $ERRORS{'UNKNOWN'};
  82. }
  83. my $serverup = 0;
  84. my @upsrv;
  85. my @downsrv; # list of servers up and down
  86. #my ($ls1,$ls2,$ls3,$lf1,$lf2,$lf3,$servers);
  87. # key off of the term "license server" and
  88. # grab the status. Keep going until "Vendor" is found
  89. #
  90. #
  91. # Collect list of license servers by their status
  92. # Vendor daemon status is ignored for the moment.
  93. while ( <CMD> ) {
  94. next if (/^lmstat/); # ignore 1st line - copyright
  95. next if (/^Flexible/); # ignore 2nd line - timestamp
  96. (/^Vendor/) && last; # ignore Vendor daemon status
  97. print $_ if $verbose;
  98. if ($_ =~ /license server /) { # matched 1 (of possibly 3) license server
  99. s/^\s*//; #some servers start at col 1, other have whitespace
  100. # strip staring whitespace if any
  101. if ( $_ =~ /UP/) {
  102. $_ =~ /^(.*):/ ;
  103. push(@upsrv, $1);
  104. print "up:$1:\n" if $verbose;
  105. } else {
  106. $_ =~ /^(.*):/;
  107. push(@downsrv, $1);
  108. print "down:$1:\n" if $verbose;
  109. }
  110. }
  111. # if ( /^License server status: [0-9]*@([-0-9a-zA-Z_]*),[0-9]*@([-0-9a-zA-Z_]*),[0-9]*@([-0-9a-zA-Z_]*)/ ) {
  112. # $ls1 = $1;
  113. # $ls2 = $2;
  114. # $ls3 = $3;
  115. # $lf1 = $lf2 = $lf3 = 0;
  116. # $servers = 3;
  117. # } elsif ( /^License server status: [0-9]*@([-0-9a-zA-Z_]*)/ ) {
  118. # $ls1 = $1;
  119. # $ls2 = $ls3 = "";
  120. # $lf1 = $lf2 = $lf3 = 0;
  121. # $servers = 1;
  122. # } elsif ( / *$ls1: license server UP/ ) {
  123. # print "$ls1 UP, ";
  124. # $lf1 = 1
  125. # } elsif ( / *$ls2: license server UP/ ) {
  126. # print "$ls2 UP, ";
  127. # $lf2 = 1
  128. # } elsif ( / *$ls3: license server UP/ ) {
  129. # print "$ls3 UP, ";
  130. # $lf3 = 1
  131. # } elsif ( / *([^:]*: UP .*)/ ) {
  132. # print " license server for $1\n";
  133. # $serverup = 1;
  134. # }
  135. }
  136. #if ( $serverup == 0 ) {
  137. # print " license server not running\n";
  138. # exit 2;
  139. #}
  140. close CMD;
  141. if ($verbose) {
  142. print "License Servers running: ".scalar(@upsrv) ."\n";
  143. foreach my $upserver (@upsrv) {
  144. print "$upserver\n";
  145. }
  146. print "License servers not running: ".scalar(@downsrv)."\n";
  147. foreach my $downserver (@downsrv) {
  148. print "$downserver\n";
  149. }
  150. }
  151. #
  152. # print list of servers which are up.
  153. #
  154. if (scalar(@upsrv) > 0) {
  155. print "License Servers running:";
  156. foreach my $upserver (@upsrv) {
  157. print "$upserver,";
  158. }
  159. }
  160. #
  161. # Ditto for those which are down.
  162. #
  163. if (scalar(@downsrv) > 0) {
  164. print "License servers NOT running:";
  165. foreach my $downserver (@downsrv) {
  166. print "$downserver,";
  167. }
  168. }
  169. # perfdata
  170. print "\n|flexlm::up:".scalar(@upsrv).";down:".scalar(@downsrv)."\n";
  171. exit $ERRORS{'OK'} if ( scalar(@downsrv) == 0 );
  172. exit $ERRORS{'WARNING'} if ( (scalar(@upsrv) > 0) && (scalar(@downsrv) > 0));
  173. #exit $ERRORS{'OK'} if ( $servers == $lf1 + $lf2 + $lf3 );
  174. #exit $ERRORS{'WARNING'} if ( $servers == 3 && $lf1 + $lf2 + $lf3 == 2 );
  175. exit $ERRORS{'CRITICAL'};
  176. sub print_usage () {
  177. print "Usage:
  178. $PROGNAME -F <filename> [-v] [-t] [-V] [-h]
  179. $PROGNAME --help
  180. $PROGNAME --version
  181. ";
  182. }
  183. sub print_help () {
  184. print_revision($PROGNAME,'@NP_VERSION@');
  185. print "Copyright (c) 2000 Ernst-Dieter Martin/Karl DeBisschop
  186. Check available flexlm license managers
  187. ";
  188. print_usage();
  189. print "
  190. -F, --filename=FILE
  191. Name of license file (usually \"license.dat\")
  192. -v, --verbose
  193. Print some extra debugging information (not advised for normal operation)
  194. -t, --timeout
  195. Plugin time out in seconds (default = $utils::TIMEOUT )
  196. -V, --version
  197. Show version and license information
  198. -h, --help
  199. Show this help screen
  200. Flexlm license managers usually run as a single server or three servers and a
  201. quorum is needed. The plugin return OK if 1 (single) or 3 (triple) servers
  202. are running, CRITICAL if 1(single) or 3 (triple) servers are down, and WARNING
  203. if 1 or 2 of 3 servers are running\n
  204. ";
  205. support();
  206. }