diff options
-rwxr-xr-x | plugins-scripts/check_flexlm.pl | 173 |
1 files changed, 134 insertions, 39 deletions
diff --git a/plugins-scripts/check_flexlm.pl b/plugins-scripts/check_flexlm.pl index dccb6fe..ade5843 100755 --- a/plugins-scripts/check_flexlm.pl +++ b/plugins-scripts/check_flexlm.pl | |||
@@ -28,13 +28,16 @@ | |||
28 | # License: GPL | 28 | # License: GPL |
29 | # $Id$ | 29 | # $Id$ |
30 | # | 30 | # |
31 | # lmstat output patches from Steve Rigler/Cliff Rice 13-Apr-2002 | ||
32 | # srigler@marathonoil.com,cerice@marathonoil.com | ||
33 | |||
31 | 34 | ||
32 | 35 | ||
33 | use strict; | 36 | use strict; |
34 | use Getopt::Long; | 37 | use Getopt::Long; |
35 | use vars qw($opt_V $opt_h $opt_F $verbose $PROGNAME); | 38 | use vars qw($opt_V $opt_h $opt_F $opt_t $verbose $PROGNAME); |
36 | use lib utils.pm; | 39 | use lib utils.pm; |
37 | use utils qw($TIMEOUT %ERRORS &print_revision &support &usage); | 40 | use utils qw(%ERRORS &print_revision &support &usage); |
38 | 41 | ||
39 | $PROGNAME="check_flexlm"; | 42 | $PROGNAME="check_flexlm"; |
40 | 43 | ||
@@ -50,21 +53,32 @@ GetOptions | |||
50 | ("V" => \$opt_V, "version" => \$opt_V, | 53 | ("V" => \$opt_V, "version" => \$opt_V, |
51 | "h" => \$opt_h, "help" => \$opt_h, | 54 | "h" => \$opt_h, "help" => \$opt_h, |
52 | "v" => \$verbose, "verbose" => \$verbose, | 55 | "v" => \$verbose, "verbose" => \$verbose, |
53 | "F=s" => \$opt_F, "filename=s" => \$opt_F); | 56 | "F=s" => \$opt_F, "filename=s" => \$opt_F, |
57 | "t=i" => \$opt_t, "timeout=i" => \$opt_t); | ||
54 | 58 | ||
55 | if ($opt_V) { | 59 | if ($opt_V) { |
56 | print_revision($PROGNAME,'$Revision$'); | 60 | print_revision($PROGNAME,'$Revision$'); |
57 | exit $ERRORS{'OK'}; | 61 | exit $ERRORS{'OK'}; |
58 | } | 62 | } |
59 | 63 | ||
64 | unless (defined $opt_t) { | ||
65 | $opt_t = $utils::TIMEOUT ; # default timeout | ||
66 | } | ||
67 | |||
68 | |||
60 | if ($opt_h) {print_help(); exit $ERRORS{'OK'};} | 69 | if ($opt_h) {print_help(); exit $ERRORS{'OK'};} |
61 | 70 | ||
71 | unless (defined $opt_F) { | ||
72 | print "Missing license.dat file\n"; | ||
73 | print_usage(); | ||
74 | exit $ERRORS{'UNKNOWN'}; | ||
75 | } | ||
62 | # Just in case of problems, let's not hang Nagios | 76 | # Just in case of problems, let's not hang Nagios |
63 | $SIG{'ALRM'} = sub { | 77 | $SIG{'ALRM'} = sub { |
64 | print "No Answer from Client\n"; | 78 | print "Timeout: No Answer from Client\n"; |
65 | exit 2; | 79 | exit $ERRORS{'UNKNOWN'}; |
66 | }; | 80 | }; |
67 | alarm($TIMEOUT); | 81 | alarm($opt_t); |
68 | 82 | ||
69 | my $lmstat = $utils::PATH_TO_LMSTAT ; | 83 | my $lmstat = $utils::PATH_TO_LMSTAT ; |
70 | unless (-x $lmstat ) { | 84 | unless (-x $lmstat ) { |
@@ -78,50 +92,125 @@ my $licfile = $1 if ($opt_F =~ /^(.*)$/); | |||
78 | 92 | ||
79 | print "$licfile\n" if $verbose; | 93 | print "$licfile\n" if $verbose; |
80 | 94 | ||
81 | open CMD,"$lmstat -c $licfile |"; | 95 | if ( ! open(CMD,"$lmstat -c $licfile |") ) { |
96 | print "ERROR: Could not open \"$lmstat -c $licfile\" ($!)\n"; | ||
97 | exit exit $ERRORS{'UNKNOWN'}; | ||
98 | } | ||
82 | 99 | ||
83 | my $serverup = 0; | 100 | my $serverup = 0; |
84 | my ($ls1,$ls2,$ls3,$lf1,$lf2,$lf3,$servers); | 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. | ||
85 | 113 | ||
86 | while ( <CMD> ) { | 114 | 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_]*)/ ) { | 115 | next if (/^lmstat/); # ignore 1st line - copyright |
88 | $ls1 = $1; | 116 | next if (/^Flexible/); # ignore 2nd line - timestamp |
89 | $ls2 = $2; | 117 | (/^Vendor/) && last; # ignore Vendor daemon status |
90 | $ls3 = $3; | 118 | print $_ if $verbose; |
91 | $lf1 = $lf2 = $lf3 = 0; | 119 | |
92 | $servers = 3; | 120 | if ($_ =~ /license server /) { # matched 1 (of possibly 3) license server |
93 | } elsif ( /^License server status: [0-9]*@([-0-9a-zA-Z_]*)/ ) { | 121 | s/^\s*//; #some servers start at col 1, other have whitespace |
94 | $ls1 = $1; | 122 | # strip staring whitespace if any |
95 | $ls2 = $ls3 = ""; | 123 | if ( $_ =~ /UP/) { |
96 | $lf1 = $lf2 = $lf3 = 0; | 124 | $_ =~ /^(.*):/ ; |
97 | $servers = 1; | 125 | push(@upsrv, $1); |
98 | } elsif ( / *$ls1: license server UP/ ) { | 126 | print "up:$1:\n" if $verbose; |
99 | print "$ls1 UP, "; | 127 | } else { |
100 | $lf1 = 1 | 128 | $_ =~ /^(.*):/; |
101 | } elsif ( / *$ls2: license server UP/ ) { | 129 | push(@downsrv, $1); |
102 | print "$ls2 UP, "; | 130 | print "down:$1:\n" if $verbose; |
103 | $lf2 = 1 | 131 | } |
104 | } elsif ( / *$ls3: license server UP/ ) { | 132 | |
105 | print "$ls3 UP, "; | 133 | } |
106 | $lf3 = 1 | 134 | |
107 | } elsif ( / *([^:]*: UP .*)/ ) { | 135 | |
108 | print " license server for $1\n"; | 136 | # if ( /^License server status: [0-9]*@([-0-9a-zA-Z_]*),[0-9]*@([-0-9a-zA-Z_]*),[0-9]*@([-0-9a-zA-Z_]*)/ ) { |
109 | $serverup = 1; | 137 | # $ls1 = $1; |
110 | } | 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 | } | ||
111 | } | 189 | } |
112 | if ( $serverup == 0 ) { | 190 | # |
113 | print " license server not running\n"; | 191 | # Ditto for those which are down. |
114 | exit 2; | 192 | # |
193 | if (scalar(@downsrv) > 0) { | ||
194 | print "License servers NOT running:"; | ||
195 | foreach my $downserver (@downsrv) { | ||
196 | print "$downserver,"; | ||
197 | } | ||
115 | } | 198 | } |
116 | 199 | ||
117 | exit $ERRORS{'OK'} if ( $servers == $lf1 + $lf2 + $lf3 ); | 200 | # perfdata |
118 | exit $ERRORS{'WARNING'} if ( $servers == 3 && $lf1 + $lf2 + $lf3 == 2 ); | 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 ); | ||
119 | exit $ERRORS{'CRITICAL'}; | 208 | exit $ERRORS{'CRITICAL'}; |
120 | 209 | ||
121 | 210 | ||
122 | sub print_usage () { | 211 | sub print_usage () { |
123 | print "Usage: | 212 | print "Usage: |
124 | $PROGNAME -F <filename> [--verbose] | 213 | $PROGNAME -F <filename> [-v] [-t] [-V] [-h] |
125 | $PROGNAME --help | 214 | $PROGNAME --help |
126 | $PROGNAME --version | 215 | $PROGNAME --version |
127 | "; | 216 | "; |
@@ -137,14 +226,20 @@ Check available flexlm license managers | |||
137 | print_usage(); | 226 | print_usage(); |
138 | print " | 227 | print " |
139 | -F, --filename=FILE | 228 | -F, --filename=FILE |
140 | Name of license file | 229 | Name of license file (usually \"license.dat\") |
141 | -v, --verbose | 230 | -v, --verbose |
142 | Print some extra debugging information (not advised for normal operation) | 231 | Print some extra debugging information (not advised for normal operation) |
232 | -t, --timeout | ||
233 | Plugin time out in seconds (default = $utils::TIMEOUT ) | ||
143 | -V, --version | 234 | -V, --version |
144 | Show version and license information | 235 | Show version and license information |
145 | -h, --help | 236 | -h, --help |
146 | Show this help screen | 237 | Show this help screen |
147 | 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 | ||
148 | "; | 243 | "; |
149 | support(); | 244 | support(); |
150 | } | 245 | } |