version 1.6, 2007/10/03 16:16:42 |
version 1.7, 2009/12/24 18:19:51 |
|
|
#!/usr/bin/perl |
#!/usr/bin/perl |
# $RedRiver: make_wireless_client_config,v 1.5 2007/01/22 17:55:04 andrew Exp $ |
# $RedRiver: make_wireless_client_config,v 1.6 2007/10/03 15:16:42 andrew Exp $ |
######################################################################## |
######################################################################## |
# make_wireless_client_config *** Generate the Nagios config file we |
# make_wireless_client_config *** Generate the Nagios config file we |
# need for wireless clients. |
# need for wireless clients. |
# |
# |
# 2006.09.08 #*#*# andrew fresh <andrew@mad-techies.org> |
# 2006.09.08 #*#*# andrew fresh <andrew@mad-techies.org> |
######################################################################## |
######################################################################## |
use strict; |
use strict; |
|
|
|
|
use Storable qw(lock_store lock_retrieve); |
use Storable qw(lock_store lock_retrieve); |
|
|
my $Only_Generate_Newer_Than = 1 * 24 * 60 * 60; # 1 day |
my $Only_Generate_Newer_Than = 90 * 24 * 60 * 60; # 90 days |
my $TurboCell_Template = 'generic-host-wireless-karlnet-client'; |
my $TurboCell_Template = 'generic-host-wireless-karlnet-client'; |
my $Trango_Template = 'generic-host-wireless-trango-client'; |
my $Trango_Template = 'generic-host-wireless-trango-client'; |
|
|
|
|
|
|
my $hosts = lock_retrieve($file) || die "Couldn't open '$file': $!"; |
my $hosts = lock_retrieve($file) || die "Couldn't open '$file': $!"; |
|
|
#use Data::Dumper; |
|
#print Dumper $hosts; |
|
|
|
my $now = time; |
my $now = time; |
my $when = $now - $Only_Generate_Newer_Than; |
my $when = $now - $Only_Generate_Newer_Than; |
|
|
my %nagios_hosts; |
my %nagios_hosts; |
foreach my $AP (sort keys %{ $hosts }) { |
foreach my $alias ( sort keys %{$hosts} ) { |
next if $when > $hosts->{$AP}->{'Checked'}; |
next if $alias =~ /[^[:print:]]/xms; |
next unless $AP =~ /^rr\w{6}\d{4}$/i; |
|
|
|
my @clients; |
my $host = $hosts->{$alias}; |
push @clients, keys %{ $hosts->{$AP}->{'Info'}->{'suRemarks'} }; |
next if $when > $host->{'Checked'}; |
push @clients, keys %{ $hosts->{$AP}->{'Info'}->{'Wireless_Host_Name'} }; |
|
|
|
#print Dumper $AP, \@clients; |
$alias =~ s/^\s+|\s+$//gxms; |
|
my $name = $host->{'Host'}->{name}; |
|
next if !$name; |
|
next if !$name =~ / \A \d{1,3}\. \d{1,3}\. \d{1,3}\. \d{1,3} \z /xms; |
|
|
foreach my $id (sort @clients) { |
my ($id, $AP, $template); |
my $host; |
if ( $host->{'Host'}->{'Type'} =~ /Trango_Client$/ ) { |
my $name; |
$id = 'id_' . $host->{'Host'}->{ID}; |
my $template; |
$AP = $host->{'Info'}->{'Wireless_Host_Name'}->{id_0}; |
my $nagios_host; |
$template = $Trango_Template; |
|
} |
|
elsif ( $host->{'Host'}->{'Type'} =~ /TurboCell$/ ) { |
|
$id = $alias; |
|
$AP = $host->{'Info'}->{'Wireless_Host_Name'}->{id_1}; |
|
$template = $TurboCell_Template; |
|
} |
|
else { |
|
next; |
|
} |
|
|
if ($hosts->{$AP}->{'Host'}->{'Type'} =~ /Trango$/) { |
next if !$AP; |
$host = $hosts->{$AP}->{'Info'}->{'suRemarks'}->{$id}; |
next if $AP !~ /^rr\w{6}\d{4}/ixms; |
$name = $hosts->{$host}->{'Host'}->{'name'}; |
|
$nagios_host = $AP . '-' . $id; |
|
$template = $Trango_Template; |
|
} elsif ($hosts->{$AP}->{'Host'}->{'Type'} =~ /TurboCell$/) { |
|
$host = $hosts->{$AP}->{'Info'}->{'Wireless_Host_Name'}->{$id}; |
|
$name = $hosts->{$host}->{'Host'}->{'name'}; |
|
$nagios_host = $AP . '-' . $host; |
|
$template = $TurboCell_Template; |
|
} else { |
|
next; |
|
} |
|
|
|
next if ! $host; |
my $nagios_host = $AP . '-' . $id; |
next if $host =~ /^rr\w{6}\d{4}$/i; |
next if exists $nagios_hosts{$nagios_host}; |
|
$nagios_hosts{$nagios_host}++; |
|
|
next if ! $name; |
my $AP_uc = uc($AP); |
#next if ! $name =~ / \A \d{1,3}\. \d{1,3}\. \d{1,3}\. \d{1,3} \z /xms |
|
|
|
next if exists $nagios_hosts{$nagios_host}; |
#print $host, ": ", $AP, "-", $id, ": ", |
$nagios_hosts{$nagios_host}++; |
# (scalar localtime($hosts->{$host}->{'Checked'})), "\n"; |
|
|
my $AP_uc = uc($AP); |
print <<EOL; |
|
|
#print $host, ": ", $AP, "-", $id, ": ", |
|
# (scalar localtime($hosts->{$host}->{'Checked'})), "\n"; |
|
|
|
print <<EOL; |
|
define host { |
define host { |
use $template |
use $template |
host_name $nagios_host; |
host_name $nagios_host |
alias $host |
alias $alias |
address $name |
address $name |
parents $AP_uc |
parents $AP_uc |
} |
} |
EOL |
EOL |
|
|
} |
|
|
|
} |
} |