From 2374fc613747982b2feeaa0a8bbc2ffba9a6f31e Mon Sep 17 00:00:00 2001 From: Arne Teuke Date: Mon, 24 Feb 2025 13:24:45 +0100 Subject: [PATCH] add configuration and service --- manifests/main/files.pp | 15 +++++++++++++++ manifests/main/service.pp | 6 ++++++ manifests/params.pp | 22 ++++++++++++++++------ templates/config.alloy.erb | 23 +++++++++++++++++++++++ 4 files changed, 60 insertions(+), 6 deletions(-) create mode 100644 templates/config.alloy.erb diff --git a/manifests/main/files.pp b/manifests/main/files.pp index 0e74a2d..a6023fc 100644 --- a/manifests/main/files.pp +++ b/manifests/main/files.pp @@ -9,4 +9,19 @@ class cd_alloy::main::files ( require cd_alloy::main::dirs + # Ensure log_targets is always an array + $log_targets_array = Array($cd_alloy::params::ay_log_targets, true) + + file { $ay_main_file: + ensure => file, + owner => 'root', + group => 'root', + mode => '0644', + selrange => s0, + selrole => object_r, + seltype => etc_t, + seluser => system_u, + content => template('cd_alloy/config.alloy.erb'), + } + } diff --git a/manifests/main/service.pp b/manifests/main/service.pp index 31a4a30..5163427 100644 --- a/manifests/main/service.pp +++ b/manifests/main/service.pp @@ -9,4 +9,10 @@ class cd_alloy::main::service ( require cd_alloy::main::files + service { $ay_service: + ensure => running, + hasstatus => true, + hasrestart => true, + enable => true, + } } diff --git a/manifests/params.pp b/manifests/params.pp index 3b97929..4e88eaf 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -1,22 +1,32 @@ ## cd_alloy::params.pp # Module name: cd_alloy # Author: Arne Teuke (arne_teuke@confdroid.com) -# @param [string] reqpackages which packages to install -# @param [string] pkg_ensure 'latest' or 'present' +# @param [string] reqpackages which packages to install +# @param [string] pkg_ensure 'latest' or 'present' +# @param [string] ay_loki_username the username to logon to loki +# @param [string] ay_loki_userpass the password to logon to loki # @summary Class contains all parameters for the cd_alloy module. ############################################################################## class cd_alloy::params ( -$reqpackages = 'alloy', -$pkg_ensure = 'latest', +$reqpackages = 'alloy', +$pkg_ensure = 'latest', + +# loki +$ay_loki_url = 'https://loki.example.net/loki/api/v1/push' +$ay_loki_username = '', +$ay_loki_userpass = '', ) { # service -$ay_service = 'alloy' +$ay_service = 'alloy' # dirs -$ay_main_dir = '/etc/alloy' +$ay_main_dir = '/etc/alloy' + +# files +$ay_main_file = "$(ay_main_dir)/config.alloy" # includes must be last diff --git a/templates/config.alloy.erb b/templates/config.alloy.erb new file mode 100644 index 0000000..a29e2a0 --- /dev/null +++ b/templates/config.alloy.erb @@ -0,0 +1,23 @@ +logging { + level = "info" + format = "logfmt" +} + +loki.source.file "system_logs" { + targets = [ +<% @log_targets_array.each do |target| -%> + {__path__ = "<%= target %>"}, +<% end -%> + ] + forward_to = [loki.write.loki.receiver] +} + +loki.write "loki" { + endpoint { + url = "https://loki.confdroid.com/loki/api/v1/push" + basic_auth { + username = "<%= @ay_loki_username %>" + password = "<%= @ay_loki_userpass %>" + } + } +} \ No newline at end of file