X-Git-Url: https://git.adam-barratt.org.uk/?a=blobdiff_plain;f=config%2Fbuild-nagios;h=28513c96ec350e41546843be6a710a48ddd269f7;hb=0d6871110ffc88fc5c71fb83892f1e71b0ecc295;hp=2729e7543dc5faf09633e5bb2bbd32581b74e04c;hpb=a094e6053e02ebcfc70ff580fc6b1c769f7e9fff;p=mirror%2Fdsa-nagios.git diff --git a/config/build-nagios b/config/build-nagios index 2729e75..28513c9 100755 --- a/config/build-nagios +++ b/config/build-nagios @@ -131,9 +131,7 @@ $nrpe = Nrpe.new() def print_block(fd, kind, hash, exclude_keys) fd.puts "define #{kind} {" hash.keys.sort.each{ |key| - next if key == '_extinfo' - next if key == '_hostgroups' - next if key == '_memberlist' + next if key[0,1] == '_' next if exclude_keys.include? key fd.puts " #{key} #{hash[key]}" } @@ -339,17 +337,19 @@ config['servers'].keys.sort.each{ |name| # Handle hostextinfo - #config['hostgroups'][ server['_hostgroups'].first ]['_extinfo'].each_pair{ |k, v| - # find the first hostgroup that has extinfo - extinfo = server['_hostgroups'].collect{ |hgname | config['hostgroups'][hgname]['_extinfo'] }.delete_if{ |ei| ei.size == 0 }.first - if extinfo then - extinfo.each_pair do |k, v| - # substitute hostname into the notes_url - v = sprintf(v,name) if k == 'notes_url' - - set_if_unset server['_extinfo'], k ,v + # Compose extinfo from all the hostgroups for each server + config['hostgroups'].each_pair{ |hgname, hostgroup| + next unless server['_hostgroups'].include?(hgname) + hostgroup['_extinfo'].each_pair do |k, v| + if v.empty? + server['_extinfo'].delete(k) + else + # substitute hostname into the notes_url + v = sprintf(v,name) if k == 'notes_url' + server['_extinfo'][k] = v + end end - end + } set_complain_if_set server['_extinfo'], 'host_name' , name, 'hostextinfo', name set_if_unset server['_extinfo'], 'vrml_image' , server['_extinfo']['icon_image'] if server['_extinfo'].has_key?('icon_image')