Fixes for nagios check function

Now handles undefined nagios_instances

Change-Id: I574d455188c287ca1cf67589cdc84c00d57b3882
This commit is contained in:
Ryan Bak 2015-03-19 11:13:18 -06:00
parent 4a3f035932
commit 80eebabd43
1 changed files with 10 additions and 4 deletions

View File

@ -4,6 +4,7 @@ Puppet::Parser::Functions.newfunction(:generate_nagios_instances, :type => :rval
nodes_dict = args[2]
existing_instances = args[3]
existing_instances = {} if existing_instances= ""
new_instances = Hash.new
nodes_dict.each do |hostname, node|
node_type = node["type"]
@ -12,12 +13,17 @@ Puppet::Parser::Functions.newfunction(:generate_nagios_instances, :type => :rval
check = checks_dict[check_name]
new_check = Hash.new
new_check["name"] = check_name
new_check["check_command"] = check["check_command"].sub! 'host' hostname
new_check["check_command"] = check["check_command"].sub! '<host>', hostname
new_check["host_name"] = hostname
new_check["check_interval"] = check["check_interval"] if check.has_key?("check_interval")
dimensions = node_dimensions.merge(check_dimensions)
new_check["dimensions"] = dimensions
check_name = "#{check_name}_#{node_name}"
if check.has_key?("dimensions") and node.has_key("dimensions")
new_check["dimensions"] = node["dimensions"].merge(check["dimensions"])
elsif check.has_key?("dimensions")
new_check["dimensions"] = check["dimensions"]
elsif node.has_key?("dimensions")
new_check["dimensions"] = node["dimensions"]
end
check_name = "#{check_name}_#{hostname}"
new_instances[check_name] = new_check
end
end