version 1.2, 2007/01/12 21:55:08 |
version 1.7, 2009/12/24 18:19:51 |
|
|
#!/usr/bin/perl |
#!/usr/bin/perl |
# $RedRiver: make_wireless_client_config,v 1.1 2007/01/12 15:58:34 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; |
|
|
foreach my $host (keys %{ $hosts }) { |
my %nagios_hosts; |
next if $when > $hosts->{$host}->{'Checked'}; |
foreach my $alias ( sort keys %{$hosts} ) { |
next if $host =~ /^rr\w{6}\d{4}$/i; |
next if $alias =~ /[^[:print:]]/xms; |
|
|
my $server; |
my $host = $hosts->{$alias}; |
my $id; |
next if $when > $host->{'Checked'}; |
my $name; |
|
my $template; |
|
|
|
if ($hosts->{$host}->{'Host'}->{'Type'} =~ /Trango_Client$/) { |
$alias =~ s/^\s+|\s+$//gxms; |
$server = $hosts->{$host}->{'Info'}->{'Wireless_Host_Name'}->{'id_0'}; |
my $name = $host->{'Host'}->{name}; |
$id = 'id_' . $hosts->{$host}->{'Host'}->{'ID'}; |
next if !$name; |
$name = $hosts->{$host}->{'Host'}->{'name'}; |
next if !$name =~ / \A \d{1,3}\. \d{1,3}\. \d{1,3}\. \d{1,3} \z /xms; |
$template = $Trango_Template; |
|
} elsif ($hosts->{$host}->{'Host'}->{'Type'} =~ /TurboCell$/) { |
|
$server = $hosts->{$host}->{'Host'}->{'comment'}; |
|
$id = $host; |
|
$name = $hosts->{$host}->{'Host'}->{'name'}; |
|
$template = $TurboCell_Template; |
|
} else { |
|
next; |
|
} |
|
|
|
next unless $server && $id; |
my ($id, $AP, $template); |
|
if ( $host->{'Host'}->{'Type'} =~ /Trango_Client$/ ) { |
|
$id = 'id_' . $host->{'Host'}->{ID}; |
|
$AP = $host->{'Info'}->{'Wireless_Host_Name'}->{id_0}; |
|
$template = $Trango_Template; |
|
} |
|
elsif ( $host->{'Host'}->{'Type'} =~ /TurboCell$/ ) { |
|
$id = $alias; |
|
$AP = $host->{'Info'}->{'Wireless_Host_Name'}->{id_1}; |
|
$template = $TurboCell_Template; |
|
} |
|
else { |
|
next; |
|
} |
|
|
|
next if !$AP; |
|
next if $AP !~ /^rr\w{6}\d{4}/ixms; |
|
|
my $server_uc = uc($server); |
my $nagios_host = $AP . '-' . $id; |
|
next if exists $nagios_hosts{$nagios_host}; |
|
$nagios_hosts{$nagios_host}++; |
|
|
#print $host, ": ", $server, "-", $id, ": ", |
my $AP_uc = uc($AP); |
# (scalar localtime($hosts->{$host}->{'Checked'})), "\n"; |
|
|
|
print <<EOL; |
#print $host, ": ", $AP, "-", $id, ": ", |
|
# (scalar localtime($hosts->{$host}->{'Checked'})), "\n"; |
|
|
|
print <<EOL; |
define host { |
define host { |
use $template |
use $template |
host_name ${server}-${id} |
host_name $nagios_host |
alias $host |
alias $alias |
address $name |
address $name |
parents $server_uc |
parents $AP_uc |
} |
} |
EOL |
EOL |
|
|