update perl module to 0.39
[monitoring-plugins.git] / plugins-scripts / check_flexlm.pl
blob5f3ed598482d1342c6248f15e6019e4a4ffc07dd
1 #!@PERL@ -w
3 # usage:
4 # check_flexlm.pl license_file
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.
12 # Contrary to most other plugins, 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
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$
22 # Notes:
23 # - you need the lmstat utility which comes with flexlm.
24 # - set the correct path in the variable $lmstat.
26 # initial version: 9-10-99 Ernst-Dieter Martin edmt@infineon.com
28 # License: GPL
30 # lmstat output patches from Steve Rigler/Cliff Rice 13-Apr-2002
31 # srigler@marathonoil.com,cerice@marathonoil.com
35 use strict;
36 use Getopt::Long;
37 use vars qw($opt_V $opt_h $opt_F $opt_t $verbose $PROGNAME);
38 use FindBin;
39 use lib "$FindBin::Bin";
40 use lib '@libexecdir@';
41 use utils qw(%ERRORS &print_revision &support &usage);
43 $PROGNAME="check_flexlm";
45 sub print_help ();
46 sub print_usage ();
48 $ENV{'PATH'}='@TRUSTED_PATH@';
49 $ENV{'BASH_ENV'}='';
50 $ENV{'ENV'}='';
52 Getopt::Long::Configure('bundling');
53 GetOptions
54 ("V" => \$opt_V, "version" => \$opt_V,
55 "h" => \$opt_h, "help" => \$opt_h,
56 "v" => \$verbose, "verbose" => \$verbose,
57 "F=s" => \$opt_F, "filename=s" => \$opt_F,
58 "t=i" => \$opt_t, "timeout=i" => \$opt_t);
60 if ($opt_V) {
61 print_revision($PROGNAME,'@NP_VERSION@');
62 exit $ERRORS{'OK'};
65 unless (defined $opt_t) {
66 $opt_t = $utils::TIMEOUT ; # default timeout
70 if ($opt_h) {print_help(); exit $ERRORS{'OK'};}
72 unless (defined $opt_F) {
73 print "Missing license.dat file\n";
74 print_usage();
75 exit $ERRORS{'UNKNOWN'};
77 # Just in case of problems, let's not hang the monitoring system
78 $SIG{'ALRM'} = sub {
79 print "Timeout: No Answer from Client\n";
80 exit $ERRORS{'UNKNOWN'};
82 alarm($opt_t);
84 my $lmstat = $utils::PATH_TO_LMSTAT ;
85 unless (-x $lmstat ) {
86 print "Cannot find \"lmstat\"\n";
87 exit $ERRORS{'UNKNOWN'};
90 ($opt_F) || ($opt_F = shift) || usage("License file not specified\n");
91 my $licfile = $1 if ($opt_F =~ /^(.*)$/);
92 ($licfile) || usage("Invalid filename: $opt_F\n");
94 print "$licfile\n" if $verbose;
96 if ( ! open(CMD,"$lmstat -c $licfile |") ) {
97 print "ERROR: Could not open \"$lmstat -c $licfile\" ($!)\n";
98 exit exit $ERRORS{'UNKNOWN'};
101 my $serverup = 0;
102 my @upsrv;
103 my @downsrv; # list of servers up and down
105 #my ($ls1,$ls2,$ls3,$lf1,$lf2,$lf3,$servers);
107 # key off of the term "license server" and
108 # grab the status. Keep going until "Vendor" is found
112 # Collect list of license servers by their status
113 # Vendor daemon status is ignored for the moment.
115 while ( <CMD> ) {
116 next if (/^lmstat/); # ignore 1st line - copyright
117 next if (/^Flexible/); # ignore 2nd line - timestamp
118 (/^Vendor/) && last; # ignore Vendor daemon status
119 print $_ if $verbose;
121 if ($_ =~ /license server /) { # matched 1 (of possibly 3) license server
122 s/^\s*//; #some servers start at col 1, other have whitespace
123 # strip staring whitespace if any
124 if ( $_ =~ /UP/) {
125 $_ =~ /^(.*):/ ;
126 push(@upsrv, $1);
127 print "up:$1:\n" if $verbose;
128 } else {
129 $_ =~ /^(.*):/;
130 push(@downsrv, $1);
131 print "down:$1:\n" if $verbose;
137 # if ( /^License server status: [0-9]*@([-0-9a-zA-Z_]*),[0-9]*@([-0-9a-zA-Z_]*),[0-9]*@([-0-9a-zA-Z_]*)/ ) {
138 # $ls1 = $1;
139 # $ls2 = $2;
140 # $ls3 = $3;
141 # $lf1 = $lf2 = $lf3 = 0;
142 # $servers = 3;
143 # } elsif ( /^License server status: [0-9]*@([-0-9a-zA-Z_]*)/ ) {
144 # $ls1 = $1;
145 # $ls2 = $ls3 = "";
146 # $lf1 = $lf2 = $lf3 = 0;
147 # $servers = 1;
148 # } elsif ( / *$ls1: license server UP/ ) {
149 # print "$ls1 UP, ";
150 # $lf1 = 1
151 # } elsif ( / *$ls2: license server UP/ ) {
152 # print "$ls2 UP, ";
153 # $lf2 = 1
154 # } elsif ( / *$ls3: license server UP/ ) {
155 # print "$ls3 UP, ";
156 # $lf3 = 1
157 # } elsif ( / *([^:]*: UP .*)/ ) {
158 # print " license server for $1\n";
159 # $serverup = 1;
164 #if ( $serverup == 0 ) {
165 # print " license server not running\n";
166 # exit 2;
169 close CMD;
171 if ($verbose) {
172 print "License Servers running: ".scalar(@upsrv) ."\n";
173 foreach my $upserver (@upsrv) {
174 print "$upserver\n";
176 print "License servers not running: ".scalar(@downsrv)."\n";
177 foreach my $downserver (@downsrv) {
178 print "$downserver\n";
183 # print list of servers which are up.
185 if (scalar(@upsrv) > 0) {
186 print "License Servers running:";
187 foreach my $upserver (@upsrv) {
188 print "$upserver,";
192 # Ditto for those which are down.
194 if (scalar(@downsrv) > 0) {
195 print "License servers NOT running:";
196 foreach my $downserver (@downsrv) {
197 print "$downserver,";
201 # perfdata
202 print "\n|flexlm::up:".scalar(@upsrv).";down:".scalar(@downsrv)."\n";
204 exit $ERRORS{'OK'} if ( scalar(@downsrv) == 0 );
205 exit $ERRORS{'WARNING'} if ( (scalar(@upsrv) > 0) && (scalar(@downsrv) > 0));
207 #exit $ERRORS{'OK'} if ( $servers == $lf1 + $lf2 + $lf3 );
208 #exit $ERRORS{'WARNING'} if ( $servers == 3 && $lf1 + $lf2 + $lf3 == 2 );
209 exit $ERRORS{'CRITICAL'};
212 sub print_usage () {
213 print "Usage:
214 $PROGNAME -F <filename> [-v] [-t] [-V] [-h]
215 $PROGNAME --help
216 $PROGNAME --version
220 sub print_help () {
221 print_revision($PROGNAME,'@NP_VERSION@');
222 print "Copyright (c) 2000 Ernst-Dieter Martin/Karl DeBisschop
224 Check available flexlm license managers
227 print_usage();
228 print "
229 -F, --filename=FILE
230 Name of license file (usually \"license.dat\")
231 -v, --verbose
232 Print some extra debugging information (not advised for normal operation)
233 -t, --timeout
234 Plugin time out in seconds (default = $utils::TIMEOUT )
235 -V, --version
236 Show version and license information
237 -h, --help
238 Show this help screen
240 Flexlm license managers usually run as a single server or three servers and a
241 quorum is needed. The plugin return OK if 1 (single) or 3 (triple) servers
242 are running, CRITICAL if 1(single) or 3 (triple) servers are down, and WARNING
243 if 1 or 2 of 3 servers are running\n
245 support();