diff options
-rw-r--r-- | debian/changelog | 3 | ||||
-rwxr-xr-x | sitesummary-nodes | 44 |
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) + } } |