From d712a708b08f6136b44901fd8a7d877d50d04f72 Mon Sep 17 00:00:00 2001 From: hadaq Date: Thu, 16 Feb 2012 09:04:21 +0000 Subject: [PATCH] JAM: improved daq2icinga. filter out duplicate nodes. still under development. --- icinga/objects/daq2icinga.pl | 45 +++++++++++++++++++++++------------- 1 file changed, 29 insertions(+), 16 deletions(-) diff --git a/icinga/objects/daq2icinga.pl b/icinga/objects/daq2icinga.pl index f359025..6dfe5c1 100755 --- a/icinga/objects/daq2icinga.pl +++ b/icinga/objects/daq2icinga.pl @@ -14,12 +14,12 @@ use File::Basename; #use String::Scanf; - +my $icinga_config_file = "./hosts_etrax.cfg"; my $daqpath = "/home/hadaq/trbsoft/daq/"; my $dbfile = "trb.db"; my @subsystems = ("cts","mdc","start","tof","rpc","shower"); - -my $icinga_config_file = "./hosts_etrax.cfg"; +my @totalsystems; +my @totalnodes; open( OUTFILE, '>', $icinga_config_file ) or die "Could not open $icinga_config_file: $! \n"; print "Generating icinga config file $icinga_config_file ...\n"; @@ -27,9 +27,14 @@ print "Generating icinga config file $icinga_config_file ...\n"; # first provide output file with standard header: + my ($sec, $min, $hr, $day, $mon, $year) = localtime; +my $timestamp= sprintf("%02d.%02d.%04d at %02d:%02d:%02d",$day, $mon + 1, 1900 + $year, $hr, $min, $sec); + print OUTFILE "###############################################################################\n"; print OUTFILE "# Config File for Monitoring etrax nodes\n"; +print OUTFILE "# This file was automatically generated from trb.db files by daq2icinga.pl\n"; +print OUTFILE "# Creation time: $timestamp\n"; print OUTFILE "#\n"; print OUTFILE "# HOST DEFINITIONS\n"; print OUTFILE "###############################################################################\n"; @@ -50,8 +55,11 @@ foreach my $component(@subsystems) { my @hosts= ; - my $numlongs = $#hosts + 1; - print "Using $numlongs entries from file $inputfile\n"; +# my $numlongs = $#hosts + 1; +# print "Using $numlongs entries from file $inputfile\n"; + print OUTFILE "\n###############################################################################\n"; + print OUTFILE "# Hosts from subcomponent $component\n"; + print OUTFILE "###############################################################################\n"; @hosts = sort @hosts; foreach my $line (@hosts) { #ignore comments: @@ -64,7 +72,13 @@ foreach my $component(@subsystems) my $nodename=$larray[1]; my $cid=$larray[0]; print "Found node $nodename of component $cid\n"; + if (grep {$_ eq $nodename} @totalnodes) + { + print "!!!! WARNING: found duplicate node $nodename in $inputfile! Skipped.\n"; + next; + } push(@validnodes, $nodename); + push(@totalnodes, $nodename); print OUTFILE "\n\# HOST DEFINITION $nodename \n"; print OUTFILE "define host{\n"; print OUTFILE " use etrax\n"; @@ -86,9 +100,9 @@ foreach my $component(@subsystems) # define hostgroup for this file - if($#validnodes>0) + if($#validnodes>=0) { - #sort(@validnodes); + push(@totalsystems, $component); print OUTFILE "define hostgroup{\n"; print OUTFILE " hostgroup_name $component \n"; print OUTFILE " alias etrax_$component\n"; @@ -102,16 +116,15 @@ foreach my $component(@subsystems) } # define hostgroup of all components: +print OUTFILE "\n\n###############################################################################\n"; +print OUTFILE "# Hostgroup definition for all nodes\n"; +print OUTFILE "###############################################################################\n"; print OUTFILE "define hostgroup{\n"; - print OUTFILE " hostgroup_name etrax \n"; - print OUTFILE " alias all etrax nodes\n"; - my $groupmembers = join(",", @subsystems); - print OUTFILE " hostgroup_members $groupmembers \n"; - print OUTFILE "}\n"; - -#provide footer - - +print OUTFILE " hostgroup_name etrax \n"; +print OUTFILE " alias all etrax nodes\n"; +my $groupmembers = join(",", @totalsystems); +print OUTFILE " hostgroup_members $groupmembers \n"; +print OUTFILE "}\n"; close(OUTFILE) || die "Couldn't close file $icinga_config_file properly"; -- 2.43.0