check_flexlm.pl 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #!/usr/local/bin/perl
  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. # current status: looks like working
  28. #
  29. # Copyright Notice: Do as you please, credit me, but don't blame me
  30. #
  31. # Just in case of problems, let's not hang Nagios
  32. $SIG{'ALRM'} = sub {
  33. print "No Answer from Client\n";
  34. exit 2;
  35. };
  36. alarm(20);
  37. $lmstat = "/opt/lic/sw/cadadm/default/bin/lmstat";
  38. $licfile = shift;
  39. #print "$licfile \n";
  40. open CMD,"$lmstat -c $licfile |";
  41. $serverup = 0;
  42. while ( <CMD> ) {
  43. if ( /^License server status: [0-9]*@([-0-9a-zA-Z_]*),[0-9]*@([-0-9a-zA-Z_]*),[0-9]*@([-0-9a-zA-Z_]*)/ ) {
  44. $ls1 = $1;
  45. $ls2 = $2;
  46. $ls3 = $3;
  47. $lf1 = $lf2 = $lf3 = 0;
  48. $servers = 3;
  49. } elsif ( /^License server status: [0-9]*@([-0-9a-zA-Z_]*)/ ) {
  50. $ls1 = $1;
  51. $ls2 = $ls3 = "";
  52. $lf1 = $lf2 = $lf3 = 0;
  53. $servers = 1;
  54. } elsif ( / *$ls1: license server UP/ ) {
  55. print "$ls1 UP, ";
  56. $lf1 = 1
  57. } elsif ( / *$ls2: license server UP/ ) {
  58. print "$ls2 UP, ";
  59. $lf2 = 1
  60. } elsif ( / *$ls3: license server UP/ ) {
  61. print "$ls3 UP, ";
  62. $lf3 = 1
  63. } elsif ( / *([^:]*: UP .*)/ ) {
  64. print " license server for $1\n";
  65. $serverup = 1;
  66. }
  67. }
  68. if ( $serverup == 0 ) {
  69. print " license server not running\n";
  70. exit 2;
  71. }
  72. exit 0 if ( $servers == $lf1 + $lf2 + $lf3 );
  73. exit 1 if ( $servers == 3 && $lf1 + $lf2 + $lf3 == 2 );
  74. exit 2;