Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple outputs #277

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
430 changes: 237 additions & 193 deletions manifests/config.pp

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion manifests/input.pp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
content => template("${module_name}/${input_template}"),
validate_cmd => $validate_cmd,
notify => Service['filebeat'],
require => File['filebeat.yml'],
require => Class['filebeat::config'],
}
}

Expand Down
4 changes: 2 additions & 2 deletions manifests/install.pp
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
}
Anchor['filebeat::install::begin'] -> Class['filebeat::install::linux'] -> Anchor['filebeat::install::end']
if $::filebeat::manage_repo {
class { '::filebeat::repo': }
Class['filebeat::repo'] -> Class['filebeat::install::linux']
include elastic_stack::repo
Class['elastic_stack::repo'] -> Class['filebeat::install::linux']
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I love the idea of using the upstream elastic repo as suggested in #189, but we customize a few things in the setup. I think it's reasonable to ask users that need those customizations to set manage_repo to false and manage it themselves, but we should probably remove references to the parameters too (README, params.pp, init.pp).

}
}
'FreeBSD': {
Expand Down
4 changes: 3 additions & 1 deletion manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
$enable_conf_modules = false
$fields = {}
$fields_under_root = false
$http = {}
$http = { 'enabled' => false }
$cloud = {}
$outputs = {}
$shipper = {}
Expand All @@ -33,6 +33,8 @@
$xpack = undef
$systemd_override_dir = '/etc/systemd/system/filebeat.service.d'
$systemd_beat_log_opts_template = "${module_name}/systemd/logging.conf.erb"
$systemd_service_template = "${module_name}/systemd/filebeat.service.erb"
$systemd_composite_service_template = "${module_name}/systemd/filebeat.composite.service.erb"

# These are irrelevant as long as the template is set based on the major_version parameter
# if versioncmp('1.9.1', $::rubyversion) > 0 {
Expand Down
76 changes: 0 additions & 76 deletions manifests/repo.pp

This file was deleted.

55 changes: 51 additions & 4 deletions manifests/service.pp
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,22 @@
#
# @summary Manage the filebeat service
class filebeat::service {
service { 'filebeat':
ensure => $filebeat::real_service_ensure,
enable => $filebeat::real_service_enable,
provider => $filebeat::service_provider,
if keys($filebeat::outputs).length <= 1 {
service { 'filebeat':
ensure => $filebeat::real_service_ensure,
enable => $filebeat::real_service_enable,
provider => $filebeat::service_provider,
}
}
else {
systemd::unit_file { "filebeat.service":
content => template($filebeat::systemd_composite_service_template),
}
~> service {'filebeat':
enable => $filebeat::real_service_enable,
ensure => $filebeat::real_service_ensure,
provider => $filebeat::service_provider,
}
}

$major_version = $filebeat::major_version
Expand Down Expand Up @@ -65,5 +77,40 @@
}
}
}
}
define filebeat::service::add {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we split the defined type in to its own file.

We might want to think about titling this one a little different too since we're not creating a new "add". I don't have another idea yet though.

if $::service_provider == 'systemd' {
if $name == $filebeat::module_name {
$service_name = $name
}
else {
$service_name = "${filebeat::module_name}.${name}"
file { "/var/lib/filebeat/${name}":
ensure => directory,
mode => '0750',
owner => $filebeat::config_file_owner,
group => $filebeat::config_file_group,
before => Systemd::Unit_file["${filebeat::module_name}.${name}.service"],
}
file { "/var/log/filebeat/${name}":
ensure => directory,
mode => '0700',
owner => $filebeat::config_file_owner,
group => $filebeat::config_file_group,
before => Systemd::Unit_file["${filebeat::module_name}.${name}.service"],
}
}
systemd::unit_file { "${service_name}.service":
content => template($filebeat::systemd_service_template),
}
~> service {"${service_name}":
enable => $filebeat::real_service_enable,
ensure => $filebeat::real_service_ensure,
provider => $filebeat::service_provider,
}

}
else {
warning("You\'re trying to add service to systemd for the additional output '${name}', but the system is using '${::service_provider}' instead of systemd.")
}
}
8 changes: 8 additions & 0 deletions metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@
{
"name": "puppetlabs/yumrepo_core",
"version_requirement": ">= 1.0.0 < 2.0.0"
},
{
"name": "camptocamp-systemd",
"version_requirement": ">= 2.0.0 < 3.0.0"
},
{
"name": "elastic-elastic_stack",
"version_requirement": ">= 7.0.0 < 8.0.0"
}
],
"operatingsystem_support": [
Expand Down
13 changes: 13 additions & 0 deletions templates/systemd/filebeat.composite.service.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[Unit]
Description=Filebeat composite service to start multiple outputs.
Documentation=https://www.elastic.co/products/beats/filebeat
Wants=network-online.target
After=network-online.target

[Service]
Type=oneshot
ExecStart=/bin/true
RemainAfterExit=yes

[Install]
WantedBy=multi-user.target
15 changes: 15 additions & 0 deletions templates/systemd/filebeat.service.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[Unit]
Description=Filebeat sends log files to <%= @name %>.
Documentation=https://www.elastic.co/products/beats/filebeat
Wants=network-online.target
After=network-online.target

[Service]
Environment="BEAT_LOG_OPTS="
Environment="BEAT_CONFIG_OPTS=-c /etc/filebeat/filebeat.<%= @name %>.yml"
Environment="BEAT_PATH_OPTS=--path.home /usr/share/filebeat --path.config /etc/filebeat --path.data /var/lib/filebeat/<%= @name %> --path.logs /var/log/filebeat/<%= @name %>"
ExecStart=/usr/share/filebeat/bin/filebeat --environment systemd $BEAT_LOG_OPTS $BEAT_CONFIG_OPTS $BEAT_PATH_OPTS
Restart=always

[Install]
WantedBy=filebeat.service