summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xbuild-nagios26
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 "}"