From 288e207f19c8bcea6e73867a39637152694e60af Mon Sep 17 00:00:00 2001 From: Petter Reinholdtsen Date: Sat, 23 Jan 2010 04:11:08 +0000 Subject: Use switch information collected using cdpr to specify Nagios host parent relationships. --- debian/changelog | 2 ++ nagios-templates.cfg | 11 +++++++++++ sitesummary-nodes | 50 ++++++++++++++++++++++++++++++++++++++++++++++---- 3 files changed, 59 insertions(+), 4 deletions(-) diff --git a/debian/changelog b/debian/changelog index a626777..445d76f 100644 --- a/debian/changelog +++ b/debian/changelog @@ -5,6 +5,8 @@ sitesummary (0.0.57~svn61900) UNRELEASED; urgency=low * Correct nagios documentation in the README. * Add Vcs-Browser and Vcs-Svn entries in control file. + * Use switch information collected using cdpr to specify Nagios + host parent relationships. -- Petter Reinholdtsen Thu, 21 Jan 2010 20:21:50 +0100 diff --git a/nagios-templates.cfg b/nagios-templates.cfg index 4fdd2fb..797b56e 100644 --- a/nagios-templates.cfg +++ b/nagios-templates.cfg @@ -66,6 +66,12 @@ define host { contact_groups admins } +define host { + use server-host + name switch-host + check_command check-host-none +} + define service { name server-service is_volatile 0 @@ -202,6 +208,11 @@ define command{ command_line /usr/lib/nagios/plugins/check_ping -H $HOSTADDRESS$ -w 5000,100% -c 5000,100% -p 1 } +define command{ + command_name check-host-none + command_line /bin/echo Switch hosts are not checked +} + define command{ command_name check_nrpe command_line /usr/lib/nagios/plugins/check_nrpe -H $HOSTADDRESS$ -c $ARG1$ diff --git a/sitesummary-nodes b/sitesummary-nodes index 73979bb..ab4b24a 100755 --- a/sitesummary-nodes +++ b/sitesummary-nodes @@ -113,6 +113,36 @@ sub is_remote_nagios_client { is_pkg_installed($hostid, "nagios3")); } +# Return information about the switches connected to a given host, as +# reported by cdpr (and perhaps lldp in the future?) +sub get_switch_info { + my $hostid = shift; + my %switch = (); + for my $if (qw(eth0 eth1)) { + my $path = get_filepath_current($hostid, "/system/cdpr.$if"); + my ($id, $addr); + if (open(my $fh, $path)) { + while (<$fh>) { + chomp; + if (m/^Device ID$/) { + $id = <$fh>; + chomp $id; + $id =~ s/^\s+value:\s+(\S)\s*/$1/; + } + if (m/^Addresses$/) { + $addr = <$fh>; + chomp $addr; + $addr =~ s/^\s+value:\s+(\S)\s*/$1/; + $switch{$addr} = $id; + } + } + close($fh); + } + } + return %switch ? %switch : (); +} + + sub is_remote_nrpe_config_active { my $hostid = shift; @@ -173,8 +203,8 @@ EOF } sub print_nagios_host_check { - my ($hostname, $address, @hostgroups) = @_; - my $template = "server-host"; + my ($template, $hostname, $address, $parent, @hostgroups) = @_; + $template = $template || "server-host"; print <