[BACK]Return to make_wireless_client_config CVS log [TXT][DIR] Up to [local] / nagios / check_rrd / bin

File: [local] / nagios / check_rrd / bin / make_wireless_client_config (download)

Revision 1.4, Mon Jan 22 16:40:52 2007 UTC (17 years, 5 months ago) by andrew
Branch: MAIN
Changes since 1.3: +44 -32 lines

Look to see who is associated, not who was seen at some point.

#!/usr/bin/perl
# $RedRiver: make_wireless_client_config,v 1.3 2007/01/13 00:04:51 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 = 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 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      $host
	address    $name
	parents    $AP_uc
}
EOL

	}

}