X-Git-Url: https://git.adam-barratt.org.uk/?a=blobdiff_plain;f=config%2Fbuild-nagios;h=28513c96ec350e41546843be6a710a48ddd269f7;hb=ed0e0a87bffbe81740d6282866ee6578ac6b2845;hp=7b2a7d679ce8d97362dcb22e33f311ab8d24ac81;hpb=99460328fde6bdab01ed61b3c514bea3644d834b;p=mirror%2Fdsa-nagios.git diff --git a/config/build-nagios b/config/build-nagios index 7b2a7d6..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]}" } @@ -147,7 +145,7 @@ def merge_contacts(host, service) [host, service].each{ |source| contacts.push source[k] if source.has_key?(k) } - service[k] = contacts.join(",") unless contacts.empty? + service[k] = contacts.sort.join(",") unless contacts.empty? } end @@ -176,9 +174,13 @@ def addService(hosts, service, files, servers) set_complain_if_set s, 'host_name', host, 'Service', s['service_description'] merge_contacts(servers[host], s) - print_block files['services'], 'service', s, %w(nrpe runfrom remotecheck - depends - hosts hostgroups excludehosts excludehostgroups) + exclude_keys = %w(nrpe runfrom remotecheck + depends + hosts hostgroups excludehosts excludehostgroups) + if servers[host]['no-servicegroups'] + exclude_keys << 'servicegroups' + end + print_block files['services'], 'service', s, exclude_keys } if service['depends'] @@ -209,7 +211,7 @@ def addService(hosts, service, files, servers) set_complain_if_set service['_extinfo'], 'service_description' , service['service_description'], 'serviceextinfo', service['service_description'] - set_complain_if_set service['_extinfo'], 'host_name' , hosts.join(',') , 'serviceextinfo', service['service_description'] + set_complain_if_set service['_extinfo'], 'host_name' , hosts.sort.join(',') , 'serviceextinfo', service['service_description'] print_block files['serviceextinfo'], 'serviceextinfo', service['_extinfo'], %w() end @@ -330,22 +332,24 @@ config['servers'].keys.sort.each{ |name| set_if_unset server, 'use' , HOST_TEMPLATE_NAME set_if_unset server, 'check_command', HOST_ALIVE_CHECK unless server['pingable'] == false - print_block files['hosts'] , 'host' , server , %w(hostgroups pingable) + print_block files['hosts'] , 'host' , server , %w(hostgroups pingable no-servicegroups) # 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') @@ -365,8 +369,8 @@ config['hostgroups'].keys.sort.each{ |name| next if hg['private'] throw "Empty hostgroup #{name}" if hg['_memberlist'].length == 0 - set_complain_if_set hg, 'hostgroup_name', name , 'Hostgroup', name - set_complain_if_set hg, 'members' , hg['_memberlist'].join(","), 'Hostgroup', name + set_complain_if_set hg, 'hostgroup_name', name , 'Hostgroup', name + set_complain_if_set hg, 'members' , hg['_memberlist'].sort.join(","), 'Hostgroup', name print_block files['hostgroups'], 'hostgroup', hg, %w() } @@ -380,6 +384,8 @@ config['services'].each{ |service| split_away_extinfo service + # make sure the depends list is an array + service['depends'] = ensure_array( service['depends'] ) # Both 'name' and 'service_description' are valid for a service's name # Internally we only use service_description as that's nagios' official term