check_flexlm.pl 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. #! /usr/bin/perl -wT
  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. # $Id$
  30. #
  31. use strict;
  32. use Getopt::Long;
  33. use vars qw($opt_V $opt_h $opt_F $verbose $PROGNAME);
  34. use FindBin ;
  35. use lib "$FindBin::Bin";
  36. use utils qw($TIMEOUT %ERRORS &print_revision &support &usage);
  37. sub print_help ();
  38. sub print_usage ();
  39. $ENV{'PATH'}='';
  40. $ENV{'BASH_ENV'}='';
  41. $ENV{'ENV'}='';
  42. Getopt::Long::Configure('bundling');
  43. GetOptions
  44. ("V" => \$opt_V, "version" => \$opt_V,
  45. "h" => \$opt_h, "help" => \$opt_h,
  46. "v" => \$verbose, "verbose" => \$verbose,
  47. "F=s" => \$opt_F, "filename=s" => \$opt_F);
  48. if ($opt_V) {
  49. print_revision($PROGNAME,'$Revision$');
  50. exit $ERRORS{'OK'};
  51. }
  52. if ($opt_h) {print_help(); exit $ERRORS{'OK'};}
  53. # Just in case of problems, let's not hang Nagios
  54. $SIG{'ALRM'} = sub {
  55. print "No Answer from Client\n";
  56. exit 2;
  57. };
  58. alarm($TIMEOUT);
  59. my $lmstat = "/opt/lic/sw/cadadm/default/bin/lmstat";
  60. ($opt_F) || ($opt_F = shift) || usage("License file not specified\n");
  61. my $licfile = $1 if ($opt_F =~ /^(.*)$/);
  62. ($licfile) || usage("Invalid filename: $opt_F\n");
  63. print "$licfile\n" if $verbose;
  64. open CMD,"$lmstat -c $licfile |";
  65. my $serverup = 0;
  66. my ($ls1,$ls2,$ls3,$lf1,$lf2,$lf3,$servers);
  67. while ( <CMD> ) {
  68. if ( /^License server status: [0-9]*@([-0-9a-zA-Z_]*),[0-9]*@([-0-9a-zA-Z_]*),[0-9]*@([-0-9a-zA-Z_]*)/ ) {
  69. $ls1 = $1;
  70. $ls2 = $2;
  71. $ls3 = $3;
  72. $lf1 = $lf2 = $lf3 = 0;
  73. $servers = 3;
  74. } elsif ( /^License server status: [0-9]*@([-0-9a-zA-Z_]*)/ ) {
  75. $ls1 = $1;
  76. $ls2 = $ls3 = "";
  77. $lf1 = $lf2 = $lf3 = 0;
  78. $servers = 1;
  79. } elsif ( / *$ls1: license server UP/ ) {
  80. print "$ls1 UP, ";
  81. $lf1 = 1
  82. } elsif ( / *$ls2: license server UP/ ) {
  83. print "$ls2 UP, ";
  84. $lf2 = 1
  85. } elsif ( / *$ls3: license server UP/ ) {
  86. print "$ls3 UP, ";
  87. $lf3 = 1
  88. } elsif ( / *([^:]*: UP .*)/ ) {
  89. print " license server for $1\n";
  90. $serverup = 1;
  91. }
  92. }
  93. if ( $serverup == 0 ) {
  94. print " license server not running\n";
  95. exit 2;
  96. }
  97. exit $ERRORS{'OK'} if ( $servers == $lf1 + $lf2 + $lf3 );
  98. exit $ERRORS{'WARNING'} if ( $servers == 3 && $lf1 + $lf2 + $lf3 == 2 );
  99. exit $ERRORS{'CRITICAL'};
  100. sub print_usage () {
  101. print "Usage:
  102. $PROGNAME -F <filename> [--verbose]
  103. $PROGNAME --help
  104. $PROGNAME --version
  105. ";
  106. }
  107. sub print_help () {
  108. print_revision($PROGNAME,'$Revision$');
  109. print "Copyright (c) 2000 Ernst-Dieter Martin/Karl DeBisschop
  110. Check available flexlm license managers
  111. ";
  112. print_usage();
  113. print "
  114. -F, --filename=FILE
  115. Name of license file
  116. -v, --verbose
  117. Print some extra debugging information (not advised for normal operation)
  118. -V, --version
  119. Show version and license information
  120. -h, --help
  121. Show this help screen
  122. ";
  123. support();
  124. }