#!/usr/bin/perl # $RedRiver: make_wireless_client_config,v 1.4 2007/01/22 16:40:52 andrew Exp $ ######################################################################## # make_wireless_client_config *** Generate the Nagios config file we # need for wireless clients. # # 2006.09.08 #*#*# andrew fresh ######################################################################## use strict; use warnings; use Storable qw(lock_store lock_retrieve); my $Only_Generate_Newer_Than = 1 * 24 * 60 * 60; # 1 day 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': $!"; #use Data::Dumper; #print Dumper $hosts; my $now = time; my $when = $now - $Only_Generate_Newer_Than; my %nagios_hosts; foreach my $AP (sort keys %{ $hosts }) { next if $when > $hosts->{$AP}->{'Checked'}; next unless $AP =~ /^rr\w{6}\d{4}$/i; my @clients; push @clients, keys %{ $hosts->{$AP}->{'Info'}->{'suRemarks'} }; push @clients, keys %{ $hosts->{$AP}->{'Info'}->{'Wireless_Host_Name'} }; #print Dumper $AP, \@clients; foreach my $id (@clients) { my $host; my $name; my $template; my $nagios_host; if ($hosts->{$AP}->{'Host'}->{'Type'} =~ /Trango$/) { $host = $hosts->{$AP}->{'Info'}->{'suRemarks'}->{$id}; $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 unless $host; next if $host =~ /^rr\w{6}\d{4}$/i; 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 <