Skip to content

Commit

Permalink
add support for journal upload to a remote server
Browse files Browse the repository at this point in the history
  • Loading branch information
trefzer committed Aug 13, 2024
1 parent 7e2e187 commit 497329e
Show file tree
Hide file tree
Showing 7 changed files with 150 additions and 0 deletions.
36 changes: 36 additions & 0 deletions REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

* `systemd::coredump`: This class manages the systemd-coredump configuration.
* `systemd::install`: Install any systemd sub packages
* `systemd::journal_upload`: This class manages and configures journal-upload.
* `systemd::journald`: This class manages and configures journald.
* `systemd::logind`: This class manages systemd's login manager configuration.
* `systemd::machine_info`: This class manages systemd's machine-info file (hostnamectl)
Expand Down Expand Up @@ -56,6 +57,7 @@

* [`Systemd::CoredumpSettings`](#Systemd--CoredumpSettings): Configurations for coredump.conf
* [`Systemd::Dropin`](#Systemd--Dropin): custom datatype that validates filenames/paths for valid systemd dropin files
* [`Systemd::JournalUploadSettings`](#Systemd--JournalUploadSettings): Matches Systemd journal upload config Struct
* [`Systemd::JournaldSettings`](#Systemd--JournaldSettings): Matches Systemd journald config Struct
* [`Systemd::JournaldSettings::Ensure`](#Systemd--JournaldSettings--Ensure): defines allowed ensure states for systemd-journald settings
* [`Systemd::LogindSettings`](#Systemd--LogindSettings): Matches Systemd Login Manager Struct
Expand Down Expand Up @@ -126,6 +128,8 @@ The following parameters are available in the `systemd` class:
* [`set_local_rtc`](#-systemd--set_local_rtc)
* [`manage_journald`](#-systemd--manage_journald)
* [`journald_settings`](#-systemd--journald_settings)
* [`manage_journal_upload`](#-systemd--manage_journal_upload)
* [`journal_upload_settings`](#-systemd--journal_upload_settings)
* [`manage_udevd`](#-systemd--manage_udevd)
* [`udev_log`](#-systemd--udev_log)
* [`udev_children_max`](#-systemd--udev_children_max)
Expand Down Expand Up @@ -460,6 +464,22 @@ Config Hash that is used to configure settings in journald.conf

Default value: `{}`

##### <a name="-systemd--manage_journal_upload"></a>`manage_journal_upload`

Data type: `Boolean`

Manage the systemd journal upload to a remote server

Default value: `false`

##### <a name="-systemd--journal_upload_settings"></a>`journal_upload_settings`

Data type: `Systemd::JournalUploadSettings`

Config Hash that is used to configure settings in journal-upload.conf

Default value: `{}`

##### <a name="-systemd--manage_udevd"></a>`manage_udevd`

Data type: `Boolean`
Expand Down Expand Up @@ -2562,6 +2582,22 @@ custom datatype that validates filenames/paths for valid systemd dropin files

Alias of `Pattern['^[^/]+\.conf$']`

### <a name="Systemd--JournalUploadSettings"></a>`Systemd::JournalUploadSettings`

Matches Systemd journal upload config Struct

Alias of

```puppet
Struct[{
Optional['URL'] => Variant[Stdlib::HTTPUrl,Systemd::JournaldSettings::Ensure],
Optional['ServerKeyFile'] => Variant[Stdlib::Unixpath,Systemd::JournaldSettings::Ensure],
Optional['ServerCertificateFile'] => Variant[Stdlib::Unixpath,Systemd::JournaldSettings::Ensure],
Optional['TrustedCertificateFile'] => Variant[Stdlib::Unixpath,Systemd::JournaldSettings::Ensure],
Optional['NetworkTimeoutSec'] => Variant[Systemd::Unit::Timespan,Systemd::JournaldSettings::Ensure],
}]
```

### <a name="Systemd--JournaldSettings"></a>`Systemd::JournaldSettings`

Matches Systemd journald config Struct
Expand Down
1 change: 1 addition & 0 deletions data/Debian-family.yaml
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
---
systemd::nspawn_package: 'systemd-container'
systemd::journal_upload::package_name: 'systemd-journal-remote'
1 change: 1 addition & 0 deletions data/RedHat-family.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
systemd::networkd_package: systemd-networkd
systemd::nspawn_package: 'systemd-container'
systemd::resolved_package: 'systemd-resolved'
systemd::journal_upload::package_name: 'systemd-journal-remote'
12 changes: 12 additions & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,12 @@
# @param journald_settings
# Config Hash that is used to configure settings in journald.conf
#
# @param manage_journal_upload
# Manage the systemd journal upload to a remote server
#
# @param journal_upload_settings
# Config Hash that is used to configure settings in journal-upload.conf
#
# @param manage_udevd
# Manage the systemd udev daemon
#
Expand Down Expand Up @@ -253,6 +259,8 @@
Boolean $purge_dropin_dirs = true,
Boolean $manage_journald = true,
Systemd::JournaldSettings $journald_settings = {},
Boolean $manage_journal_upload = false,
Systemd::JournalUploadSettings $journal_upload_settings = {},
Systemd::MachineInfoSettings $machine_info_settings = {},
Boolean $manage_udevd = false,
Optional[Variant[Integer,String]] $udev_log = undef,
Expand Down Expand Up @@ -355,6 +363,10 @@
contain systemd::journald
}

if $manage_journal_upload {
contain systemd::journal_upload
}

if $manage_logind {
contain systemd::logind
}
Expand Down
38 changes: 38 additions & 0 deletions manifests/journal_upload.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# @api private
# @summary This class manages and configures journal-upload.
# @see https://www.freedesktop.org/software/systemd/man/journald.conf.html
#
# @param package_name
# name of the package to install for the functionality
#
class systemd::journal_upload (
Optional[String[1]] $package_name = undef,
) {
assert_private()

if $package_name {
stdlib::ensure_packages($package_name)
}

service { 'systemd-journal-upload':
ensure => running,
}
$systemd::journal_upload_settings.each |$option, $value| {
ini_setting {
$option:
path => '/etc/systemd/journal-upload.conf',
section => 'Upload',
setting => $option,
notify => Service['systemd-journal-upload'],
}
if $value =~ Hash {
Ini_setting[$option] {
* => $value,
}
} else {
Ini_setting[$option] {
value => $value,
}
}
}
}
50 changes: 50 additions & 0 deletions spec/classes/init_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,56 @@
it { is_expected.not_to contain_service('systemd-journald') }
end

context 'when journal-upload is enabled' do
let(:params) do
{
manage_journal_upload: true,
journal_upload_settings: {
'URL' => 'https://central.server:19532',
'ServerKeyFile' => '/tmp/key.pem',
'ServerCertificateFile' => '/tmp/cert.pem',
'TrustedCertificateFile' => {
'ensure' => 'absent',
},
},
}
end

it { is_expected.to compile.with_all_deps }
it { is_expected.to contain_service('systemd-journal-upload') }

it { is_expected.to have_ini_setting_resource_count(4) }

it {
expect(subject).to contain_ini_setting('URL').with(
path: '/etc/systemd/journal-upload.conf',
section: 'Upload',
notify: 'Service[systemd-journal-upload]',
value: 'https://central.server:19532'
)
}

it {
expect(subject).to contain_ini_setting('TrustedCertificateFile').with(
path: '/etc/systemd/journal-upload.conf',
section: 'Upload',
notify: 'Service[systemd-journal-upload]',
ensure: 'absent'
)
}
end

context 'when journal-upload is not enabled' do
let(:params) do
{
manage_journal_upload: false,
}
end

it { is_expected.to compile.with_all_deps }
it { is_expected.not_to contain_service('systemd-journal-upload') }
end

context 'when disabling udevd management' do
let(:params) do
{
Expand Down
12 changes: 12 additions & 0 deletions types/journaluploadsettings.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Matches Systemd journal upload config Struct
type Systemd::JournalUploadSettings = Struct[
# lint:ignore:140chars
{
Optional['URL'] => Variant[Stdlib::HTTPUrl,Systemd::JournaldSettings::Ensure],
Optional['ServerKeyFile'] => Variant[Stdlib::Unixpath,Systemd::JournaldSettings::Ensure],
Optional['ServerCertificateFile'] => Variant[Stdlib::Unixpath,Systemd::JournaldSettings::Ensure],
Optional['TrustedCertificateFile'] => Variant[Stdlib::Unixpath,Systemd::JournaldSettings::Ensure],
Optional['NetworkTimeoutSec'] => Variant[Systemd::Unit::Timespan,Systemd::JournaldSettings::Ensure],
}
# lint:endignore
]

0 comments on commit 497329e

Please sign in to comment.