diff options
-rw-r--r-- | SiteSummary.pm | 25 | ||||
-rw-r--r-- | debian/changelog | 4 | ||||
-rw-r--r-- | sitesummary-collector.cgi | 16 | ||||
-rwxr-xr-x | sitesummary-nodes | 19 |
4 files changed, 44 insertions, 20 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 { diff --git a/debian/changelog b/debian/changelog index 38f2c38..5e5f00e 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,4 +1,4 @@ -sitesummary (0.0.74) UNRELEASED; urgency=low +sitesummary (0.0.74~test0) UNRELEASED; urgency=low * Add munin include dir to default munin config to match recent munin versions. @@ -7,6 +7,8 @@ sitesummary (0.0.74) UNRELEASED; urgency=low - Only check Linux software RAID if a RAID is enabled and not only when /proc/mdstat is present. - Report missing ldapsearch tool from check_ldap_root. + - Rewrite code to recognise a remote Nagios client to use host ID + to allow a Nagios server to be another Nagios servers client. * Collect /etc/lsb-release if present to have more detailed version information on Ubuntu. * Add suggests from sitesummary on ldap-utils and cups-client for diff --git a/sitesummary-collector.cgi b/sitesummary-collector.cgi index 06acf4c..5d3ddd1 100644 --- a/sitesummary-collector.cgi +++ b/sitesummary-collector.cgi @@ -11,6 +11,7 @@ use CGI; use POSIX qw(strftime); use Socket; use Sys::Syslog; +use SiteSummary; my $basedir = "/var/lib/sitesummary"; my $handlerdir = "/usr/lib/sitesummary/handler.d"; @@ -93,20 +94,7 @@ unlink $savefile; exit 0; sub extract_unique_id { - my $eth0mac; - my $eth1mac; - my $eth2mac; - open(IFCONFIG, "system/ifconfig-a") || die "Unable to read ifconfig-a"; - 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 get_unique_ether_id("system/ifconfig-a") || die "Unable to read ifconfig-a"; } sub process_entry { diff --git a/sitesummary-nodes b/sitesummary-nodes index e8695ac..7438e3d 100755 --- a/sitesummary-nodes +++ b/sitesummary-nodes @@ -9,6 +9,7 @@ use warnings; use SiteSummary; use Getopt::Std; use Socket; +use File::Temp qw(tempfile); sub usage { print <<EOF; @@ -21,7 +22,7 @@ Usage: $0 [-hmnw] EOF } -# Idea for way to provide overrides for the functions in this script +# Idea for way to provide overrides for the functions in this script #eval 'require "/etc/sitesummary/sitesummary-nodes-override"'; #if ($@ && $@ !~ qr{^Can't locate /etc/sitesummary/sitesummary-nodes-override}) { # die $@; @@ -31,6 +32,8 @@ my %opts; getopts("hmnw", \%opts) || (usage(), exit(1)); my %hostnames; +my $server_hostid = get_localhost_hostid() || + die "Unable to figure out hostid for the local host"; for_all_hosts(\&handle_host); @@ -60,6 +63,14 @@ sub print_list { } } +sub get_localhost_hostid { + my ($fh, $filename) = tempfile(); + `/sbin/ifconfig -a > $filename`; + my $localhost_hostid = get_unique_ether_id($filename); + unlink $filename; + return $localhost_hostid; +} + # Get an IP address, try to resolve it in DNS , and return the IP # address if no DNS reverse entry was found. sub get_dnsnameorip { @@ -107,10 +118,8 @@ sub print_ip_hw_list { sub is_remote_nagios_client { my $hostid = shift; - return is_pkg_installed($hostid, "nagios-nrpe-server") && ! - (is_pkg_installed($hostid, "nagios-text") || - is_pkg_installed($hostid, "nagios2") || - is_pkg_installed($hostid, "nagios3")); + return is_pkg_installed($hostid, "nagios-nrpe-server") && + $server_hostid ne $hostid; } # Return information about the switches connected to a given host, as |