diff options
author | Petter Reinholdtsen <pere@hungry.com> | 2010-01-16 00:44:41 +0000 |
---|---|---|
committer | Petter Reinholdtsen <pere@hungry.com> | 2010-01-16 00:44:41 +0000 |
commit | a30da43bcb5d4d1d53b7a6619105d724a079fbf6 (patch) | |
tree | baa8dfbb15aff5e240ca1fd55932fb8634d201f1 | |
parent | 09a600c2f7019d71a064004c640fd726405e7d78 (diff) | |
download | sitesummary-a30da43bcb5d4d1d53b7a6619105d724a079fbf6.tar.gz sitesummary-a30da43bcb5d4d1d53b7a6619105d724a079fbf6.tar.bz2 sitesummary-a30da43bcb5d4d1d53b7a6619105d724a079fbf6.tar.xz |
Rewrite how nagios configuration is generated to use a function to
generate each service check.
-rw-r--r-- | debian/changelog | 7 | ||||
-rwxr-xr-x | sitesummary-nodes | 211 |
2 files changed, 90 insertions, 128 deletions
diff --git a/debian/changelog b/debian/changelog index 4c23785..d27e396 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,10 @@ +sitesummary (0.0.54) UNRELEASED; urgency=low + + * Rewrite how nagios configuration is generated to use a function to + generate each service check. + + -- Petter Reinholdtsen <pere@debian.org> Sat, 16 Jan 2010 01:39:35 +0100 + sitesummary (0.0.53) unstable; urgency=low * Collect software raid status from /proc/mdstat if it exist. diff --git a/sitesummary-nodes b/sitesummary-nodes index 4f01059..c79a4ff 100755 --- a/sitesummary-nodes +++ b/sitesummary-nodes @@ -21,7 +21,7 @@ EOF } my %opts; -getopts("hmnw", \%opts) || (usage(), exit(1)); +getopts("hmnwr", \%opts) || (usage(), exit(1)); my %hostnames; @@ -34,7 +34,7 @@ if ($opts{'h'}) { print_munin_list(); } elsif ($opts{'w'}) { print_ip_hw_list(); -} elsif ($opts{'n'}) { # XXX Nagios config generation do not work yet +} elsif ($opts{'n'}) { generate_nagios_config(); } else { print_list(); @@ -113,6 +113,31 @@ sub is_remote_nagios_client { is_pkg_installed($hostid, "nagios3")); } +sub print_nagios_service_check { + my ($remote, $hostname, $description, $check, $check_args) = @_; + my $template = "server-service"; + my $cmd; + return if $opts{'r'} && remote; + if ($remote) { + $cmd = "check_nrpe!$check"; + if (defined $check_args) { + $check_args =~ s/!/ /; + $cmd .= " -a $check_args"; + } + } else { + $cmd = "$check"; + $cmd .= "!$check_args" if defined $check_args; + } + print <<EOF; +define service { + use $template; + host_name $hostname + service_description $description + check_command $cmd +} +EOF +} + sub generate_nagios_config { for my $hostname (sort keys %hostnames) { my $hostid = $hostnames{$hostname}; @@ -121,7 +146,7 @@ sub generate_nagios_config { my $address = get_dns_address($hostid); my $redirect = ""; - $redirect = "check_nrpe!" if is_remote_nagios_client($hostid); + my $remote = is_remote_nagios_client($hostid); # first, check ping to see if the other checks should be performed print <<EOF; @@ -131,43 +156,22 @@ define host { host_name $hostname address $address } -define service { - use server-service - host_name $hostname - service_description ping - check_command check_ping!100.0,20%!500.0,60% -} -define service { - use server-service - host_name $hostname - service_description swap - check_command ${redirect}check_swap!10%!5% -} -define service { - use server-service - host_name $hostname - service_description current users - check_command ${redirect}check_users!20!50 -} -define service { - use server-service - host_name $hostname - service_description processes total - check_command ${redirect}check_procs!500!1000 -} -define service { - use server-service - host_name $hostname - service_description processes zombie - check_command ${redirect}check_procs_zombie!20!100 -} -define service { - use server-service - host_name $hostname - service_description apt-updates - check_command ${redirect}check_apt -} EOF + print_nagios_service_check(0, $hostname, "ping", + "check_ping", "100.0,20%!500.0,60%"); + print_nagios_service_check($remote, $hostname, "swap", + "check_swap", "10%!5%"); + print_nagios_service_check($remote, $hostname, "current users", + "check_users", "20!50"); + print_nagios_service_check($remote, $hostname, "processes total", + "check_procs", "500!1000"); + print_nagios_service_check($remote, $hostname, "processes zombie", + "check_procs_zombie", "20!100"); + print_nagios_service_check($remote, $hostname, "apt-updates", + "check_apt"); + # Check unix load + print_nagios_service_check($remote, $hostname, "load as in top", + "check_load", "75,75,75!90,90,90"); # check disk free space my $path = get_filepath_current($hostid, "/system/procmounts"); @@ -195,14 +199,10 @@ EOF $checked{$partition} = 1; my $warn = 10; my $crit = 5; - print <<EOF; -define service { - use server-service - host_name $hostname - service_description disk $partition - check_command ${redirect}check_disk!$warn%!$crit%!$partition -} -EOF + print_nagios_service_check($remote, $hostname, + "disk $partition", + "check_disk", + "$warn%!$crit%!$partition"); } } @@ -221,25 +221,13 @@ EOF is_pkg_installed($hostid, $tcpservices{$port}->{package})); my $servicename = $tcpservices{$port}->{name}; - print <<EOF; -define service { - use server-service - host_name $hostname - service_description $servicename - check_command ${redirect}check_tcp!$port -} -EOF + print_nagios_service_check(0, $hostname, $servicename, + "check_tcp", $port); } # check software raid status if ( -e get_filepath_current($hostid, "/system/mdstat") ) { - print <<EOF; -define service { - use server-service - host_name $hostname - service_description sw-raid - check_command ${redirect}check_linux_raid -} -EOF + print_nagios_service_check($remote, $hostname, "sw-raid", + "check_linux_raid"); } # check munin if munin-node is installed @@ -249,76 +237,43 @@ EOF # check LDAP and LDAPS using the protocol # Check DNS server - print <<EOF if is_pkg_installed($hostid, "pdns-server"); -define service { - use server-service - host_name $hostname - service_description dns - check_command ${redirect}check_dns -} -EOF + print_nagios_service_check($remote, $hostname, "dns", + "check_dns") + if is_pkg_installed($hostid, "pdns-server"); + # Check IMAPS server - print <<EOF if is_pkg_installed($hostid, "courier-imap-ssl"); -define service { - use server-service - host_name $hostname - service_description imaps - check_command ${redirect}check_imaps -} -EOF + print_nagios_service_check($remote, $hostname, "imaps", + "check_imaps") + if is_pkg_installed($hostid, "courier-imap-ssl"); + # Check NFS server - print <<EOF if is_pkg_installed($hostid, "nfs-kernel-server"); -define service { - use server-service - host_name $hostname - service_description nfs - check_command ${redirect}check_nfs -} -EOF + print_nagios_service_check($remote, $hostname, "nfs", + "check_nfs") + if is_pkg_installed($hostid, "nfs-kernel-server"); + # Check Squid web proxy - print <<EOF if is_pkg_installed($hostid, "squid"); -define service { - use server-service - host_name $hostname - service_description squid - check_command ${redirect}check_squid!3128!http://www + print_nagios_service_check($remote, $hostname, "squid", + "check_squid", "3128!http://www") + if is_pkg_installed($hostid, "squid"); -} -EOF # Check SSH server - print <<EOF if is_pkg_installed($hostid, "openssh-server"); -define service { - use server-service - host_name $hostname - service_description ssh - check_command ${redirect}check_ssh -} -EOF - print <<EOF if (is_pkg_installed($hostid, "apache") || is_pkg_installed($hostid, "apache2")); -define service { - use server-service - host_name $hostname - service_description http - check_command ${redirect}check_http - } -EOF + print_nagios_service_check($remote, $hostname, "ssh", + "check_ssh") + if is_pkg_installed($hostid, "openssh-server"); - print <<EOF if (is_pkg_installed($hostid, "ntp") || is_pkg_installed($hostid, "ntp-server")); -define service { - use server-service - host_name $hostname - service_description ntp time server - check_command ${redirect}check_ntp!-H!localhost -} -EOF - # Check unix load - print <<EOF; -define service { - use server-service - host_name $hostname - service_description load as in top - check_command ${redirect}check_load!75,75,75!90,90,90 -} -EOF + print_nagios_service_check($remote, $hostname, "http", + "check_http") + if (is_pkg_installed($hostid, "apache") || + is_pkg_installed($hostid, "apache2")); + + print_nagios_service_check($remote, $hostname, "ntp time server", + "check_ntp", "-H!localhost") + if (is_pkg_installed($hostid, "ntp") || + is_pkg_installed($hostid, "ntp-server")); + + # Detect if cron no longer is running + print_nagios_service_check($remote, $hostname, "process - cron", + "check_procs_command", "-a!1:15 1:25 cron") + if (is_pkg_installed($hostid, "cron")); } } |