diff options
author | Peter Palfrader <peter@palfrader.org> | 2005-10-10 23:43:10 +0000 |
---|---|---|
committer | weasel <weasel@bc3d92e2-beff-0310-a7cd-cc87d7ac0ede> | 2005-10-10 23:43:10 +0000 |
commit | 9f001770b66566ea33540a859267cfe59d1cdd4f (patch) | |
tree | 03a811cd6fbe08e3699af1bf42550a1c3c7e7131 /build-nagios | |
parent | 7848dc464b0cc3a4a38b83934a6ce665bec6a782 (diff) |
Copy all unknown fields in host definitions to resulting host definitions
git-svn-id: svn+ssh://asteria.noreply.org/svn/weaselutils/trunk@24 bc3d92e2-beff-0310-a7cd-cc87d7ac0ede
Diffstat (limited to 'build-nagios')
-rwxr-xr-x | build-nagios | 26 |
1 files changed, 19 insertions, 7 deletions
diff --git a/build-nagios b/build-nagios index 405f564..27e542c 100755 --- a/build-nagios +++ b/build-nagios @@ -73,6 +73,7 @@ config['hostgroups'].each_value{ |hg| } config['servers'].each_pair{ |name, server| + throw "No hostgroups defined for #{name}" unless server['hostgroups'] server['hostgroups'].split(/,/).each{ |hg| hg.strip! throw "Hostgroup #{hg} is not defined" unless config['hostgroups'].has_key?(hg) @@ -84,8 +85,12 @@ config['servers'].each_pair{ |name, server| config['hostgroups']['all'] = {} config['hostgroups']['all']['alias'] = "all servers" config['hostgroups']['all']['members'] = [] +config['hostgroups']['pingable'] = {} +config['hostgroups']['pingable']['alias'] = "pingable servers" +config['hostgroups']['pingable']['members'] = [] config['servers'].each_key{ |name| config['hostgroups']['all']['members'] << name + config['hostgroups']['pingable']['members'] << name unless (config['servers'][name]['pingable'] == false) } @@ -94,13 +99,21 @@ config['servers'].each_key{ |name| # Hosts and Hostgroups f = File.new(GENERATED_PREFIX+"auto-hosts.cfg", "w") config['servers'].each_pair{ |name, server| + if server.has_key?('ip') + STDERR.puts("Host definition for #{name} has an 'ip' field. Please use address instead"); + server['address'] = server['ip']; + server.delete('ip'); + end + server['host_name'] = name + server['alias'] = name unless server.has_key?('alias') + server['check_command'] = 'check-host-alive' unless (server['pingable'] == false || server.has_key?('check_command')) + server['use'] = 'generic-host' unless server.has_key?('use'); + f.puts "define host{" - f.puts " use generic-host" - f.puts " host_name #{ name }" - f.puts " alias #{ name }" - f.puts " address #{ server['ip'] }" - f.puts " check_command check-host-alive" - f.puts " parents #{ server['parents'] }" if server.has_key?('parents') + server.each_pair{ |key, value| + next if %w(hostgroups pingable).include? key + f.puts " #{key} #{value}" + } f.puts "}" f.puts } @@ -141,7 +154,6 @@ def addService(hosts, service, f, deps) # known keys: next if %w(name check hosts nrpe remotecheck hostgroups excludehosts excludehostgroups depends runfrom).include? key f.puts " #{key} #{value}" - } f.puts "}" |