diff options
author | Petter Reinholdtsen <pere@hungry.com> | 2011-12-24 05:27:58 +0000 |
---|---|---|
committer | Petter Reinholdtsen <pere@hungry.com> | 2011-12-24 05:27:58 +0000 |
commit | dd16d2508f8660cd55abe365ffc0a232c487100c (patch) | |
tree | be1ed09d7781cf1d6e7a22e447e6982d88b0ff50 /SiteSummary.pm | |
parent | 42459853003bd47a1e4eeb5fc85874a8222637b0 (diff) | |
download | sitesummary-dd16d2508f8660cd55abe365ffc0a232c487100c.tar.gz sitesummary-dd16d2508f8660cd55abe365ffc0a232c487100c.tar.bz2 sitesummary-dd16d2508f8660cd55abe365ffc0a232c487100c.tar.xz |
Rewrite code to recognise a remote Nagios client to use host ID
to allow a Nagios server to be another Nagios servers client.
Diffstat (limited to 'SiteSummary.pm')
-rw-r--r-- | SiteSummary.pm | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/SiteSummary.pm b/SiteSummary.pm index 53b3c50..c8fa9c7 100644 --- a/SiteSummary.pm +++ b/SiteSummary.pm @@ -24,6 +24,7 @@ our @EXPORT = qw( get_macaddresses get_primary_ip_address get_primary_macaddress + get_unique_ether_id get_site get_sitegroup is_laptop @@ -198,6 +199,30 @@ sub get_primary_macaddress { } # +# Given the output from 'ifconfig -a', return the unique host ID used +# by sitesummary. +# Use like this: +# get_unique_ether_id(get_file_string($hostid, "/system/ifconfig-a")) +# +sub get_unique_ether_id { + my $ifconfigoutput = shift; + my $eth0mac; + my $eth1mac; + my $eth2mac; + open(IFCONFIG, $ifconfigoutput) || return undef; + while (<IFCONFIG>) { + chomp; + $eth0mac = $1 if (m/^eth0\s+Link encap:Ethernet HWaddr (\S+)/); + $eth1mac = $1 if (m/^eth1\s+Link encap:Ethernet HWaddr (\S+)/); + $eth2mac = $1 if (m/^eth2\s+Link encap:Ethernet HWaddr (\S+)/); + } + close (IFCONFIG); + #print STDERR "MAC: $eth0mac\n"; + my $mac = $eth0mac || $eth1mac || $eth2mac || "unknown"; + return lc("ether-$mac"); +} + +# # Return the hostname string # sub get_hostname { |