File: [local] / nagios / check_rrd / bin / make_wireless_client_config (download)
Revision 1.7, Thu Dec 24 18:19:51 2009 UTC (14 years, 8 months ago) by andrew
Branch: MAIN
CVS Tags: HEAD Changes since 1.6: +42 -53 lines
check all clients seen within 90 days, not just those that are currently associated
|
#!/usr/bin/perl
# $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
# need for wireless clients.
#
# 2006.09.08 #*#*# andrew fresh <andrew@mad-techies.org>
########################################################################
use strict;
use warnings;
use Storable qw(lock_store lock_retrieve);
my $Only_Generate_Newer_Than = 90 * 24 * 60 * 60; # 90 days
my $TurboCell_Template = 'generic-host-wireless-karlnet-client';
my $Trango_Template = 'generic-host-wireless-trango-client';
my $file = shift || die "first argument needs to be name of file to process";
die "file '$file' does not exist" unless -e $file;
my $hosts = lock_retrieve($file) || die "Couldn't open '$file': $!";
my $now = time;
my $when = $now - $Only_Generate_Newer_Than;
my %nagios_hosts;
foreach my $alias ( sort keys %{$hosts} ) {
next if $alias =~ /[^[:print:]]/xms;
my $host = $hosts->{$alias};
next if $when > $host->{'Checked'};
$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;
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 $nagios_host = $AP . '-' . $id;
next if exists $nagios_hosts{$nagios_host};
$nagios_hosts{$nagios_host}++;
my $AP_uc = uc($AP);
#print $host, ": ", $AP, "-", $id, ": ",
# (scalar localtime($hosts->{$host}->{'Checked'})), "\n";
print <<EOL;
define host {
use $template
host_name $nagios_host
alias $alias
address $name
parents $AP_uc
}
EOL
}