check_flexlm.pl 6.2 KB

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