From 60ce32a358677a5acaa9a5e924868c020a7216f7 Mon Sep 17 00:00:00 2001 From: Peter Palfrader Date: Sun, 2 Oct 2005 12:37:08 +0000 Subject: Make excludehostgroups git-svn-id: svn+ssh://asteria.noreply.org/svn/weaselutils/trunk@20 bc3d92e2-beff-0310-a7cd-cc87d7ac0ede --- build-nagios | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/build-nagios b/build-nagios index 8743209..0eb5595 100755 --- a/build-nagios +++ b/build-nagios @@ -9,6 +9,9 @@ SHORTORG="rela" CONTACTGROUP="weaselgroup" GENERATED_PREFIX="/etc/NOREPLY/generated/nagios/" +MAX_CHECK_ATTEMPTS_DEFAULT=6 +MAX_CHECK_ATTEMPTS_NRPESERVICE=5 + class Nrpe def initialize @checks = {} @@ -124,6 +127,8 @@ def addService(hosts, service, f, deps) f.puts " host_name #{ hosts_comma }" f.puts " service_description #{ service['name'] }" f.puts " check_command #{ service['check'] }" if service['check'] + service['max_check_attempts']=MAX_CHECK_ATTEMPTS_DEFAULT unless service['max_check_attempts'] + service['max_check_attempts']=MAX_CHECK_ATTEMPTS_DEFAULT+service['max_check_attempts'] if service['max_check_attempts'] < 0 if service['nrpe'] check = $nrpe.add(service['name'], service['nrpe']) f.puts " check_command #{ ORG }_check_nrpe!#{ check }" @@ -133,7 +138,7 @@ def addService(hosts, service, f, deps) # put additional keys into services service.each_pair{ |key, value| # known keys: - next if %w(name check hosts nrpe remotecheck hostgroups excludehosts depends runfrom).include? key + next if %w(name check hosts nrpe remotecheck hostgroups excludehosts excludehostgroups depends runfrom).include? key f.puts " #{key} #{value}" } @@ -186,13 +191,23 @@ config['services'].each{ |service| hosts = hosts.concat config['hostgroups'][hg]['members'] } end + excludehosts = [] if service['excludehosts'] then - service['excludehosts'].delete(" \t").split(/,/).each{ |host| - if hosts.delete(host) == nil - throw "Cannot remove host #{host} from service #{service['name']}: it's not included anyway" + excludehosts = service['excludehosts'].delete(" \t").split(/,/) + end + if service['excludehostgroups'] then + service['excludehostgroups'].delete(" \t").split(/,/).each{ |hg| + unless config['hostgroups'][hg] + throw "hostgroup #{hg} does not exist- used in service #{service['name']}" end + excludehosts = excludehosts.concat config['hostgroups'][hg]['members'] } end + excludehosts.each{ |host| + if hosts.delete(host) == nil + throw "Cannot remove host #{host} from service #{service['name']}: it's not included anyway" + end + } throw "no hosts for service #{service['name']}" if hosts.empty? -- cgit v1.2.3