Skip to content

Commit

Permalink
Syslog: write Nginx messages to separate files
Browse files Browse the repository at this point in the history
  • Loading branch information
sevein committed Oct 13, 2021
1 parent dca7b62 commit a5f61e7
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 19 deletions.
1 change: 1 addition & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ archivematica_src_configure_am_whitelist: '""' # Dashboard API whi
# Send logs to syslog
#
archivematica_src_syslog_enabled: "false"
archivematica_src_syslog_nginx_enabled: "false"
archivematica_src_syslog_server: "localhost"
archivematica_src_syslog_port: "514"
archivematica_src_syslog_storageservice_facility: "local0"
Expand Down
9 changes: 5 additions & 4 deletions templates/etc/nginx/sites-available/dashboard-ssl.conf.j2
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@ server {

listen 80;
server_name _;
{% if archivematica_src_syslog_enabled|bool %}
error_log syslog:server={{ archivematica_src_syslog_server }},tag=dashboard info;
access_log syslog:server={{ archivematica_src_syslog_server }},tag=dashboard combined;
{% endif %}

# Adjust to taste
client_max_body_size 256M;

{% if archivematica_src_syslog_enabled|bool and archivematica_src_syslog_nginx_enabled|bool %}
access_log syslog:server={{ archivematica_src_syslog_server }},tag=dashboard combined;
error_log syslog:server={{ archivematica_src_syslog_server }},tag=dashboard info;
{% endif %}

{% if archivematica_src_ssl_include_acme_chlg_loc|bool %}
# location for acme challenge (non-encrypted)
include /etc/nginx/acmetool-location.conf;
Expand Down
10 changes: 5 additions & 5 deletions templates/etc/nginx/sites-available/dashboard.conf.j2
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ upstream archivematica_dashboard_backend {
server {

listen 80;
server_name _;

# Adjust to taste
client_max_body_size 256M;

server_name _;
{% if archivematica_src_syslog_enabled|bool %}
error_log syslog:server={{ archivematica_src_syslog_server }},tag=dashboard info;
access_log syslog:server={{ archivematica_src_syslog_server }},tag=dashboard combined;
{% endif %}
{% if archivematica_src_syslog_enabled|bool and archivematica_src_syslog_nginx_enabled|bool %}
access_log syslog:server={{ archivematica_src_syslog_server }},tag=dashboard combined;
error_log syslog:server={{ archivematica_src_syslog_server }},tag=dashboard info;
{% endif %}

location / {
proxy_set_header Host $http_host;
Expand Down
7 changes: 4 additions & 3 deletions templates/etc/nginx/sites-available/storage-ssl.conf.j2
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ upstream archivematica_storage_service_backend {
server {

listen 8000 ssl;
{% if archivematica_src_syslog_enabled|bool %}
error_log syslog:server={{ archivematica_src_syslog_server }},tag=storage info;

{% if archivematica_src_syslog_enabled|bool and archivematica_src_syslog_nginx_enabled|bool %}
access_log syslog:server={{ archivematica_src_syslog_server }},tag=storage combined;
{% endif %}
error_log syslog:server={{ archivematica_src_syslog_server }},tag=storage info;
{% endif %}

ssl_certificate {{ archivematica_src_ssl_fullchain }};
ssl_certificate_key {{ archivematica_src_ssl_privkey }};
Expand Down
10 changes: 6 additions & 4 deletions templates/etc/nginx/sites-available/storage.conf.j2
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ server {

listen 8000;

{% if archivematica_src_syslog_enabled|bool %}
access_log syslog:server={{ archivematica_src_syslog_server }},tag=storage combined;
error_log syslog:server={{ archivematica_src_syslog_server }},tag=storage info;
{% endif %}

# Adjust to taste
client_max_body_size 256M;
{% if archivematica_src_syslog_enabled|bool %}
error_log syslog:server={{ archivematica_src_syslog_server }},tag=storage info;
access_log syslog:server={{ archivematica_src_syslog_server }},tag=storage combined;
{% endif %}

location / {
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
Expand Down
20 changes: 17 additions & 3 deletions templates/etc/rsyslog.d/archivematica.conf.j2
Original file line number Diff line number Diff line change
@@ -1,13 +1,27 @@
#Create templates
# Create templates.
$template AMLOG,"{{ archivematica_src_syslog_logdir }}/%$YEAR%/%$MONTH%/%$DAY%/%programname%.log"
{% if archivematica_src_syslog_nginx_enabled|bool %}
$template NGINXAMLOG,"/var/log/archivematica/%$YEAR%/%$MONTH%/%$DAY%/%programname%-access.log"
$template NGINXAMLOGERROR,"/var/log/archivematica/%$YEAR%/%$MONTH%/%$DAY%/%programname%-error.log"

#Log each service on it's own file
if (re_match($programname, '(dashboard|storage)') and $syslogseverity-text == 'error') then {
?NGINXAMLOGERROR
stop
}

if (re_match($programname, '(dashboard|storage)')) then {
?NGINXAMLOG
stop
}
{% endif %}

# Log each service on its own file.
{{ archivematica_src_syslog_storageservice_facility }}.* -?AMLOG
{{ archivematica_src_syslog_dashboard_facility }}.* -?AMLOG
{{ archivematica_src_syslog_mcpclient_facility }}.* -?AMLOG
{{ archivematica_src_syslog_mcpserver_facility }}.* -?AMLOG

#Stop processing
# Stop processing.
{{ archivematica_src_syslog_storageservice_facility }}.* stop
{{ archivematica_src_syslog_dashboard_facility }}.* stop
{{ archivematica_src_syslog_mcpclient_facility }}.* stop
Expand Down

0 comments on commit a5f61e7

Please sign in to comment.