Update THANKS file
[monitoring-plugins.git] / plugins-scripts / check_flexlm.pl
blob54d933c723ffbd313d42e192c72fa5736883ffcb
1 #!/usr/bin/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 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
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 lib utils.pm;
39 use utils qw(%ERRORS &print_revision &support &usage);
41 $PROGNAME="check_flexlm";
43 sub print_help ();
44 sub print_usage ();
46 $ENV{'PATH'}='';
47 $ENV{'BASH_ENV'}='';
48 $ENV{'ENV'}='';
50 Getopt::Long::Configure('bundling');
51 GetOptions
52 ("V" => \$opt_V, "version" => \$opt_V,
53 "h" => \$opt_h, "help" => \$opt_h,
54 "v" => \$verbose, "verbose" => \$verbose,
55 "F=s" => \$opt_F, "filename=s" => \$opt_F,
56 "t=i" => \$opt_t, "timeout=i" => \$opt_t);
58 if ($opt_V) {
59 print_revision($PROGNAME,'@NP_VERSION@');
60 exit $ERRORS{'OK'};
63 unless (defined $opt_t) {
64 $opt_t = $utils::TIMEOUT ; # default timeout
68 if ($opt_h) {print_help(); exit $ERRORS{'OK'};}
70 unless (defined $opt_F) {
71 print "Missing license.dat file\n";
72 print_usage();
73 exit $ERRORS{'UNKNOWN'};
75 # Just in case of problems, let's not hang Nagios
76 $SIG{'ALRM'} = sub {
77 print "Timeout: No Answer from Client\n";
78 exit $ERRORS{'UNKNOWN'};
80 alarm($opt_t);
82 my $lmstat = $utils::PATH_TO_LMSTAT ;
83 unless (-x $lmstat ) {
84 print "Cannot find \"lmstat\"\n";
85 exit $ERRORS{'UNKNOWN'};
88 ($opt_F) || ($opt_F = shift) || usage("License file not specified\n");
89 my $licfile = $1 if ($opt_F =~ /^(.*)$/);
90 ($licfile) || usage("Invalid filename: $opt_F\n");
92 print "$licfile\n" if $verbose;
94 if ( ! open(CMD,"$lmstat -c $licfile |") ) {
95 print "ERROR: Could not open \"$lmstat -c $licfile\" ($!)\n";
96 exit exit $ERRORS{'UNKNOWN'};
99 my $serverup = 0;
100 my @upsrv;
101 my @downsrv; # list of servers up and down
103 #my ($ls1,$ls2,$ls3,$lf1,$lf2,$lf3,$servers);
105 # key off of the term "license server" and
106 # grab the status. Keep going until "Vendor" is found
110 # Collect list of license servers by their status
111 # Vendor daemon status is ignored for the moment.
113 while ( <CMD> ) {
114 next if (/^lmstat/); # ignore 1st line - copyright
115 next if (/^Flexible/); # ignore 2nd line - timestamp
116 (/^Vendor/) && last; # ignore Vendor daemon status
117 print $_ if $verbose;
119 if ($_ =~ /license server /) { # matched 1 (of possibly 3) license server
120 s/^\s*//; #some servers start at col 1, other have whitespace
121 # strip staring whitespace if any
122 if ( $_ =~ /UP/) {
123 $_ =~ /^(.*):/ ;
124 push(@upsrv, $1);
125 print "up:$1:\n" if $verbose;
126 } else {
127 $_ =~ /^(.*):/;
128 push(@downsrv, $1);
129 print "down:$1:\n" if $verbose;
135 # if ( /^License server status: [0-9]*@([-0-9a-zA-Z_]*),[0-9]*@([-0-9a-zA-Z_]*),[0-9]*@([-0-9a-zA-Z_]*)/ ) {
136 # $ls1 = $1;
137 # $ls2 = $2;
138 # $ls3 = $3;
139 # $lf1 = $lf2 = $lf3 = 0;
140 # $servers = 3;
141 # } elsif ( /^License server status: [0-9]*@([-0-9a-zA-Z_]*)/ ) {
142 # $ls1 = $1;
143 # $ls2 = $ls3 = "";
144 # $lf1 = $lf2 = $lf3 = 0;
145 # $servers = 1;
146 # } elsif ( / *$ls1: license server UP/ ) {
147 # print "$ls1 UP, ";
148 # $lf1 = 1
149 # } elsif ( / *$ls2: license server UP/ ) {
150 # print "$ls2 UP, ";
151 # $lf2 = 1
152 # } elsif ( / *$ls3: license server UP/ ) {
153 # print "$ls3 UP, ";
154 # $lf3 = 1
155 # } elsif ( / *([^:]*: UP .*)/ ) {
156 # print " license server for $1\n";
157 # $serverup = 1;
162 #if ( $serverup == 0 ) {
163 # print " license server not running\n";
164 # exit 2;
167 close CMD;
169 if ($verbose) {
170 print "License Servers running: ".scalar(@upsrv) ."\n";
171 foreach my $upserver (@upsrv) {
172 print "$upserver\n";
174 print "License servers not running: ".scalar(@downsrv)."\n";
175 foreach my $downserver (@downsrv) {
176 print "$downserver\n";
181 # print list of servers which are up.
183 if (scalar(@upsrv) > 0) {
184 print "License Servers running:";
185 foreach my $upserver (@upsrv) {
186 print "$upserver,";
190 # Ditto for those which are down.
192 if (scalar(@downsrv) > 0) {
193 print "License servers NOT running:";
194 foreach my $downserver (@downsrv) {
195 print "$downserver,";
199 # perfdata
200 print "\n|flexlm::up:".scalar(@upsrv).";down:".scalar(@downsrv)."\n";
202 exit $ERRORS{'OK'} if ( scalar(@downsrv) == 0 );
203 exit $ERRORS{'WARNING'} if ( (scalar(@upsrv) > 0) && (scalar(@downsrv) > 0));
205 #exit $ERRORS{'OK'} if ( $servers == $lf1 + $lf2 + $lf3 );
206 #exit $ERRORS{'WARNING'} if ( $servers == 3 && $lf1 + $lf2 + $lf3 == 2 );
207 exit $ERRORS{'CRITICAL'};
210 sub print_usage () {
211 print "Usage:
212 $PROGNAME -F <filename> [-v] [-t] [-V] [-h]
213 $PROGNAME --help
214 $PROGNAME --version
218 sub print_help () {
219 print_revision($PROGNAME,'@NP_VERSION@');
220 print "Copyright (c) 2000 Ernst-Dieter Martin/Karl DeBisschop
222 Check available flexlm license managers
225 print_usage();
226 print "
227 -F, --filename=FILE
228 Name of license file (usually \"license.dat\")
229 -v, --verbose
230 Print some extra debugging information (not advised for normal operation)
231 -t, --timeout
232 Plugin time out in seconds (default = $utils::TIMEOUT )
233 -V, --version
234 Show version and license information
235 -h, --help
236 Show this help screen
238 Flexlm license managers usually run as a single server or three servers and a
239 quorum is needed. The plugin return OK if 1 (single) or 3 (triple) servers
240 are running, CRITICAL if 1(single) or 3 (triple) servers are down, and WARNING
241 if 1 or 2 of 3 servers are running\n
243 support();