#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";
# 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";
{
my @hosts= <IFILE>;
- 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:
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";
# 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";
}
# 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";