[ Index ] |
PHP Cross Reference of Unnamed Project |
[Summary view] [Print] [Text view]
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: check_flexlm.pl,v 1.6 2003/02/04 06:16:16 sghosh Exp $ 30 # 31 # lmstat output patches from Steve Rigler/Cliff Rice 13-Apr-2002 32 # srigler@marathonoil.com,cerice@marathonoil.com 33 34 35 36 use strict; 37 use Getopt::Long; 38 use vars qw($opt_V $opt_h $opt_F $opt_t $verbose $PROGNAME); 39 use lib "/usr/lib/nagios/plugins"; 40 use utils qw(%ERRORS &print_revision &support &usage); 41 42 $PROGNAME="check_flexlm"; 43 44 sub print_help (); 45 sub print_usage (); 46 47 $ENV{'PATH'}=''; 48 $ENV{'BASH_ENV'}=''; 49 $ENV{'ENV'}=''; 50 51 Getopt::Long::Configure('bundling'); 52 GetOptions 53 ("V" => \$opt_V, "version" => \$opt_V, 54 "h" => \$opt_h, "help" => \$opt_h, 55 "v" => \$verbose, "verbose" => \$verbose, 56 "F=s" => \$opt_F, "filename=s" => \$opt_F, 57 "t=i" => \$opt_t, "timeout=i" => \$opt_t); 58 59 if ($opt_V) { 60 print_revision($PROGNAME,'$Revision: 1.6 $'); 61 exit $ERRORS{'OK'}; 62 } 63 64 unless (defined $opt_t) { 65 $opt_t = $utils::TIMEOUT ; # default timeout 66 } 67 68 69 if ($opt_h) {print_help(); exit $ERRORS{'OK'};} 70 71 unless (defined $opt_F) { 72 print "Missing license.dat file\n"; 73 print_usage(); 74 exit $ERRORS{'UNKNOWN'}; 75 } 76 # Just in case of problems, let's not hang Nagios 77 $SIG{'ALRM'} = sub { 78 print "Timeout: No Answer from Client\n"; 79 exit $ERRORS{'UNKNOWN'}; 80 }; 81 alarm($opt_t); 82 83 my $lmstat = $utils::PATH_TO_LMSTAT ; 84 unless (-x $lmstat ) { 85 print "Cannot find \"lmstat\"\n"; 86 exit $ERRORS{'UNKNOWN'}; 87 } 88 89 ($opt_F) || ($opt_F = shift) || usage("License file not specified\n"); 90 my $licfile = $1 if ($opt_F =~ /^(.*)$/); 91 ($licfile) || usage("Invalid filename: $opt_F\n"); 92 93 print "$licfile\n" if $verbose; 94 95 if ( ! open(CMD,"$lmstat -c $licfile |") ) { 96 print "ERROR: Could not open \"$lmstat -c $licfile\" ($!)\n"; 97 exit exit $ERRORS{'UNKNOWN'}; 98 } 99 100 my $serverup = 0; 101 my @upsrv; 102 my @downsrv; # list of servers up and down 103 104 #my ($ls1,$ls2,$ls3,$lf1,$lf2,$lf3,$servers); 105 106 # key off of the term "license server" and 107 # grab the status. Keep going until "Vendor" is found 108 # 109 110 # 111 # Collect list of license servers by their status 112 # Vendor daemon status is ignored for the moment. 113 114 while ( <CMD> ) { 115 next if (/^lmstat/); # ignore 1st line - copyright 116 next if (/^Flexible/); # ignore 2nd line - timestamp 117 (/^Vendor/) && last; # ignore Vendor daemon status 118 print $_ if $verbose; 119 120 if ($_ =~ /license server /) { # matched 1 (of possibly 3) license server 121 s/^\s*//; #some servers start at col 1, other have whitespace 122 # strip staring whitespace if any 123 if ( $_ =~ /UP/) { 124 $_ =~ /^(.*):/ ; 125 push(@upsrv, $1); 126 print "up:$1:\n" if $verbose; 127 } else { 128 $_ =~ /^(.*):/; 129 push(@downsrv, $1); 130 print "down:$1:\n" if $verbose; 131 } 132 133 } 134 135 136 # if ( /^License server status: [0-9]*@([-0-9a-zA-Z_]*),[0-9]*@([-0-9a-zA-Z_]*),[0-9]*@([-0-9a-zA-Z_]*)/ ) { 137 # $ls1 = $1; 138 # $ls2 = $2; 139 # $ls3 = $3; 140 # $lf1 = $lf2 = $lf3 = 0; 141 # $servers = 3; 142 # } elsif ( /^License server status: [0-9]*@([-0-9a-zA-Z_]*)/ ) { 143 # $ls1 = $1; 144 # $ls2 = $ls3 = ""; 145 # $lf1 = $lf2 = $lf3 = 0; 146 # $servers = 1; 147 # } elsif ( / *$ls1: license server UP/ ) { 148 # print "$ls1 UP, "; 149 # $lf1 = 1 150 # } elsif ( / *$ls2: license server UP/ ) { 151 # print "$ls2 UP, "; 152 # $lf2 = 1 153 # } elsif ( / *$ls3: license server UP/ ) { 154 # print "$ls3 UP, "; 155 # $lf3 = 1 156 # } elsif ( / *([^:]*: UP .*)/ ) { 157 # print " license server for $1\n"; 158 # $serverup = 1; 159 # } 160 161 } 162 163 #if ( $serverup == 0 ) { 164 # print " license server not running\n"; 165 # exit 2; 166 #} 167 168 close CMD; 169 170 if ($verbose) { 171 print "License Servers running: ".scalar(@upsrv) ."\n"; 172 foreach my $upserver (@upsrv) { 173 print "$upserver\n"; 174 } 175 print "License servers not running: ".scalar(@downsrv)."\n"; 176 foreach my $downserver (@downsrv) { 177 print "$downserver\n"; 178 } 179 } 180 181 # 182 # print list of servers which are up. 183 # 184 if (scalar(@upsrv) > 0) { 185 print "License Servers running:"; 186 foreach my $upserver (@upsrv) { 187 print "$upserver,"; 188 } 189 } 190 # 191 # Ditto for those which are down. 192 # 193 if (scalar(@downsrv) > 0) { 194 print "License servers NOT running:"; 195 foreach my $downserver (@downsrv) { 196 print "$downserver,"; 197 } 198 } 199 200 # perfdata 201 print "\n|flexlm::up:".scalar(@upsrv).";down:".scalar(@downsrv)."\n"; 202 203 exit $ERRORS{'OK'} if ( scalar(@downsrv) == 0 ); 204 exit $ERRORS{'WARNING'} if ( (scalar(@upsrv) > 0) && (scalar(@downsrv) > 0)); 205 206 #exit $ERRORS{'OK'} if ( $servers == $lf1 + $lf2 + $lf3 ); 207 #exit $ERRORS{'WARNING'} if ( $servers == 3 && $lf1 + $lf2 + $lf3 == 2 ); 208 exit $ERRORS{'CRITICAL'}; 209 210 211 sub print_usage () { 212 print "Usage: 213 $PROGNAME -F <filename> [-v] [-t] [-V] [-h] 214 $PROGNAME --help 215 $PROGNAME --version 216 "; 217 } 218 219 sub print_help () { 220 print_revision($PROGNAME,'$Revision: 1.6 $'); 221 print "Copyright (c) 2000 Ernst-Dieter Martin/Karl DeBisschop 222 223 Check available flexlm license managers 224 225 "; 226 print_usage(); 227 print " 228 -F, --filename=FILE 229 Name of license file (usually \"license.dat\") 230 -v, --verbose 231 Print some extra debugging information (not advised for normal operation) 232 -t, --timeout 233 Plugin time out in seconds (default = $utils::TIMEOUT ) 234 -V, --version 235 Show version and license information 236 -h, --help 237 Show this help screen 238 239 Flexlm license managers usually run as a single server or three servers and a 240 quorum is needed. The plugin return OK if 1 (single) or 3 (triple) servers 241 are running, CRITICAL if 1(single) or 3 (triple) servers are down, and WARNING 242 if 1 or 2 of 3 servers are running\n 243 "; 244 support(); 245 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Tue Mar 17 22:47:18 2015 | Cross-referenced by PHPXref 0.7.1 |