aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPetter Reinholdtsen <pere@hungry.com>2010-01-23 04:11:08 +0000
committerPetter Reinholdtsen <pere@hungry.com>2010-01-23 04:11:08 +0000
commit288e207f19c8bcea6e73867a39637152694e60af (patch)
treebd4ad16752c64396fa5e6701fc9862c9aa8a3e43
parentd6a04c6db6948067c34507c0e44a410c72c7f402 (diff)
downloadsitesummary-288e207f19c8bcea6e73867a39637152694e60af.tar.gz
sitesummary-288e207f19c8bcea6e73867a39637152694e60af.tar.bz2
sitesummary-288e207f19c8bcea6e73867a39637152694e60af.tar.xz
Use switch information collected using cdpr to specify Nagios
host parent relationships.
-rw-r--r--debian/changelog2
-rw-r--r--nagios-templates.cfg11
-rwxr-xr-xsitesummary-nodes50
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 <pere@debian.org> 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
@@ -203,6 +209,11 @@ define command{
}
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 <<EOF;
##################### $hostname #######################
define host {
@@ -182,6 +212,7 @@ define host {
host_name $hostname
address $address
EOF
+ print " parents $parent\n" if ($parent);
if (@hostgroups) {
print " hostgroups " . join(",", @hostgroups), "\n";
}
@@ -223,14 +254,25 @@ sub generate_nagios_config {
# Also check default route host
if (defined $defaultroute && !exists $hosts{$defaultroute}) {
- print_nagios_host_check($defaultroute, $defaultroute, "site-none");
+ print_nagios_host_check(undef, $defaultroute, $defaultroute,
+ undef, "site-none");
$hosts{$defaultroute} = $defaultroute;
$hostgroup{"site-none"} = 1;
print_nagios_service_check(0, $defaultroute, "ping",
"check_ping", "100.0,20%!500.0,60%");
}
- print_nagios_host_check($hostname, $address, @groups)
+ my %switch = get_switch_info($hostid);
+ my @parents = ();
+ for my $addr (keys %switch) {
+ print_nagios_host_check("switch-host", $switch{$addr}, $addr, undef)
+ unless (exists $hosts{$switch{$addr}});
+ $hosts{$switch{$addr}} = $addr;
+ push(@parents, $switch{$addr});
+ }
+
+ print_nagios_host_check(undef, $hostname, $address,
+ join(",", @parents), @groups)
unless (exists $hosts{$hostname});
$hosts{$hostname} = $address;