Tuesday, November 27, 2007

Nagios Remote Radius Monitor Script


This script written in Perl can be used as a monitor within Nagios to monitor the state of a Radius server.

#!/usr/bin/perl
use Authen::Radius;
my $numberargs = $#ARGV + 1;
if ($numberargs ne 5) {
   print "Usage: check_radius \n";
   exit(0);
}
my $hostname = $ARGV[0];
my $port = $ARGV[1];
my $radiussecret = $ARGV[2];
my $username = $ARGV[3];
my $password = $ARGV[4];
my $radius = new Authen::Radius(Host => "$hostname:$port", Secret => $radiussecret);
if (!defined $radius) {
   print "No Response from Host\n";
   exit(2);
} else {
   my $r = $radius->check_pwd($username, $password);
   if($r) {
      print "Service OK\n";
      exit(0);
   } else {
      print "Service Critical\n";
      exit(2);
   }
}
exit(2);