Puppet Class: metricbeat::config
- Inherits:
- metricbeat
- Defined in:
- manifests/config.pp
Summary
Manages Metricbeat's configuration fileOverview
metricbeat::config Manages the state and contests of Metricbeat's configuration file
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'manifests/config.pp', line 7
class metricbeat::config inherits metricbeat {
# Use lookup to merge metricbeat::modules config from different levels of hiera
$modules_lookup = lookup('metricbeat::modules', undef, 'unique', undef)
# Check to see if anything has been confiugred in hiera
if $modules_lookup {
$modules_arr = $modules_lookup
# check if array is empty, no need to create a config entry then
} elsif $metricbeat::modules[0].length() > 0 {
$modules_arr = $metricbeat::modules
} else {
$modules_arr = undef
}
# if fields are "under root", then remove prefix
if $metricbeat::fields_under_root == true {
$fields_tmp = $metricbeat::fields.each | $key, $value | { {$key => $value} }
} else {
$fields_tmp = $metricbeat::fields
}
if $metricbeat::major_version == '5' {
$metricbeat_config_base = delete_undef_values({
'cloud.id' => $metricbeat::cloud_id,
'cloud.auth' => $metricbeat::cloud_auth,
'name' => $metricbeat::beat_name,
'tags' => $metricbeat::tags,
'logging' => $metricbeat::logging,
'processors' => $metricbeat::processors,
'queue_size' => $metricbeat::queue_size,
'metricbeat' => {
'modules' => $metricbeat::modules,
},
'output' => $metricbeat::outputs,
'metricbeat.config.modules.path' => "${metricbeat::config_dir}/modules.d/*.yml",
})
$metricbeat_config = deep_merge($metricbeat_config_base, $fields_tmp)
}
else {
$metricbeat_config_base = delete_undef_values({
'cloud.id' => $metricbeat::cloud_id,
'cloud.auth' => $metricbeat::cloud_auth,
'name' => $metricbeat::beat_name,
'tags' => $metricbeat::tags,
'logging' => $metricbeat::logging,
'processors' => $metricbeat::processors,
'queue' => $metricbeat::queue,
'fields_under_root' => $metricbeat::fields_under_root,
'metricbeat.modules' => $modules_arr,
'output' => $metricbeat::outputs,
'metricbeat.config.modules.path' => "${metricbeat::config_dir}/modules.d/*.yml",
})
if $fields_tmp {
$fields_tmp2 = { 'fields' => $fields_tmp, }
$metricbeat_config_temp = deep_merge( $metricbeat_config_base, $fields_tmp2 )
} else {
$metricbeat_config_temp = $metricbeat_config_base
}
# Add the 'xpack' section if supported (version >= 6.2.0)
if versioncmp($metricbeat::package_ensure, '6.2.0') >= 0 {
$metricbeat_config = deep_merge($metricbeat_config_temp, {'xpack' => $metricbeat::xpack})
}
else {
$metricbeat_config = $metricbeat_config_temp
}
}
# Create modules.d files that exist in hiera then collect any created via exported resources
$module_templates_real = hiera_array('metricbeat::module_templates', $metricbeat::module_templates)
$module_templates_real.each |$module| {
@@metricbeat::modulesd { $module: }
}
Metricbeat::Modulesd <<||>>
case $::kernel {
'Linux': {
$validate_cmd = $metricbeat::disable_configtest ? {
true => undef,
default => $metricbeat::major_version ? {
'5' => '/usr/share/metricbeat/bin/metricbeat -configtest -c %',
default => "/usr/share/metricbeat/bin/metricbeat --path.config ${metricbeat::config_dir} test config",
}
}
file{'metricbeat.yml':
ensure => $metricbeat::ensure,
path => "${metricbeat::config_dir}/metricbeat.yml",
owner => 'root',
group => 'root',
mode => $metricbeat::config_mode,
content => inline_template('<%= @metricbeat_config.to_yaml() %>'),
validate_cmd => $validate_cmd,
}
}
'Windows': {
$cmd_install_dir = regsubst($metricbeat::install_dir, '/', '\\', 'G')
$metricbeat_path = join([$cmd_install_dir, 'Metricbeat', 'metricbeat.exe'], '\\')
$validate_cmd = $metricbeat::disable_configtest ? {
true => undef,
default => $metricbeat::major_version ? {
'5' => "\"${metricbeat_path}\" -N configtest -c \"%\"",
default => "\"${metricbeat_path}\" --path.config \"${metricbeat::config_dir}\" test config",
}
}
file{'metricbeat.yml':
ensure => $metricbeat::ensure,
path => "${metricbeat::config_dir}/metricbeat.yml",
content => inline_template('<%= @metricbeat_config.to_yaml() %>'),
validate_cmd => $validate_cmd,
}
}
default: {
fail("${::kernel} is not supported by metricbeat.")
}
}
}
|