From 7e4c74300a68f84053a4e141c14aa1b98b88812f Mon Sep 17 00:00:00 2001 From: Paul Wise Date: Tue, 9 Dec 2014 13:47:11 +0800 Subject: [PATCH] Compose the extinfo for servers based on all their hostgroups extinfo. Also allow removal of items using the empty string. --- config/build-nagios | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/config/build-nagios b/config/build-nagios index 7a80f0a..28513c9 100755 --- a/config/build-nagios +++ b/config/build-nagios @@ -337,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') -- 2.20.1