Better generation of nagios check file

Change-Id: I884297e4eec73ccf896704b272587344a629e04d
This commit is contained in:
Ryan Bak 2015-05-07 16:35:35 -06:00
parent 1299be941c
commit e095ef29dc
3 changed files with 35 additions and 107 deletions

View File

@ -1,52 +0,0 @@
Puppet::Parser::Functions.newfunction(:generate_nagios_instances, :type => :rvalue) do |args|
checks_dict = args[0]
types_dict = args[1]
nodes_dict = args[2]
dimensions_dict = args[3]
flags_dict = args[4]
existing_instances = args[5]
existing_instances = {} if existing_instances == ""
dimensions_dict = {} if dimensions_dict == ""
new_instances = Hash.new
nodes_dict.each do |groupname, nodes|
group_dimensions = {}
group_dimensions = dimensions_dict[groupname] if dimensions_dict.has_key?(groupname)
next if not flags_dict.has_key?(groupname)
group_flags = flags_dict[groupname]
nodes.each do |hostname|
next if not group_flags.has_key?("type")
node_type = group_flags["type"]
check_list = types_dict[node_type]
check_list.each do |check_name|
check = checks_dict[check_name]
new_check = Hash.new
new_check["check_name"] = check_name
new_command = check["check_command"]
group_dimensions.each do |key, value|
to_sub = '<'
to_sub << key
to_sub << '>'
new_command = new_command.sub to_sub, value
end
group_flags.each do |key, value|
to_sub = '<'
to_sub << key
to_sub << '>'
new_command = new_command.sub to_sub, value
end
new_check["check_command"] = new_command.sub '<host>', hostname
new_check["host_name"] = hostname
new_check["check_interval"] = check["check_interval"] if check.has_key?("check_interval")
if check.has_key?("dimensions")
new_check["dimensions"] = group_dimensions.merge(check["dimensions"])
else
new_check["dimensions"] = group_dimensions
end
check_name = "#{check_name}_#{hostname}"
new_instances[check_name] = new_check
end
end
end
instances = existing_instances.merge(new_instances)
end

View File

@ -1,12 +1,16 @@
#
# configure monasca plugin yaml file for nagios_wrapper
#
# nrpe is not used by the check, only by puppet to determine which host
# uses this fragment
#
define monasca::checks::instances::nagios_wrapper (
$check_command,
$check_name = undef,
$host_name = undef,
$check_interval = undef,
$dimensions = undef,
$nrpe = undef,
) {
$conf_dir = $::monasca::agent::conf_dir
concat::fragment { "${title}_nagios_wrapper_instance":

View File

@ -23,74 +23,50 @@
# disk:
# check_command: 'check_disk -w 15\% -c 5\% -A -i /srv/node'
# check_interval: '300'
# [*checks*]
# A hash of check defenitions.
# For use with types and nodes. When all three are defined they will combined to create a list
# of checks in the format that the nagios plugin requires, and merged with the instances list
# Parameters are:
# check_name (the instance key): The name of the check.
# check_command (required): Use 'host' where the name of the host should be filled in.
# check_interval
# dimensions
# [*types*]
# A hash of node type defenitions.
# For use with checks and nodes
# Parameters are:
# type_name (the instance key): The type of node (e.g control, compute).
# This is followed with a list of checks to run on that node type.
# [*nodes*]
# A hash of node defenitions.
# For use with checks and types
# Parameters are:
# group_name (the instance key): An identifier for a group of nodes. Used with flags.
# This is followed with a list of hostnames
# [*dimensions*]
# A hash of node dimensions to be submitted with the metrics. All dimensions also act as flags.
# For use with checks, types, nodes and flags
# Parameters are:
# group_name (the instance key): The group of nodes to which the dimensions apply
# Any other key value pairs can be provided here.
# [*flags*]
# A hash of node flags for use in the command.
# For use with checks, types, nodes and dimensions
# Parameters are:
# group_name (the instance key): The group of nodes to which the flags apply
# type (required): The type of given group of nodes.
# Any other key value pairs can be provided here.
# A hash of node dimensions to be submitted with the metrics.
# If the collector is used these are the dimensions submitted with the metrics.
# [*host_name*]
# Use with the collector to determine which checks run on which host
# [*central_mon*]
# Set to true when using the collector if a single host will be running
# all non-nrpe checks
#
class monasca::checks::nagios_wrapper(
$check_path = '/usr/lib/nagios/plugins:/usr/local/bin/nagios',
$temp_file_path = '/dev/shm/',
$instances = undef,
$checks = undef,
$types = undef,
$nodes = undef,
$dimensions = undef,
$flags = undef,
$host_name = undef,
$central_mon = false,
){
$conf_dir = $::monasca::agent::conf_dir
if $checks and $types and $nodes and $flags{
$real_instances = generate_nagios_instances($checks, $types, $nodes, $dimensions, $flags, $instances)
if ($central_mon) {
Monasca::Checks::Instances::Nagios_wrapper <<| nrpe == false |>> {
dimensions => $dimensions,
}
}
else {
$real_instances = $instances
Monasca::Checks::Instances::Nagios_wrapper <<| host_name == $host_name and nrpe != false |>> {
dimensions => $dimensions,
}
}
if($real_instances){
Concat["${conf_dir}/nagios_wrapper.yaml"] ~> Service['monasca-agent']
concat { "${conf_dir}/nagios_wrapper.yaml":
owner => 'root',
group => $::monasca::group,
mode => '0640',
warn => true,
require => File[$conf_dir],
}
concat::fragment { 'nagios_wrapper_header':
target => "${conf_dir}/nagios_wrapper.yaml",
order => '0',
content => template('monasca/checks/nagios_wrapper.yaml.erb'),
}
create_resources('monasca::checks::instances::nagios_wrapper', $real_instances)
Concat["${conf_dir}/nagios_wrapper.yaml"] ~> Service['monasca-agent']
concat { "${conf_dir}/nagios_wrapper.yaml":
owner => 'root',
group => $::monasca::group,
mode => '0640',
warn => true,
require => File[$conf_dir],
}
concat::fragment { 'nagios_wrapper_header':
target => "${conf_dir}/nagios_wrapper.yaml",
order => '0',
content => template('monasca/checks/nagios_wrapper.yaml.erb'),
}
if($instances){
create_resources('monasca::checks::instances::nagios_wrapper', $instances)
}
}