--- /dev/null
+#!/usr/bin/perl -w
+
+# dbl2dabc V0.1
+# convert etrax nodes from daq config to icinga hosts config file
+# v0.1: 15-Feb-2012 Joern Adamczewski-Musch, gsi
+#
+
+use English;
+use strict;
+use Getopt::Long;
+use FileHandle;
+use File::Path;
+use File::Basename;
+#use String::Scanf;
+
+
+
+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";
+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:
+
+print OUTFILE "###############################################################################\n";
+print OUTFILE "# Config File for Monitoring etrax nodes\n";
+print OUTFILE "#\n";
+print OUTFILE "# HOST DEFINITIONS\n";
+print OUTFILE "###############################################################################\n";
+
+
+foreach my $component(@subsystems)
+{
+ my $inputfile="$daqpath$component/$dbfile";
+ print " processing $inputfile ... \n";
+ my @validnodes;
+ my $rev=open( IFILE, '<', $inputfile);
+ if(!$rev)
+ {
+ # we do not have file, just set empty number with template:
+ print "Could not open $inputfile .\n";
+ }
+ else
+ {
+
+ my @hosts= <IFILE>;
+ my $numlongs = $#hosts + 1;
+ print "Using $numlongs entries from file $inputfile\n";
+ @hosts = sort @hosts;
+ foreach my $line (@hosts) {
+ #ignore comments:
+ #- Remove all comments and whitespace:
+ next if ($line =~ /^\s*($|#)/);
+
+ # first define the host
+
+ my @larray=split(/\s+/,$line);
+ my $nodename=$larray[1];
+ my $cid=$larray[0];
+ print "Found node $nodename of component $cid\n";
+ push(@validnodes, $nodename);
+ print OUTFILE "\n\# HOST DEFINITION $nodename \n";
+ print OUTFILE "define host{\n";
+ print OUTFILE " use etrax\n";
+ my $hdef = sprintf(" host_name %s \; assigned to %s \n",$nodename,$cid);
+ print OUTFILE $hdef;
+ my $adef = sprintf(" alias %s_%s \n",$nodename,$cid);
+ print OUTFILE $adef;
+ # to do: figure out ip from hostname
+# $ip= sscanf("etraxp%d", $nodename);
+# print "Found ip adress $ip \n";
+# my fullip=sprintf("address 192.168.101.%d\n",$ip);
+# print OUTFILE $fullip;
+ print OUTFILE "}\n";
+ }
+
+
+
+
+
+
+ # define hostgroup for this file
+ if($#validnodes>0)
+ {
+ #sort(@validnodes);
+ print OUTFILE "define hostgroup{\n";
+ print OUTFILE " hostgroup_name $component \n";
+ print OUTFILE " alias etrax_$component\n";
+ my $members = join(",", @validnodes);
+ print OUTFILE " members $members \n";
+ print OUTFILE "}\n";
+ }
+ close(IFILE) || die "Couldn't close file $inputfile properly";
+
+ }
+
+}
+# define hostgroup of all components:
+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
+
+
+
+close(OUTFILE) || die "Couldn't close file $icinga_config_file properly";
+
+print "\tdone.\n";