aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPetter Reinholdtsen <pere@hungry.com>2010-01-20 13:43:46 +0000
committerPetter Reinholdtsen <pere@hungry.com>2010-01-20 13:43:46 +0000
commit4e0fe49629a9e8045518e02139522a123816252b (patch)
tree9752a360db657308d98d79e09e0b41475d67f9e7
parent8305f7c86e175f1e6c5ccc2e58dce938457d3778 (diff)
downloadsitesummary-4e0fe49629a9e8045518e02139522a123816252b.tar.gz
sitesummary-4e0fe49629a9e8045518e02139522a123816252b.tar.bz2
sitesummary-4e0fe49629a9e8045518e02139522a123816252b.tar.xz
Generate Nagios host groups for the site and subsite provided from
each client.
-rw-r--r--debian/changelog3
-rwxr-xr-xsitesummary-nodes44
2 files changed, 44 insertions, 3 deletions
diff --git a/debian/changelog b/debian/changelog
index 520b639..a493412 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -3,6 +3,9 @@ sitesummary (0.0.56~svn61690) lenny; urgency=low
* Continue development. _To_ upload the non-svn version, merge all
previous *~svn* versions.
+ * Generate Nagios host groups for the site and subsite provided from
+ each client.
+
-- Petter Reinholdtsen <pere@debian.org> Tue, 19 Jan 2010 20:52:58 +0100
sitesummary (0.0.56~svn61689) lenny; urgency=low
diff --git a/sitesummary-nodes b/sitesummary-nodes
index 1897660..e92b30c 100755
--- a/sitesummary-nodes
+++ b/sitesummary-nodes
@@ -155,8 +155,25 @@ define service {
EOF
}
+sub nagios_hostgroup_namewash {
+ my $name = shift;
+ $name =~ s/[^a-zA-Z_-]/-/g; # Avoid illegal characteres
+ return $name;
+}
+
+sub print_nagios_hostgroup {
+ my ($name, $alias) = @_;
+
+ print <<EOF;
+define hostgroup {
+ hostgroup_name $name
+EOF
+ print " alias $alias\n" if $alias;
+ print "}\n";
+}
+
sub print_nagios_host_check {
- my ($hostname, $address) = @_;
+ my ($hostname, $address, @hostgroups) = @_;
my $template = "server-host";
print <<EOF;
##################### $hostname #######################
@@ -164,13 +181,18 @@ define host {
use $template
host_name $hostname
address $address
-}
EOF
+ if (@hostgroups) {
+ print " hostgroups " . join(",", @hostgroups), "\n";
+ }
+ print "}\n";
}
sub generate_nagios_config {
my %hosts;
+ my %hostgroup;
for my $hostname (sort keys %hostnames) {
+ my @groups = ();
my $hostid = $hostnames{$hostname};
my $address = get_dns_address($hostid);
@@ -180,6 +202,18 @@ sub generate_nagios_config {
my $remote = is_remote_nagios_client($hostid);
my $nrpestatus = is_remote_nrpe_config_active($hostid);
+ my $site = get_site($hostid) || "none";
+ my $sitegroup = get_sitegroup($hostid);
+ my $groupname = nagios_hostgroup_namewash("site-$site");
+ $hostgroup{$groupname} = 1;
+ push(@groups, $groupname);
+ if ($sitegroup) {
+ $groupname = nagios_hostgroup_namewash("site-$site-$sitegroup");
+ $hostgroup{$groupname} = 1;
+ push(@groups, $groupname);
+ }
+
+
# Only check laptops that have the nagios tools installed
next if is_laptop($hostid) && ! $remote && ! $nagiosclient;
@@ -193,7 +227,7 @@ sub generate_nagios_config {
"check_ping", "100.0,20%!500.0,60%");
}
- print_nagios_host_check($hostname, $address)
+ print_nagios_host_check($hostname, $address, @groups)
unless (exists $hosts{$hostname});
$hosts{$hostname} = $address;
@@ -339,4 +373,8 @@ sub generate_nagios_config {
"check_procs_cron", "1:15!1:25")
if (is_pkg_installed($hostid, "cron"));
}
+
+ for my $name (sort keys %hostgroup) {
+ print_nagios_hostgroup($name)
+ }
}