aboutsummaryrefslogtreecommitdiffstats
path: root/sitesummary-nodes
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 /sitesummary-nodes
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.
Diffstat (limited to 'sitesummary-nodes')
-rwxr-xr-xsitesummary-nodes50
1 files changed, 46 insertions, 4 deletions
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;