diff options
author | Petter Reinholdtsen <pere@hungry.com> | 2008-06-11 19:52:49 +0000 |
---|---|---|
committer | Petter Reinholdtsen <pere@hungry.com> | 2008-06-11 19:52:49 +0000 |
commit | 6c7beec7b53211366189c0b2e4b4d8aa4640ff87 (patch) | |
tree | 1c19f29a6254f5d97ee5a10f45e76bc898879520 /sitesummary-nodes | |
parent | fe66a3c40d852c0ad397f0fc54208ca50007e264 (diff) | |
download | sitesummary-6c7beec7b53211366189c0b2e4b4d8aa4640ff87.tar.gz sitesummary-6c7beec7b53211366189c0b2e4b4d8aa4640ff87.tar.bz2 sitesummary-6c7beec7b53211366189c0b2e4b4d8aa4640ff87.tar.xz |
* New argument -w to sitesummary-nodes, to list DNS name and MAC address,
for use with wakeonlan packages.
Diffstat (limited to 'sitesummary-nodes')
-rwxr-xr-x | sitesummary-nodes | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/sitesummary-nodes b/sitesummary-nodes index 1cc8741..cc0b376 100755 --- a/sitesummary-nodes +++ b/sitesummary-nodes @@ -10,7 +10,7 @@ use SiteSummary; use Getopt::Std; my %opts; -getopts("mn", \%opts); +getopts("mnw", \%opts); my %hostnames; @@ -18,11 +18,14 @@ for_all_hosts(\&handle_host); if ($opts{'m'}) { print_munin_list(); +} elsif ($opts{'w'}) { + print_ip_hw_list(); } elsif ($opts{'n'}) { # XXX Nagios config generation do not work yet generate_nagios_config(); } else { print_list(); } +exit 0; sub handle_host { my $hostid = shift; @@ -81,6 +84,33 @@ EOF } } +sub get_primary_macaddress { + my $hostid = shift; + my $path = get_filepath_current($hostid, "/system/ifconfig-a"); + # XXX Not properly implemented, just pick the first interface + my $macaddress; + if (open (FILE, $path)) { + while(<FILE>) { + chomp; + if (m/Link encap:Ethernet\s+HWaddr (\S+)\s+/) { + $macaddress = $1; + last; + } + } + close(FILE); + return $macaddress; + } else { + return undef; + } +} + +sub print_ip_hw_list { + for my $hostname (sort keys %hostnames) { + my $macaddress = get_primary_macaddress($hostnames{$hostname}); + print "$hostname $macaddress\n"; + } +} + sub generate_nagios_config { for my $hostname (sort keys %hostnames) { my $hostid = $hostnames{$hostname}; |