aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--README8
-rw-r--r--SiteSummary.pm28
2 files changed, 26 insertions, 10 deletions
diff --git a/README b/README
index e0be004..4d89049 100644
--- a/README
+++ b/README
@@ -77,10 +77,16 @@ To handle hosts with hostnames missing in DNS or IP adresses not
available directly from the Nagios and Munin server, a mechanism to
map entries to new hostnames is provided.
-To enable it, create a file /etc/sitesummary/hostmap with content like this
+To enable it, create a file /etc/sitesummary/hostmap or a file in
+/etc/sitesummary/hostmap.d/ with content like this
ether-AA:BB:CC:DD:EE:FF new-name
+Empty lines are ignored. The # character indicate the start of a
+comment. Entries in /etc/sitesummary/hostmap.d/ override entries in
+/etc/sitesummary/hostmap, and the entries in hostmap.d/ are read in
+alphabetic order, where the last entry take effect.
+
The ether-* name is the host entry name from
/var/lib/sitesummary/entries/, and the new-name entry is the hostname
to use instead of the value in system/hostname.
diff --git a/SiteSummary.pm b/SiteSummary.pm
index 43d459d..53b3c50 100644
--- a/SiteSummary.pm
+++ b/SiteSummary.pm
@@ -39,20 +39,30 @@ my $debian_edu_config = "/debian-edu/config";
# available via tunnels.
my $hostmapfile = "/etc/sitesummary/hostmap";
+my $hostmapdir = "/etc/sitesummary/hostmap.d";
my %hostmap;
sub load_hostmap {
- if (open(my $fh, '<', $hostmapfile)) {
- %hostmap = (); # Clear hostmap
- while (<$fh>) {
- chomp;
- my ($hostid, $newhostname) = split(/\s+/);
- $hostmap{$hostid} = $newhostname;
+ my @files = ($hostmapfile);
+ %hostmap = (); # Clear hostmap
+
+ if (opendir(my $dh, $hostmapdir)) {
+ push(@files, grep { /^\./ && -f "$some_dir/$_" } sort readdir($dh));
+ closedir $dh;
+ }
+ for my $file (@files) {
+ if (open(my $fh, '<', $file)) {
+ while (<$fh>) {
+ chomp;
+ s/\#.*$//;
+ next if m/^\s*$/;
+ my ($hostid, $newhostname) = split(/\s+/);
+ $hostmap{$hostid} = $newhostname;
+ }
+ close $fh;
}
- close $fh;
- } else {
- return;
}
+ return;
}
sub get_filepath_current {