diff options
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}; |