From 11db9bde0436153442b6733ade93cb90ecaa3737 Mon Sep 17 00:00:00 2001 From: Juan Pablo Firrincieli Date: Thu, 27 Nov 2025 13:02:35 +0100 Subject: [PATCH 1/3] Added optional nagios::server::log_archives_mtime to delete old files from `/var/log/nagios/archives` with a cronjob in nagios user --- README.md | 28 ++++++++++++++++++++++++++++ manifests/server.pp | 11 +++++++++++ 2 files changed, 39 insertions(+) diff --git a/README.md b/README.md index 23f4528..00ab3c7 100644 --- a/README.md +++ b/README.md @@ -146,6 +146,34 @@ To override the parameters of a default template using hiera : nagios::server::template_generic_service: notification_options: 'u,c,r' ``` +### Log archive retention + +By default, Nagios log archives under `/var/log/nagios/archives` are kept +forever. You can optionally enable automatic cleanup by setting the +`log_archives_mtime` parameter on `nagios::server`. + +This value is passed directly to `find -mtime`, so it supports the same formats +as `find` (for example: `+365`, `+30`, `7`, `-1`, etc.). When set, a daily cron +job is created (running as the `nagios` user) to delete old files from +`/var/log/nagios/archives`. + +Example, keep only the last year of archives: + +```puppet +class { '::nagios::server': + log_archives_mtime => '+365', + # ...other parameters... +} +```` + +or from hieradata: + +```yaml +nagios::server::log_archives_mtime: '+365' +``` + +If `log_archives_mtime` is left unset (the default), no cron job is created and +archives are never deleted. ## Hints diff --git a/manifests/server.pp b/manifests/server.pp index 91512ff..920168a 100644 --- a/manifests/server.pp +++ b/manifests/server.pp @@ -100,6 +100,7 @@ $plugin_redis_sentinel = false, $selinux = true, $check_for_updates = true, + $log_archives_mtime = undef, # Original template entries $template_generic_contact = {}, $template_generic_host = {}, @@ -1340,4 +1341,14 @@ } } + # When $log_archives_mtime we configure the prune job + if $log_archives_mtime { + cron { 'nagios-archives-prune': + ensure => present, + user => 'nagios', + minute => '15', + hour => '3', + command => "/usr/bin/find /var/log/nagios/archives -type f -name 'nagios-*.log*' -mtime ${log_archives_mtime} -delete", + } + } } From e700b8bf3692e42a825436442f0919dcf8b001f2 Mon Sep 17 00:00:00 2001 From: Juan Pablo Firrincieli Date: Thu, 27 Nov 2025 14:09:10 +0100 Subject: [PATCH 2/3] Shorter readme and log_archives_retention_days type integer to avoid doing the opposite of what we want by mistake --- README.md | 25 ++++++++----------------- manifests/server.pp | 4 ++-- 2 files changed, 10 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 00ab3c7..e086003 100644 --- a/README.md +++ b/README.md @@ -148,33 +148,24 @@ nagios::server::template_generic_service: ``` ### Log archive retention -By default, Nagios log archives under `/var/log/nagios/archives` are kept -forever. You can optionally enable automatic cleanup by setting the -`log_archives_mtime` parameter on `nagios::server`. +Set `log_archives_retention_days` to automatically delete archives in +`/var/log/nagios/archives` older than the specified number of days +(default: keep everything). -This value is passed directly to `find -mtime`, so it supports the same formats -as `find` (for example: `+365`, `+30`, `7`, `-1`, etc.). When set, a daily cron -job is created (running as the `nagios` user) to delete old files from -`/var/log/nagios/archives`. - -Example, keep only the last year of archives: +Example: ```puppet class { '::nagios::server': - log_archives_mtime => '+365', - # ...other parameters... + log_archives_retention_days => 365, } -```` +``` -or from hieradata: +Hiera: ```yaml -nagios::server::log_archives_mtime: '+365' +nagios::server::log_archives_retention_days: 365 ``` -If `log_archives_mtime` is left unset (the default), no cron job is created and -archives are never deleted. - ## Hints Debug any startup or configuration problems on the server with : diff --git a/manifests/server.pp b/manifests/server.pp index 920168a..a50c5e2 100644 --- a/manifests/server.pp +++ b/manifests/server.pp @@ -100,7 +100,7 @@ $plugin_redis_sentinel = false, $selinux = true, $check_for_updates = true, - $log_archives_mtime = undef, + Optional[Integer] $log_archives_mtime = undef, # Original template entries $template_generic_contact = {}, $template_generic_host = {}, @@ -1348,7 +1348,7 @@ user => 'nagios', minute => '15', hour => '3', - command => "/usr/bin/find /var/log/nagios/archives -type f -name 'nagios-*.log*' -mtime ${log_archives_mtime} -delete", + command => "/usr/bin/find /var/log/nagios/archives -type f -name 'nagios-*.log*' -mtime +${log_archives_mtime} -delete", } } } From e028eeedba19aba04f0bca127d4552ec33dc9d54 Mon Sep 17 00:00:00 2001 From: Juan Pablo Firrincieli Date: Thu, 27 Nov 2025 14:26:34 +0100 Subject: [PATCH 3/3] Fixed a typo in the Readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e086003..817de30 100644 --- a/README.md +++ b/README.md @@ -137,11 +137,11 @@ To enable nagiosgraph for the client's services in the server web interface : class { '::nagios::client': service_use => 'generic-service,nagiosgraph-service', } +``` To override the parameters of a default template using hiera : ```yaml ---- # Remove default warning notifications for services nagios::server::template_generic_service: notification_options: 'u,c,r'