[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.1, Fri Jan 12 15:58:34 2007 UTC (17 years, 5 months ago) by andrew
Branch: MAIN

a script to generate the nagios configs for wireless clients

#!/usr/bin/perl
# $RedRiver$
########################################################################
# 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;

foreach my $host (keys %{ $hosts }) {
	next if $when > $hosts->{$host}->{'Checked'};
	next if $host =~ /^rr\w{6}\d{4}$/i;

	my $server;
	my $id;
	my $name;
	my $template;

	if ($hosts->{$host}->{'Host'}->{'Type'} =~ /Trango_Client$/) {
		$server = $hosts->{$host}->{'Info'}->{'Wireless_Host_Name'}->{'id_0'};
		$id     = 'id_' . $hosts->{$host}->{'Host'}->{'ID'};
		$name   = $hosts->{$host}->{'Host'}->{'name'};
		$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;


	#print $host, ": ", $server, "-", $id, ": ", 
	#	(scalar localtime($hosts->{$host}->{'Checked'})), "\n";

	print <<EOL;
define host {
	use        $template
	host_name  ${server}-${id}
	alias      $host
	address    $name
}
EOL

}