diff options
author | Marius Halden <marius.h@lden.org> | 2015-02-15 00:59:09 +0100 |
---|---|---|
committer | Marius Halden <marius.h@lden.org> | 2015-03-28 19:29:23 +0100 |
commit | 9ba853dde6ca00fa99402aa4029b1605fecbefdb (patch) | |
tree | 7e5e8aaf414dcaf14e29b0b6e0d6c90b889fe309 /sitesummary-nodes | |
parent | 139bdcdf9718ae0e3bfd65fb8627b21e358e0f78 (diff) | |
download | sitesummary-9ba853dde6ca00fa99402aa4029b1605fecbefdb.tar.gz sitesummary-9ba853dde6ca00fa99402aa4029b1605fecbefdb.tar.bz2 sitesummary-9ba853dde6ca00fa99402aa4029b1605fecbefdb.tar.xz |
Add support for changing nagios settings through a configuration file.nagios-cfg2
Diffstat (limited to 'sitesummary-nodes')
-rwxr-xr-x | sitesummary-nodes | 62 |
1 files changed, 41 insertions, 21 deletions
diff --git a/sitesummary-nodes b/sitesummary-nodes index a889fe7..bd31d57 100755 --- a/sitesummary-nodes +++ b/sitesummary-nodes @@ -63,6 +63,7 @@ if ($opts{'h'}) { } close $fh; } + generate_nagios_config(); } else { print_list(); @@ -248,12 +249,22 @@ EOF print "}\n"; } +sub get_cfg { + my ($host, $service, $setting) = @_; + no strict 'vars'; + + return undef unless defined $services; + return $services->{$host}->{$service}->{$setting}; +} + sub generate_nagios_config { my %hosts; my %hostgroup; + for my $hostname (sort keys %hostnames) { my @groups = (); my $hostid = $hostnames{$hostname}; + my ($warn, $crit); my $address = get_dns_address($hostid); my $localhostname = get_localhostname($hostid); @@ -344,12 +355,12 @@ sub generate_nagios_config { unless (exists $hosts{$hostname}); $hosts{$hostname} = $address; - # first, check ping to see if the other checks should be performed - print_nagios_service_check(0, $hostname, "ping", - "check_ping", - sprintf("%.1f,%d%%!%.1f,%d%%", - $npingwarn, $npingwarnp, - $npingcrit, $npingcritp)); + # first, check ping to see if the other checks should be performed + print_nagios_service_check(0, $hostname, "ping", + "check_ping", + sprintf("%.1f,%d%%!%.1f,%d%%", + $npingwarn, $npingwarnp, + $npingcrit, $npingcritp)); my %tcpservices = ( @@ -479,8 +490,11 @@ sub generate_nagios_config { next unless ((!$remote && $nagiosclient) || ($remote && "args" eq $nrpestatus)); - print_nagios_service_check($remote, $hostname, "swap", - "check_swap", "10%!5%"); + $warn = get_cfg($hostname, 'swap', 'warn') || "10%"; + $crit = get_cfg($hostname, 'swap', 'crit') || "5%"; + print_nagios_service_check($remote, $hostname, "swap", + "check_swap", "$warn!$crit"); + my $proclimit = "500!1000"; # Raise process count limits for thin clients, as # lots of users can log into these machines and run their @@ -488,13 +502,16 @@ sub generate_nagios_config { if (is_pkg_installed($hostid, "ltsp-server")) { $proclimit = "1500!2500"; } - print_nagios_service_check($remote, $hostname, "processes total", - "check_procs", $proclimit); - print_nagios_service_check($remote, $hostname, "processes zombie", - "check_procs_zombie", "20!100"); - # Check unix load - print_nagios_service_check($remote, $hostname, "load as in top", - "check_load", "75,75,75!90,90,90"); + print_nagios_service_check($remote, $hostname, "processes total", + "check_procs", $proclimit); + print_nagios_service_check($remote, $hostname, "processes zombie", + "check_procs_zombie", "20!100"); + + $warn = get_cfg($hostname, 'load-avg', 'warn') || "75,75,75"; + $crit = get_cfg($hostname, 'load-avg', 'crit') || "90,90,90"; + # Check unix load + print_nagios_service_check($remote, $hostname, "load as in top", + "check_load", "$crit!$warn"); # check disk free space my $path = get_filepath_current($hostid, "/system/procmounts"); @@ -541,12 +558,15 @@ sub generate_nagios_config { $fs eq "usbfs"); $checked{$device} = 1; - my $warn = 10; - my $crit = 5; - print_nagios_service_check($remote, $hostname, - "disk $partition", - "check_disk", - "$warn%!$crit%!$partition"); + + my $warn = get_cfg($hostname, "disk-$partition", + 'warn') || 10; + my $crit = get_cfg($hostname, "disk-$partition", + 'crit') || 5; + print_nagios_service_check($remote, $hostname, + "disk $partition", + "check_disk", + "$warn%!$crit%!$partition"); } } |