X-Git-Url: https://git.adam-barratt.org.uk/?a=blobdiff_plain;f=build-nagios;h=8475da8200f75b512c019e69c95108b83c3c46ca;hb=34816cfa599726fb4d7c33e02091a14b22069312;hp=9d7541bb7d05062fce43ed9af8a67239aaee0bc2;hpb=da547572939d8456d6e41352b65ebec70b2009a0;p=mirror%2Fdsa-nagios.git diff --git a/build-nagios b/build-nagios index 9d7541b..8475da8 100755 --- a/build-nagios +++ b/build-nagios @@ -9,7 +9,7 @@ SHORTORG="dsa" GENERATED_PREFIX="./generated/" nagios_filename = {}; -%w(hosts hostgroups services dependencies hostextinfo serviceextinfo).each{ +%w(hosts hostgroups services dependencies hostextinfo serviceextinfo servicegroups).each{ |x| nagios_filename[x] = GENERATED_PREFIX+"auto-#{x}.cfg" } nagios_filename['nrpe'] = GENERATED_PREFIX+"nrpe_#{ ORG }.cfg" @@ -117,6 +117,15 @@ def print_block(fd, kind, hash, exclude_keys) fd.puts end +def merge_contacts(host, service) + %w{contacts contact_groups}.each{ |k| + contacts = [] + [host, service].each{ |source| + contacts.push source[k] if source.has_key?(k) + } + service[k] = contacts.join(",") unless contacts.empty? + } +end # Add the service definition service to hosts # f is the file for service definitions, deps the file for dependencies @@ -141,9 +150,7 @@ def addService(hosts, service, files, servers) hosts.each{ |host| s = service.clone set_complain_if_set s, 'host_name', host, 'Service', s['service_description'] - %w{contacts contact_groups}.each{ |k| - set_if_unset(s, k, servers[host][k]) if servers[host].has_key? k - } + merge_contacts(servers[host], s) print_block files['services'], 'service', s, %w(nrpe runfrom remotecheck depends @@ -279,6 +286,8 @@ config['servers'].each_pair{ |name, server| }; } +config['servicegroups'] = {} unless config.has_key? 'servicegroups' + ############## # HOSTS ############## @@ -404,6 +413,17 @@ config['services'].each{ |service| } + +############## +# SERVICEGROUPS +############## +config['servicegroups'].each_pair{ |name, sg| + set_complain_if_set sg, 'servicegroup_name', name , 'Servicegroup', name + + print_block files['servicegroups'], 'servicegroup', sg, %w() +} + + ############## # NRPE config file ##############