diff options
Diffstat (limited to 'plugins-scripts/check_flexlm.pl')
-rwxr-xr-x | plugins-scripts/check_flexlm.pl | 149 |
1 files changed, 149 insertions, 0 deletions
diff --git a/plugins-scripts/check_flexlm.pl b/plugins-scripts/check_flexlm.pl new file mode 100755 index 00000000..1d26b7c8 --- /dev/null +++ b/plugins-scripts/check_flexlm.pl | |||
@@ -0,0 +1,149 @@ | |||
1 | #! /usr/bin/perl -wT | ||
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 | # | ||
30 | |||
31 | BEGIN { | ||
32 | if ($0 =~ m/^(.*?)[\/\\]([^\/\\]+)$/) { | ||
33 | $runtimedir = $1; | ||
34 | $PROGNAME = $2; | ||
35 | } | ||
36 | } | ||
37 | |||
38 | use strict; | ||
39 | use Getopt::Long; | ||
40 | use vars qw($opt_V $opt_h $opt_F $verbose $PROGNAME); | ||
41 | use lib $main::runtimedir; | ||
42 | use utils qw($TIMEOUT %ERRORS &print_revision &support &usage); | ||
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 | |||
58 | if ($opt_V) { | ||
59 | print_revision($PROGNAME,'$Revision$'); | ||
60 | exit $ERRORS{'OK'}; | ||
61 | } | ||
62 | |||
63 | if ($opt_h) {print_help(); exit $ERRORS{'OK'};} | ||
64 | |||
65 | # Just in case of problems, let's not hang Nagios | ||
66 | $SIG{'ALRM'} = sub { | ||
67 | print "No Answer from Client\n"; | ||
68 | exit 2; | ||
69 | }; | ||
70 | alarm($TIMEOUT); | ||
71 | |||
72 | my $lmstat = "/opt/lic/sw/cadadm/default/bin/lmstat"; | ||
73 | |||
74 | ($opt_F) || ($opt_F = shift) || usage("License file not specified\n"); | ||
75 | my $licfile = $1 if ($opt_F =~ /^(.*)$/); | ||
76 | ($licfile) || usage("Invalid filename: $opt_F\n"); | ||
77 | |||
78 | print "$licfile\n" if $verbose; | ||
79 | |||
80 | open CMD,"$lmstat -c $licfile |"; | ||
81 | |||
82 | my $serverup = 0; | ||
83 | my ($ls1,$ls2,$ls3,$lf1,$lf2,$lf3,$servers); | ||
84 | |||
85 | while ( <CMD> ) { | ||
86 | if ( /^License server status: [0-9]*@([-0-9a-zA-Z_]*),[0-9]*@([-0-9a-zA-Z_]*),[0-9]*@([-0-9a-zA-Z_]*)/ ) { | ||
87 | $ls1 = $1; | ||
88 | $ls2 = $2; | ||
89 | $ls3 = $3; | ||
90 | $lf1 = $lf2 = $lf3 = 0; | ||
91 | $servers = 3; | ||
92 | } elsif ( /^License server status: [0-9]*@([-0-9a-zA-Z_]*)/ ) { | ||
93 | $ls1 = $1; | ||
94 | $ls2 = $ls3 = ""; | ||
95 | $lf1 = $lf2 = $lf3 = 0; | ||
96 | $servers = 1; | ||
97 | } elsif ( / *$ls1: license server UP/ ) { | ||
98 | print "$ls1 UP, "; | ||
99 | $lf1 = 1 | ||
100 | } elsif ( / *$ls2: license server UP/ ) { | ||
101 | print "$ls2 UP, "; | ||
102 | $lf2 = 1 | ||
103 | } elsif ( / *$ls3: license server UP/ ) { | ||
104 | print "$ls3 UP, "; | ||
105 | $lf3 = 1 | ||
106 | } elsif ( / *([^:]*: UP .*)/ ) { | ||
107 | print " license server for $1\n"; | ||
108 | $serverup = 1; | ||
109 | } | ||
110 | } | ||
111 | if ( $serverup == 0 ) { | ||
112 | print " license server not running\n"; | ||
113 | exit 2; | ||
114 | } | ||
115 | |||
116 | exit $ERRORS{'OK'} if ( $servers == $lf1 + $lf2 + $lf3 ); | ||
117 | exit $ERRORS{'WARNING'} if ( $servers == 3 && $lf1 + $lf2 + $lf3 == 2 ); | ||
118 | exit $ERRORS{'CRITICAL'}; | ||
119 | |||
120 | |||
121 | sub print_usage () { | ||
122 | print "Usage: | ||
123 | $PROGNAME -F <filename> [--verbose] | ||
124 | $PROGNAME --help | ||
125 | $PROGNAME --version | ||
126 | "; | ||
127 | } | ||
128 | |||
129 | sub print_help () { | ||
130 | print_revision($PROGNAME,'$Revision$'); | ||
131 | print "Copyright (c) 2000 Ernst-Dieter Martin/Karl DeBisschop | ||
132 | |||
133 | Check available flexlm license managers | ||
134 | |||
135 | "; | ||
136 | print_usage(); | ||
137 | print " | ||
138 | -F, --filename=FILE | ||
139 | Name of license file | ||
140 | -v, --verbose | ||
141 | Print some extra debugging information (not advised for normal operation) | ||
142 | -V, --version | ||
143 | Show version and license information | ||
144 | -h, --help | ||
145 | Show this help screen | ||
146 | |||
147 | "; | ||
148 | support(); | ||
149 | } | ||