Annotation of nagios/check_radius/check_radius.pl, Revision 1.2
1.1 andrew 1: #!/usr/bin/perl
1.2 ! andrew 2: # $RedRiver$
1.1 andrew 3: #
4: # check_radius.pl - nagios plugin
5: #
6: #
7: # Copyright (C) 2003 andrew fresh
8: #
9: # This program is free software; you can redistribute it and/or
10: # modify it under the terms of the GNU General Public License
11: # as published by the Free Software Foundation; either version 2
12: # of the License, or (at your option) any later version.
13: #
14: # This program is distributed in the hope that it will be useful,
15: # but WITHOUT ANY WARRANTY; without even the implied warranty of
16: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17: # GNU General Public License for more details.
18: #
19: # You should have received a copy of the GNU General Public License
20: # along with this program; if not, write to the Free Software
21: # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22: #
23: #
24: # Report bugs to: andrew@mad-techies.org
25: #
26: # 11.26.2000 Version 1.0
27: #
1.2 ! andrew 28: # $Id: check_radius.pl,v 1.1.1.1 2005/04/22 17:42:57 andrew Exp $
1.1 andrew 29:
30: use strict;
31: use warnings;
32: use diagnostics;
33:
34: use POSIX;
35: use lib "C:/nrpe_nt/lib" ;
36: use utils qw($TIMEOUT %ERRORS &print_revision &support);
37:
38: use Getopt::Long;
39: Getopt::Long::Configure('bundling');
40:
41: my $PROGNAME = "check_radius";
42:
43: my $state = 'UNKNOWN'; # tells whether the it is warning, critical, or OK
44: my $answer = ''; # stores the test of the errors
45: my $hostname = '';
46: my $port = '';
47: my $secret = '';
48: my $user = '';
49: my $pwd = '';
50: my $timeout = 5;
51: my %states; # This stores the count of states;
52: my $file;
53: my $opt_h ;
54: my $opt_V ;
55:
56:
57: # Just in case of problems, let's not hang Nagios
58: $SIG{'ALRM'} = sub {
59: print ("ERROR: No radius response from $hostname (alarm timeout)\n");
60: exit $ERRORS{"UNKNOWN"};
61: };
62: alarm($TIMEOUT);
63:
64:
65:
66: #Option checking
67: my $status = GetOptions(
68: "V" => \$opt_V, "version" => \$opt_V,
69: "h" => \$opt_h, "help" => \$opt_h,
70: "H=s" => \$hostname, "hostname=s" => \$hostname,
71: "s=s" => \$secret, "secret=s" => \$secret,
72: "P=i" => \$port, "port=i" => \$port,
73: "u=s" => \$user, "username=s" => \$user,
74: "p=s" => \$pwd, "password=s" => \$pwd,
75: "t=i" => \$timeout, "timeout=i"=> \$timeout,
76: );
77:
78: if ($status == 0)
79: {
80: print_help() ;
81: exit $ERRORS{'OK'};
82: }
83:
84:
85: if ($opt_V) {
1.2 ! andrew 86: print_revision($PROGNAME,'$Revision: 1.1.1.1 $ ');
1.1 andrew 87: exit $ERRORS{'OK'};
88: }
89:
90: if ($opt_h) {
91: print_help();
92: exit $ERRORS{'OK'};
93: }
94:
95: unless ($hostname && $secret && $user && $pwd) {
96: print_help();
97: exit $ERRORS{'OK'};
98: }
99:
100: if ($port) {
101: $hostname .= ":" . $port;
102: }
103:
104: use Authen::Radius;
105:
106: #print "Creating Client . . . ";
107: my $r = new Authen::Radius(Host => $hostname, Secret => $secret, Timeout => $timeout);
108: #print defined $r ? "" : "not ", "ok\n";
109:
110: unless (defined $r) {
111: done('UNKNOWN', "Couldn't create socket!");
112: }
113:
114:
115: $r->clear_attributes;
116:
117: $r->add_attributes (
118: { Name => 1, Value => $user, Type => 'string' }, # Username
119: { Name => 2, Value => $pwd, Type => 'string' }, # Password
120: { Name => 5, Value => '1', Type => 'integer' }, # NASPort
121: );
122:
123: #print "Authenticating . . .";
124: my $snt = $r->send_packet(ACCESS_REQUEST);
125: unless (defined $snt) {
126: done('CRITICAL', "Couldn't sent authentication packet: " . $r->strerror($r->get_error));
127: }
128:
129: $r->clear_attributes;
130:
131: my $rcv = $r->recv_packet();
132:
133: #print "" . (defined($rcv) and $rcv == ACCESS_ACCEPT) ? "" : "not ", "ok\n";
134:
135: unless (defined $rcv) {
136: done ('CRITICAL', "Didn't recieve valid response: " . $r->strerror($r->get_error));
137: }
138:
139: unless ($rcv == ACCESS_ACCEPT) {
140: done ('WARNING', "Access was denied for $user");
141: }
142:
143:
144: #my @a = $r->get_attributes;
145: #print "Attributes . . . ";
146: #print $#a != -1 ? "" : "not ", "ok\n";
147: #for $a (@a) {
148: # print "attr: name=$a->{'Name'} value=$a->{'Value'}\n";
149: #}
150:
151:
152: if ($state eq 'UNKNOWN') {
153: $state = 'OK';
154: $answer = "User $user authenticated correctly!";
155: }
156:
157: done($state, $answer);
158:
159: sub done
160: {
161: my $state = shift;
162: my $answer = shift;
163:
164: print "$state: ";
165: print $answer;
166: exit $ERRORS{$state};
167: }
168:
169: sub print_help {
170: printf "$PROGNAME plugin for Nagios monitors radius authentication\n";
171: printf " $PROGNAME -H <HOSTNAME> -u <USERNAME> -p <PASSWORD>\n";
172: printf "\nUsage:\n";
173: printf " -H (--hostname) Hostname to query (required)\n";
174: printf " -s (--secret) Radius Secret (required)\n";
175: printf " -P (--port) Radius auth port\n";
176: printf " -u (--username) Username to try authenticating (required)\n";
177: printf " -p (--password) Password to authenticate with (required)\n";
178: printf " -t (--timeout) Time to wait for response (defaults to 5 secs)\n";
179: printf " -h (--help) usage help \n\n";
1.2 ! andrew 180: print_revision($PROGNAME, '$Revision: 1.1.1.1 $');
1.1 andrew 181: }
182:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>