Code

remove call_getopt
[nagiosplug.git] / plugins-scripts / check_flexlm.pl
1 #!/usr/bin/perl -w
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 #
33 use strict;
34 use Getopt::Long;
35 use vars qw($opt_V $opt_h $opt_F $verbose $PROGNAME);
36 use lib utils.pm;
37 use utils qw($TIMEOUT %ERRORS &print_revision &support &usage);
39 $PROGNAME="check_flexlm";
41 sub print_help ();
42 sub print_usage ();
44 $ENV{'PATH'}='';
45 $ENV{'BASH_ENV'}=''; 
46 $ENV{'ENV'}='';
48 Getopt::Long::Configure('bundling');
49 GetOptions
50         ("V"   => \$opt_V,   "version"    => \$opt_V,
51          "h"   => \$opt_h,   "help"       => \$opt_h,
52          "v"   => \$verbose, "verbose"    => \$verbose,
53          "F=s" => \$opt_F,   "filename=s" => \$opt_F);
55 if ($opt_V) {
56         print_revision($PROGNAME,'$Revision$');
57         exit $ERRORS{'OK'};
58 }
60 if ($opt_h) {print_help(); exit $ERRORS{'OK'};}
62 # Just in case of problems, let's not hang Nagios
63 $SIG{'ALRM'} = sub {
64         print "No Answer from Client\n";
65         exit 2;
66 };
67 alarm($TIMEOUT);
69 my $lmstat = $utils::PATH_TO_LMSTAT ;
70 unless (-x $lmstat ) {
71         print "Cannot find \"lmstat\"\n";
72         exit $ERRORS{'UNKNOWN'};
73 }
75 ($opt_F) || ($opt_F = shift) || usage("License file not specified\n");
76 my $licfile = $1 if ($opt_F =~ /^(.*)$/);
77 ($licfile) || usage("Invalid filename: $opt_F\n");
79 print "$licfile\n" if $verbose;
81 open CMD,"$lmstat -c $licfile |";
83 my $serverup = 0;
84 my ($ls1,$ls2,$ls3,$lf1,$lf2,$lf3,$servers);
86 while ( <CMD> ) {
87   if ( /^License server status: [0-9]*@([-0-9a-zA-Z_]*),[0-9]*@([-0-9a-zA-Z_]*),[0-9]*@([-0-9a-zA-Z_]*)/ ) {
88         $ls1 = $1;
89         $ls2 = $2;
90         $ls3 = $3;
91         $lf1 = $lf2 = $lf3 = 0;
92         $servers = 3;
93   } elsif ( /^License server status: [0-9]*@([-0-9a-zA-Z_]*)/ ) {
94         $ls1 = $1;
95         $ls2 = $ls3 = "";
96         $lf1 = $lf2 = $lf3 = 0;
97         $servers = 1;
98   } elsif ( / *$ls1: license server UP/ ) {
99         print "$ls1 UP, ";
100         $lf1 = 1
101   } elsif ( / *$ls2: license server UP/ ) {
102         print "$ls2 UP, ";
103         $lf2 = 1
104   } elsif ( / *$ls3: license server UP/ ) {
105         print "$ls3 UP, ";
106         $lf3 = 1
107   } elsif ( / *([^:]*: UP .*)/ ) {
108         print " license server for $1\n";
109         $serverup = 1;
110   }
112 if ( $serverup == 0 ) {
113     print " license server not running\n";
114     exit 2;     
117 exit $ERRORS{'OK'} if ( $servers == $lf1 + $lf2 + $lf3 );
118 exit $ERRORS{'WARNING'} if ( $servers == 3 && $lf1 + $lf2 + $lf3 == 2 );
119 exit $ERRORS{'CRITICAL'};
122 sub print_usage () {
123         print "Usage:
124    $PROGNAME -F <filename> [--verbose]
125    $PROGNAME --help
126    $PROGNAME --version
127 ";
130 sub print_help () {
131         print_revision($PROGNAME,'$Revision$');
132         print "Copyright (c) 2000 Ernst-Dieter Martin/Karl DeBisschop
134 Check available flexlm license managers
136 ";
137         print_usage();
138         print "
139 -F, --filename=FILE
140    Name of license file
141 -v, --verbose
142    Print some extra debugging information (not advised for normal operation)
143 -V, --version
144    Show version and license information
145 -h, --help
146    Show this help screen
148 ";
149         support();