#! /usr/bin/perl -w # # usage: # check_rlm license_file # # Check available rlm license managers. # Use rlmutil to check the status of the license server # described by the license file given as argument. # Check and interpret the output of rlmutil # and create returncodes and output. # # Contrary to the nagios concept, this script takes # a file, not a hostname as an argument and returns # the status of services described in that # file. # # -- mercilessly hacked from the check_flexlm by Ernst-Dieter Martin # # # Notes: # - you need the rlmutil utility which comes with rlm. # - set the correct path in the variable $rlmutil. # e.g., edit utils.pm and add something like: # $PATH_TO_RLMUTIL = "/usr/bin/rlm/rlmutil" ; # # Kirk Lawson - 4/1/2010 # use strict; use Getopt::Long; use vars qw($opt_V $opt_h $opt_F $opt_t $verbose $PROGNAME $error_status @line); use lib "/usr/lib64/nagios/plugins"; use utils qw(%ERRORS &print_revision &support &usage); $PROGNAME="check_rlmutil"; sub print_help (); sub print_usage (); $ENV{'PATH'}=''; $ENV{'BASH_ENV'}=''; $ENV{'ENV'}=''; Getopt::Long::Configure('bundling'); GetOptions ("V" => \$opt_V, "version" => \$opt_V, "h" => \$opt_h, "help" => \$opt_h, "v" => \$verbose, "verbose" => \$verbose, "F=s" => \$opt_F, "filename=s" => \$opt_F, "t=i" => \$opt_t, "timeout=i" => \$opt_t); if ($opt_V) { print_revision($PROGNAME,'$Revision: 1.0 $'); exit $ERRORS{'OK'}; } unless (defined $opt_t) { $opt_t = $utils::TIMEOUT ; # default timeout } if ($opt_h) {print_help(); exit $ERRORS{'OK'};} unless (defined $opt_F) { print "Missing license.dat file\n"; print_usage(); exit $ERRORS{'UNKNOWN'}; } # Just in case of problems, let's not hang Nagios $SIG{'ALRM'} = sub { print "Timeout: No Answer from Client\n"; exit $ERRORS{'UNKNOWN'}; }; alarm($opt_t); my $rlmutil = $utils::PATH_TO_RLMUTIL ; unless (-x $rlmutil ) { print "Cannot find \"rlmutil\"\n"; exit $ERRORS{'UNKNOWN'}; } ($opt_F) || ($opt_F = shift) || usage("License file not specified\n"); my $licfile = $1 if ($opt_F =~ /^(.*)$/); ($licfile) || usage("Invalid filename: $opt_F\n"); print "$licfile\n" if $verbose; if ( ! open(CMD,"$rlmutil rlmstat -c $licfile |") ) { print "ERROR: Could not open \"$rlmutil -c $licfile\" ($!)\n"; exit exit $ERRORS{'UNKNOWN'}; } my $serverup = "down"; # key off of the term "rlm status" and # grab the status. # while ( ) { next if (/^setting/); # ignore 1st line - copyright next if (/^rlmutil/); # ignore 2nd line - timestamp print $_ if $verbose; if ($_ =~ /rlm status /) { s/^\s*//; #strip staring whitespace if any @line = $_; @line = split; if ( $line[6] eq "up" ) { # print "License Server running: $line[4] (port $line[6]\n"; $serverup = "up"; # print "@line\n" if $verbose; } } $error_status = $_ #always keep a copy of the last line read in - if #error/not-up, this line will hold what the actual error is } close CMD; if ($verbose) { if ( $serverup eq "up" ) { print "License Server running: $line[3] (port $line[5]\n"; } else { print "License server not running: \n"; } } # perfdata if ( $serverup eq "up" ) { print "|rlm: $line[3] (port $line[5]\n"; exit $ERRORS{'OK'}; } else { print "|rlm server failure: $error_status\n"; exit $ERRORS{'CRITICAL'}; } sub print_usage () { print "Usage: $PROGNAME -F [-v] [-t] [-V] [-h] $PROGNAME --help $PROGNAME --version "; } sub print_help () { print_revision($PROGNAME,'$Revision: 1.0 $'); print "Copyright (c) 2010 GPL Check available rlm license managers "; print_usage(); print " -F, --filename=FILE Name of license file (usually \"license.dat\") -v, --verbose Print some extra debugging information (not advised for normal operation) -t, --timeout Plugin time out in seconds (default = $utils::TIMEOUT ) -V, --version Show version and license information -h, --help Show this help screen rlm license managers usually run as a single server.\n "; support(); }