diff options
author | Petter Reinholdtsen <pere@hungry.com> | 2011-12-17 14:47:55 +0000 |
---|---|---|
committer | Petter Reinholdtsen <pere@hungry.com> | 2011-12-17 14:47:55 +0000 |
commit | 3e7133117f4cf3c3ad2823610b255416f9beaefe (patch) | |
tree | 3aa43c592488c180b8acc189471beb1c8bd1beeb | |
parent | 120798867d5fed900dec9f17c13e361f49101cc4 (diff) | |
download | sitesummary-3e7133117f4cf3c3ad2823610b255416f9beaefe.tar.gz sitesummary-3e7133117f4cf3c3ad2823610b255416f9beaefe.tar.bz2 sitesummary-3e7133117f4cf3c3ad2823610b255416f9beaefe.tar.xz |
Add support for hostmap.d/ and comments.
-rw-r--r-- | README | 8 | ||||
-rw-r--r-- | SiteSummary.pm | 28 |
2 files changed, 26 insertions, 10 deletions
@@ -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 { |