check_flexlm.pl 3.7 KB

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