[BACK]Return to check_radius.pl CVS log [TXT][DIR] Up to [local] / nagios / check_radius

Diff for /nagios/check_radius/check_radius.pl between version 1.1.1.1 and 1.3

version 1.1.1.1, 2005/04/22 18:42:57 version 1.3, 2006/08/29 23:26:31
Line 1 
Line 1 
 #!/usr/bin/perl  #!/usr/bin/perl
 #  # $RedRiver: check_radius.pl,v 1.2 2005/08/25 00:56:07 andrew Exp $
 # check_radius.pl - nagios plugin  #
 #  # check_radius.pl - nagios plugin
 #  #
 # Copyright (C) 2003 andrew fresh  #
 #  # Copyright (C) 2003 andrew fresh
 # This program is free software; you can redistribute it and/or  #
 # modify it under the terms of the GNU General Public License  # This program is free software; you can redistribute it and/or
 # as published by the Free Software Foundation; either version 2  # modify it under the terms of the GNU General Public License
 # of the License, or (at your option) any later version.  # as published by the Free Software Foundation; either version 2
 #  # of the License, or (at your option) any later version.
 # This program is distributed in the hope that it will be useful,  #
 # but WITHOUT ANY WARRANTY; without even the implied warranty of  # This program is distributed in the hope that it will be useful,
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the  # but WITHOUT ANY WARRANTY; without even the implied warranty of
 # GNU General Public License for more details.  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 #  # GNU General Public License for more details.
 # You should have received a copy of the GNU General Public License  #
 # along with this program; if not, write to the Free Software  # You should have received a copy of the GNU General Public License
 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.  # along with this program; if not, write to the Free Software
 #  # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 #  #
 # Report bugs to: andrew@mad-techies.org  #
 #  # Report bugs to: andrew@mad-techies.org
 # 11.26.2000 Version 1.0  #
 #  # 11.26.2000 Version 1.0
 # $Id$  #
   # $Id$
 use strict;  
 use warnings;  use strict;
 use diagnostics;  use warnings;
   use diagnostics;
 use POSIX;  
 use lib "C:/nrpe_nt/lib"  ;  use POSIX;
 use utils qw($TIMEOUT %ERRORS &print_revision &support);  use lib "/usr/local/libexec/nagios";
   use utils qw($TIMEOUT %ERRORS &print_revision &support);
 use Getopt::Long;  
 Getopt::Long::Configure('bundling');  use Getopt::Long;
   Getopt::Long::Configure('bundling');
 my $PROGNAME = "check_radius";  
   my $PROGNAME = "check_radius";
 my $state = 'UNKNOWN'; # tells whether the it is warning, critical, or OK  
 my $answer = ''; # stores the test of the errors  my $state = 'UNKNOWN'; # tells whether the it is warning, critical, or OK
 my $hostname = '';  my $answer = ''; # stores the test of the errors
 my $port = '';  my $hostname = '';
 my $secret = '';  my $port = '';
 my $user   = '';  my $secret = '';
 my $pwd    = '';  my $user   = '';
 my $timeout = 5;  my $pwd    = '';
 my %states; # This stores the count of states;  my $timeout = 5;
 my $file;  my %states; # This stores the count of states;
 my $opt_h ;  my $file;
 my $opt_V ;  my $opt_h ;
   my $opt_V ;
   
 # Just in case of problems, let's not hang Nagios  
 $SIG{'ALRM'} = sub {  # Just in case of problems, let's not hang Nagios
      print ("ERROR: No radius response from $hostname (alarm timeout)\n");  $SIG{'ALRM'} = sub {
      exit $ERRORS{"UNKNOWN"};       print ("ERROR: No radius response from $hostname (alarm timeout)\n");
 };       exit $ERRORS{"UNKNOWN"};
 alarm($TIMEOUT);  };
   alarm($TIMEOUT);
   
   
 #Option checking  
 my $status = GetOptions(  #Option checking
         "V"   => \$opt_V, "version"    => \$opt_V,  my $status = GetOptions(
         "h"   => \$opt_h, "help"       => \$opt_h,          "V"   => \$opt_V, "version"    => \$opt_V,
         "H=s" => \$hostname, "hostname=s" => \$hostname,          "h"   => \$opt_h, "help"       => \$opt_h,
         "s=s" => \$secret, "secret=s" => \$secret,          "H=s" => \$hostname, "hostname=s" => \$hostname,
         "P=i" => \$port, "port=i" => \$port,          "s=s" => \$secret, "secret=s" => \$secret,
         "u=s" => \$user, "username=s" => \$user,          "P=i" => \$port, "port=i" => \$port,
         "p=s" => \$pwd, "password=s" => \$pwd,          "u=s" => \$user, "username=s" => \$user,
                 "t=i" => \$timeout, "timeout=i"=> \$timeout,          "p=s" => \$pwd, "password=s" => \$pwd,
         );                  "t=i" => \$timeout, "timeout=i"=> \$timeout,
                   );
 if ($status == 0)  
 {  if ($status == 0)
     print_help() ;  {
     exit $ERRORS{'OK'};      print_help() ;
 }      exit $ERRORS{'OK'};
   }
   
 if ($opt_V) {  
     print_revision($PROGNAME,'$Revision$ ');  if ($opt_V) {
     exit $ERRORS{'OK'};      print_revision($PROGNAME,'$Revision$ ');
 }      exit $ERRORS{'OK'};
   }
 if ($opt_h) {  
     print_help();  if ($opt_h) {
     exit $ERRORS{'OK'};      print_help();
 }      exit $ERRORS{'OK'};
   }
 unless ($hostname && $secret && $user && $pwd) {  
         print_help();  unless ($hostname && $secret && $user && $pwd) {
         exit $ERRORS{'OK'};          print_help();
 }          exit $ERRORS{'OK'};
   }
 if ($port) {  
         $hostname .= ":" . $port;  if ($port) {
 }          $hostname .= ":" . $port;
   }
 use Authen::Radius;  
   use Authen::Radius;
 #print "Creating Client . . . ";  
 my $r = new Authen::Radius(Host => $hostname, Secret => $secret, Timeout => $timeout);  #print "Creating Client . . . ";
 #print defined $r ? "" : "not ", "ok\n";  my $r = new Authen::Radius(Host => $hostname, Secret => $secret, Timeout => $timeout);
   #print defined $r ? "" : "not ", "ok\n";
 unless (defined $r) {  
         done('UNKNOWN', "Couldn't create socket!");  unless (defined $r) {
 }          done('UNKNOWN', "Couldn't create socket!");
   }
   
 $r->clear_attributes;  
   $r->clear_attributes;
 $r->add_attributes (  
         { Name => 1, Value => $user, Type => 'string' }, # Username  $r->add_attributes (
         { Name => 2, Value => $pwd, Type => 'string' },  # Password          { Name => 1, Value => $user, Type => 'string' }, # Username
         { Name => 5, Value => '1', Type => 'integer' },  # NASPort          { Name => 2, Value => $pwd, Type => 'string' },  # Password
 );          { Name => 5, Value => '1', Type => 'integer' },  # NASPort
   );
 #print "Authenticating . . .";  
 my $snt = $r->send_packet(ACCESS_REQUEST);  #print "Authenticating . . .";
 unless (defined $snt) {  my $snt = $r->send_packet(ACCESS_REQUEST);
         done('CRITICAL', "Couldn't sent authentication packet: " . $r->strerror($r->get_error));  unless (defined $snt) {
 }          done('CRITICAL', "Couldn't sent authentication packet: " . $r->strerror($r->get_error));
   }
 $r->clear_attributes;  
   $r->clear_attributes;
 my $rcv = $r->recv_packet();  
   my $rcv = $r->recv_packet();
 #print "" . (defined($rcv) and $rcv == ACCESS_ACCEPT) ? "" : "not ", "ok\n";  
   #print "" . (defined($rcv) and $rcv == ACCESS_ACCEPT) ? "" : "not ", "ok\n";
 unless (defined $rcv) {  
         done ('CRITICAL', "Didn't recieve valid response: " . $r->strerror($r->get_error));  unless (defined $rcv) {
 }          done ('CRITICAL', "Didn't recieve valid response: " . $r->strerror($r->get_error));
                   }
 unless ($rcv == ACCESS_ACCEPT) {  
         done ('WARNING', "Access was denied for $user");  unless ($rcv == ACCESS_ACCEPT) {
 }          done ('WARNING', "Access was denied for $user");
   }
   
 #my @a = $r->get_attributes;  
 #print "Attributes . . . ";  #my @a = $r->get_attributes;
 #print $#a != -1 ? "" : "not ", "ok\n";  #print "Attributes . . . ";
 #for $a (@a) {  #print $#a != -1 ? "" : "not ", "ok\n";
 #       print "attr: name=$a->{'Name'} value=$a->{'Value'}\n";  #for $a (@a) {
 #}  #       print "attr: name=$a->{'Name'} value=$a->{'Value'}\n";
   #}
   
 if ($state eq 'UNKNOWN') {  
         $state = 'OK';  if ($state eq 'UNKNOWN') {
         $answer = "User $user authenticated correctly!";          $state = 'OK';
 }          $answer = "User $user authenticated correctly!";
   }
 done($state, $answer);  
   done($state, $answer);
 sub done  
 {  sub done
         my $state = shift;  {
         my $answer = shift;          my $state = shift;
           my $answer = shift;
         print "$state: ";  
         print $answer;          print "$state: ";
         exit $ERRORS{$state};          print $answer;
 }          exit $ERRORS{$state};
   }
 sub print_help {  
     printf "$PROGNAME plugin for Nagios monitors radius authentication\n";  sub print_help {
         printf "  $PROGNAME -H <HOSTNAME> -u <USERNAME> -p <PASSWORD>\n";      printf "$PROGNAME plugin for Nagios monitors radius authentication\n";
     printf "\nUsage:\n";          printf "  $PROGNAME -H <HOSTNAME> -u <USERNAME> -p <PASSWORD>\n";
     printf "   -H (--hostname)   Hostname to query              (required)\n";      printf "\nUsage:\n";
         printf "   -s (--secret)     Radius Secret                  (required)\n";      printf "   -H (--hostname)   Hostname to query              (required)\n";
         printf "   -P (--port)       Radius auth port\n";          printf "   -s (--secret)     Radius Secret                  (required)\n";
         printf "   -u (--username)   Username to try authenticating (required)\n";          printf "   -P (--port)       Radius auth port\n";
         printf "   -p (--password)   Password to authenticate with  (required)\n";          printf "   -u (--username)   Username to try authenticating (required)\n";
         printf "   -t (--timeout)    Time to wait for response (defaults to 5 secs)\n";          printf "   -p (--password)   Password to authenticate with  (required)\n";
     printf "   -h (--help)       usage help \n\n";          printf "   -t (--timeout)    Time to wait for response (defaults to 5 secs)\n";
     print_revision($PROGNAME, '$Revision$');      printf "   -h (--help)       usage help \n\n";
 }      print_revision($PROGNAME, '$Revision$');
   }
   

Legend:
Removed from v.1.1.1.1  
changed lines
  Added in v.1.3

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>