Title: [opsview] [9975] MRTG duplicate IP address warnings
- Revision
- 9975
- Author
- dferguson
- Date
- 2012-09-06 15:40:30 +0100 (Thu, 06 Sep 2012)
Log Message
MRTG duplicate IP address warnings
Where hosts have MRTG enabled, check to ensure thre are no duplicate IP addresses between those hosts, else MRTG will fail to collect the data.
Modified Paths
Modified: trunk/CHANGES
===================================================================
--- trunk/CHANGES 2012-09-06 14:27:31 UTC (rev 9974)
+++ trunk/CHANGES 2012-09-06 14:40:30 UTC (rev 9975)
@@ -6,6 +6,7 @@
ENHANCEMENTS:
REST API for listing currently running monitoring servers
Remove some specified words from device interface ifDescr information to reduce instances of duplicate interface ids being used (level 3 added)
+ Warnings on multiple hosts using same IP when hosts are configured for MRTG
NOTICES:
Removed runtime.opsview_monitoringclusters, which was not used
FIXES:
Modified: trunk/opsview-core/bin/nagconfgen.pl
===================================================================
--- trunk/opsview-core/bin/nagconfgen.pl 2012-09-06 14:27:31 UTC (rev 9974)
+++ trunk/opsview-core/bin/nagconfgen.pl 2012-09-06 14:40:30 UTC (rev 9975)
@@ -477,11 +477,43 @@
$hostname_lookup->{ $host->name }++;
}
+ my $hostip_lookup = {};
+ my %seen;
+
foreach my $host (@hosts) {
my @parents =
map { $hostname_lookup->{ $_->name } ? $_->name : () }
( @{ $parents_lookup->{ $host->id } } );
+ # Lookup and cache host IP's for checking potential
+ # MRTG configuration errors
+ if ( $host->use_mrtg ) {
+ my $hostips;
+ if ( exists $seen{ $host->id } ) {
+ $hostips = $seen{ $host->id };
+ }
+ else {
+ $hostips = $host->hostip;
+ $seen{ $host->id } = $hostips;
+ unless (@$hostips) {
+ warn(
+ "Unable to lookup IP address for '"
+ . $host->name . "' ("
+ . $host->ip
+ . ") - ignoring MRTG configuration for this host"
+ );
+
+ # Keep previous behaviour when unable to look up IP's
+ #next;
+ }
+ else {
+ foreach my $h (@$hostips) {
+ push @{ $hostip_lookup->{$h} }, $host->name;
+ }
+ }
+ }
+ }
+
my $hostgroup = $host->hostgroup;
my $hgname = $hostgroup->name;
if ( !exists $configuration_cache_data->{hostgroups}->{$hgname} ) {
@@ -594,6 +626,20 @@
$c++;
}
close OUTFILE;
+
+ # Remove duplicate hostnames for each hostip
+ foreach my $hostip ( keys %$hostip_lookup ) {
+ my %hostname;
+ map { $hostname{$_} = 1 } @{ $hostip_lookup->{$hostip} };
+ $hostip_lookup->{$hostip} = [ sort keys %hostname ];
+
+ # Warnings if more than one Nagios hostname for a single IP
+ warn(
+ "IP $hostip has more than 1 host associated with it for use with MRTG: "
+ . join( ", ", sort( keys(%hostname) ) ) )
+ if ( scalar keys %hostname > 1 );
+ }
+
plog "$c hosts written to hosts.cfg";
}
Modified: trunk/opsview-core/lib/Opsview/Schema/Hosts.pm
===================================================================
--- trunk/opsview-core/lib/Opsview/Schema/Hosts.pm 2012-09-06 14:27:31 UTC (rev 9974)
+++ trunk/opsview-core/lib/Opsview/Schema/Hosts.pm 2012-09-06 14:40:30 UTC (rev 9975)
@@ -1011,7 +1011,7 @@
}
else {
$snmp_auth =
- "-v "
+ "-v "
. $self->snmp_version . " -C "
. (
Opsview::Utils->make_shell_friendly(
@@ -1218,7 +1218,7 @@
}
else {
$snmp_auth =
- "-v "
+ "-v "
. $self->snmp_version . " -C "
. (
Opsview::Utils->make_shell_friendly(
@@ -1349,4 +1349,34 @@
};
}
+=item $self->hostip( $address )
+
+Uses $address if specified, otherwise $self->ip.
+
+Returns an array ref of ip addresses for this host, as resolved by gethostbyname(3). Returns
+an empty array ref if unable to resolve it correctly.
+
+=cut
+
+sub hostip {
+ my ( $self, $address ) = @_;
+ use Net::hostent;
+ use Socket;
+ $address = $self->ip unless defined $address;
+
+ if ( $address =~ /^\d+\.\d+\.\d+\.\d+$/ ) {
+ return [$address];
+ }
+
+ $_ = Net::hostent::gethost($address);
+ unless ($_) {
+ return [];
+ }
+ my @addresses = ();
+ for my $addr ( @{ $_->addr_list } ) {
+ push @addresses, inet_ntoa($addr);
+ }
+ return \@addresses;
+}
+
1;
_______________________________________________
Opsview-checkins mailing list
[email protected]
http://lists.opsview.org/lists/listinfo/opsview-checkins