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

Adjust logs for containerized and non-containerized services #7043

Merged
merged 26 commits into from
Jul 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
7c14fdb
disable docker logs for all containers
nqb Jun 24, 2022
b68154e
draft existing services
nqb Jun 24, 2022
f7298d3
draft new services
nqb Jun 24, 2022
0d62a04
use syslogtag in place of programname to handle specific cases
nqb Jun 27, 2022
62bc666
split Apache requests and application requests for containerized serv…
nqb Jun 27, 2022
c08e89b
pkg: logfiles are created by rsyslog with correct rights
nqb Jun 27, 2022
ba6015a
start rsyslog early to use rules ASAP
nqb Jun 27, 2022
054a84d
logrotate: create httpd-requests without extension to rotate properly
nqb Jun 27, 2022
ec8b5bd
update wording in web admin
nqb Jun 27, 2022
7daed4e
checkup permissions is wrong
nqb Jun 27, 2022
4881a38
refresh list of log files
nqb Jun 27, 2022
5dd6a85
fixpermissions should not modify log dir or log files
nqb Jun 27, 2022
72b9643
rename httpd-requests in httpd.apache
nqb Jun 28, 2022
b504d6f
adjust rsyslog rules
nqb Jun 29, 2022
3968b1d
docs: update related to logs
nqb Jun 29, 2022
daa2571
create logs directory with new permissions
nqb Jun 30, 2022
2eb959d
handle innobackup.log file
nqb Jun 30, 2022
229a285
add upgrade script
nqb Jul 4, 2022
565d08e
exclude log dir and files from chown
nqb Jul 5, 2022
7d632b7
reverse rsyslog rules to catch Apache requests as a fallback
nqb Jul 5, 2022
d22c909
redirect GIN requests in fingerbank.log
nqb Jul 5, 2022
d3f2447
create an haproxy.log to catch generic haproxy messages
nqb Jul 5, 2022
784a48d
catch /usr/local/pf/sbin/galera-autofix
nqb Jul 5, 2022
32cf566
expose /var/log in read-only to live-view /var/log/syslog,messages
nqb Jul 5, 2022
05df6a6
Update docs/installation/best_practices.asciidoc
nqb Jul 6, 2022
2b62362
rotate old httpd.* log files after upgrade
nqb Jul 6, 2022
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
91 changes: 91 additions & 0 deletions addons/upgrade/to-12.0-rename-log-files.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
#!/usr/bin/perl

=head1 NAME

to-12.0-rename-log-files.pl

=head1 DESCRIPTION

Rename log files defined in logs= in syslog.conf

=cut

use strict;
use warnings;
use lib qw(/usr/local/pf/lib /usr/local/pf/lib_perl/lib/perl5);
use pf::util;
use pf::IniFiles;
use pf::constants::config;
use pf::file_paths qw(
$conf_dir
$syslog_config_file
);
use List::MoreUtils qw(any);

run_as_pf();

my %remap = (
'mariadb_error.log' => 'mariadb.log',
'httpd.aaa.access' => 'httpd.apache',
'httpd.aaa.error' => 'httpd.apache',
'httpd.collector.log' => 'httpd.apache',
'httpd.collector.error' => 'httpd.apache',
'httpd.portal.error' => 'httpd.apache',
'httpd.portal.access' => 'httpd.apache',
'httpd.portal.catalyst' => 'httpd.apache',
'httpd.proxy.error' => 'httpd.apache',
'httpd.proxy.access' => 'httpd.apache',
'httpd.webservices.error' => 'httpd.apache',
'httpd.webservices.access' => 'httpd.apache',
'httpd.api-frontend.access' => 'httpd.apache',
);

my $ini = pf::IniFiles->new( -file => $syslog_config_file, -allowempty => 1);
my $i = 0;

for my $section ($ini->Sections()) {
if (my $logs = $ini->val($section, 'logs')) {
$logs = [ split(/,/, $logs) ];

if(any {exists $remap{$_}} @$logs) {
print "Renaming log files in section $section in file $syslog_config_file\n";
$logs = [ map { exists($remap{$_}) ? $remap{$_} : $_ } @$logs ];
$ini->setval($section, 'logs', join(',', @$logs));
$i |= 1;
}
}
}
if ($i) {
$ini->RewriteConfig();
print "All done\n";
} else {
print "Nothing to be done\n";
}

=head1 AUTHOR

Inverse inc. <info@inverse.ca>

=head1 COPYRIGHT

Copyright (C) 2005-2022 Inverse inc.

=head1 LICENSE

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
USA.

=cut

8 changes: 4 additions & 4 deletions conf/monitoring/statsd.d/packetfence.conf.example
Original file line number Diff line number Diff line change
Expand Up @@ -163,15 +163,15 @@
type = line
dimension = pattern 'source.packetfence.radius_log.*' '' last 1 1

[logs.mariadb_error_log]
name = packetfence.mariadb_error_log
title = mariadb_error.log file events
[logs.mariadb_log]
name = packetfence.mariadb_log
title = mariadb.log file events
family = packetfence
context = chart.context
units = Events
priority = 91000
type = line
dimension = pattern 'source.packetfence.mariadb_error_log.*' '' last 1 1
dimension = pattern 'source.packetfence.mariadb_log.*' '' last 1 1

[logs.pfcron_log]
name = packetfence.pfcron_log
Expand Down
6 changes: 3 additions & 3 deletions conf/stats.conf.defaults
Original file line number Diff line number Diff line change
Expand Up @@ -239,11 +239,11 @@ match=ERROR
statsd_ns=source.packetfence.radius_acct_log.error
management=false

[metric 'Events in mariadb_error.log']
[metric 'Events in mariadb.log']
type=tail_file
file=/usr/local/pf/logs/mariadb_error.log
file=/usr/local/pf/logs/mariadb.log
match=DESYNCED
statsd_ns=source.packetfence.mariadb_error_log.desynced
statsd_ns=source.packetfence.mariadb_log.desynced
management=false

[metric 'Events in pfcron.log']
Expand Down
1 change: 1 addition & 0 deletions containers/daemon.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"log-driver": "none",
"default-address-pools": [
{
"base": "100.64.0.0/10",
Expand Down
2 changes: 0 additions & 2 deletions debian/packetfence-redis-cache.postinst
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ DIST=$(lsb_release -c -s)
case "$1" in
configure)
export PACKETFENCE=/usr/local/pf
chmod 2775 -R $PACKETFENCE/logs
chmod 2775 -R $PACKETFENCE/var
chown pf:pf $PACKETFENCE/logs
chown pf:pf $PACKETFENCE/var
if [ ${DIST} = "wheezy" ] || [ ${DIST} = "precise" ]; then
update-rc.d packetfence-redis-cache defaults 60 || exit 0
Expand Down
21 changes: 6 additions & 15 deletions debian/packetfence.postinst
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ case "$1" in
chmod 2775 -R $PACKETFENCE/var
find $PACKETFENCE/var/conf -type f -exec chmod 664 '{}' \;
find $PACKETFENCE/var/conf -type d -exec chmod 775 '{}' \;
chmod 2775 -R $PACKETFENCE/logs
chmod 0755 $PACKETFENCE/addons/*.pl
chmod 0755 $PACKETFENCE/addons/*.sh
chmod 0755 $PACKETFENCE/addons/upgrade/*.pl
Expand All @@ -42,7 +41,8 @@ case "$1" in
chmod ug+s $PACKETFENCE/bin/pfcmd

chown pf:pf $PACKETFENCE
find $PACKETFENCE '(' -type d -or -type f ')' -not -name pfcmd -print0 | xargs -0 chown pf:pf
find $PACKETFENCE '(' -type d -or -type f ')' -not -name pfcmd -not -path "$PACKETFENCE/logs*" -print0 | xargs -0 chown pf:pf
chgrp pf $PACKETFENCE/logs

# link to latest SQL schema
if [ -h "$PACKETFENCE/db/pf-schema.sql" ]; then
Expand All @@ -52,15 +52,6 @@ case "$1" in
VERSIONSQL=$(ls pf-schema-* |sort --version-sort -r | head -1)
ln -f -s $VERSIONSQL ./pf-schema.sql

#Check if log files exist and create them with the correct owner
for fic_log in packetfence.log
do
if [ ! -e /usr/local/pf/logs/$fic_log ]; then
touch /usr/local/pf/logs/$fic_log
chown pf.pf /usr/local/pf/logs/$fic_log
fi
done

#Make ssl certificate
cd /usr/local/pf
make conf/ssl/server.pem
Expand Down Expand Up @@ -140,8 +131,12 @@ case "$1" in
echo "Setting packetfence.target as the default systemd target."
/bin/systemctl set-default packetfence.target
fi

systemctl daemon-reload
echo "Restarting journald to enable persistent logging"
/bin/systemctl restart systemd-journald
echo "Restarting rsyslog"
systemctl restart rsyslog

# get containers image and tag them locally
/usr/local/pf/containers/manage-images.sh
Expand All @@ -152,7 +147,6 @@ case "$1" in
systemctl disable packetfence-iptables
systemctl enable packetfence-haproxy-admin
systemctl enable packetfence-tracking-config.path
systemctl daemon-reload
systemctl restart docker
systemctl start packetfence-config
/usr/local/pf/bin/pfcmd generatemariadbconfig --force
Expand All @@ -162,9 +156,6 @@ case "$1" in
printf '[client-server]\nsocket = /var/lib/mysql/mysql.sock\n' > /etc/mysql/mariadb.conf.d/999-socket-override.cnf
sed -i 's#^socket\s*=.*#socket=/var/lib/mysql/mysql.sock#' /etc/mysql/my.cnf

echo "Restarting rsyslog"
systemctl restart rsyslog

perl /usr/local/pf/addons/upgrade/add-default-params-to-auth.pl
set +e
/usr/local/pf/bin/pfcmd configreload
Expand Down
2 changes: 1 addition & 1 deletion debian/rules
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ install: build
install -d -m0700 $(CURDIR)/debian/packetfence$(PREFIX)/$(NAME)/conf/ssl
install -d -m0700 $(CURDIR)/debian/packetfence$(PREFIX)/$(NAME)/conf/ssl/acme-challenge
install -d -m0700 $(CURDIR)/debian/packetfence$(PREFIX)/$(NAME)/raddb/sites-enabled
install -d -m2770 $(CURDIR)/debian/packetfence$(PREFIX)/$(NAME)/logs
install -d -m0750 $(CURDIR)/debian/packetfence$(PREFIX)/$(NAME)/logs
install -d -m2770 $(CURDIR)/debian/packetfence$(PREFIX)/$(NAME)/var/conf
install -d -m2770 $(CURDIR)/debian/packetfence$(PREFIX)/$(NAME)/var/cache
install -d -m2770 $(CURDIR)/debian/packetfence$(PREFIX)/$(NAME)/var/cache/ntlm_cache_users
Expand Down
4 changes: 2 additions & 2 deletions docs/cluster/appendix.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ mysql -u root -p pf -h localhost
----

If its not, make sure you check the MariaDB log
([filename]`/usr/local/pf/logs/mariadb_error.log`)
([filename]`/usr/local/pf/logs/mariadb.log`)

===== Sync nodes A and B

Expand All @@ -337,7 +337,7 @@ rm -fr /var/lib/mysql/*
systemctl start packetfence-mariadb
----

Should there be any issues during the sync, make sure you look into the MariaDB log ([filename]`/usr/local/pf/logs/mariadb_error.log`)
Should there be any issues during the sync, make sure you look into the MariaDB log ([filename]`/usr/local/pf/logs/mariadb.log`)

Once both nodes have completely synced (try connecting to it using the MariaDB
command line), then you can break the cluster election command you have
Expand Down
4 changes: 2 additions & 2 deletions docs/cluster/troubleshooting_a_cluster.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Important variables:
* `wsrep_last_committed`: Sequence number of the most recently committed transaction. You can identify the most advanced node with this value.
* `wsrep_local_state_comment`: Current sync state of the cluster. A healthy state is 'Synced'. Refer to the Galera cluster documentation for the meaning of the other values this can have.

In order for the cluster to be considered healthy, all nodes must be listed under `wsrep_incoming_addresses` and `wsrep_local_state_comment` must be `Synced`. Otherwise look in the MariaDB log ([filename]`/usr/local/pf/logs/mariadb_error.log`)
In order for the cluster to be considered healthy, all nodes must be listed under `wsrep_incoming_addresses` and `wsrep_local_state_comment` must be `Synced`. Otherwise look in the MariaDB log ([filename]`/usr/local/pf/logs/mariadb.log`)

=== Automatic clustering resolution service: galera-autofix

Expand Down Expand Up @@ -123,7 +123,7 @@ systemctl start packetfence-mariadb
You should then see `/var/lib/mysql` be populated again with the data and once
MariaDB becomes available again on the server, it means the sync has
completed. In case of issues, look in the MariaDB log file
(`/usr/local/pf/logs/mariadb_error.log`)
(`/usr/local/pf/logs/mariadb.log`)

WARNING: After stopping the `packetfence-mariadb` service, be sure there is no more `mysql` process running.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ endif::[]

The Galera cluster stack used by PacketFence resembles a lot to how a normal MariaDB Galera cluster behaves but it contains hooks to auto-correct some issues that can occur.

NOTE: A lot of useful information is logged in the MariaDB log which can be found in `/usr/local/pf/logs/mariadb_error.log`
NOTE: A lot of useful information is logged in the MariaDB log which can be found in `/usr/local/pf/logs/mariadb.log`

=== Quorum behavior

Expand Down
2 changes: 1 addition & 1 deletion docs/installation/appendix.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ For Mariabackup:
# chown -R mysql: /var/lib/mysql
# service packetfence-mariadb start

Should the service fail to start, make sure you look into the MariaDB error logs.
Should the service fail to start, make sure you look into the MariaDB logs.

[appendix]
=== How to restore a standalone PacketFence server ?
Expand Down
2 changes: 1 addition & 1 deletion docs/installation/best_practices.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ IPTables is now entirely managed by PacketFence. However, if you need to perform

=== Log Rotations

PacketFence can generate a lot of log entries in huge production environments. This is why we recommend to use `logrotate` to periodically rotate your logs. A working logrotate script is provided with the PacketFence package. This script is located under the `/usr/local/pf/packetfence.logrotate` file, and it's configured to do a daily log rotation and keeping old logs with compression. It has been added during PacketFence initial installation.
PacketFence can generate a lot of log entries in huge production environments. This is why we recommend to use `logrotate` to periodically rotate your logs. A working logrotate script is provided with the PacketFence package. This script is located inside the logrotate directory (`/etc/logrotate.d/`), and it's configured to do a daily log rotation and keeping old logs with compression. It has been added during PacketFence initial installation.

=== Large Registration Network

Expand Down
17 changes: 3 additions & 14 deletions docs/installation/troubleshooting_packetfence.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,9 @@ PacketFence provides a RADIUS auditing module which allows you to be aware of al

=== Log files

Here are the most important PacketFence log files:

[options="compact"]
* `/usr/local/pf/logs/packetfence.log` — PacketFence Core Log
* `/usr/local/pf/logs/httpd.portal.access` — Apache – Captive Portal Access Log
* `/usr/local/pf/logs/httpd.portal.error` — Apache – Captive Portal Error Log
* `/usr/local/pf/logs/httpd.admin.access` — Apache – Web Admin/Services Access Log
* `/usr/local/pf/logs/httpd.admin.error` — Apache – Web Admin/Services Error Log
* `/usr/local/pf/logs/httpd.webservices.access` — Apache – Webservices Access Log
* `/usr/local/pf/logs/httpd.webservices.error` — Apache – Webservices Error Log
* `/usr/local/pf/logs/httpd.aaa.access` — Apache – AAA Access Log
* `/usr/local/pf/logs/httpd.aaa.error` — Apache – AAA Error Log

There are other log files in [filename]`/usr/local/pf/logs/` that could be relevant depending on what issue you are experiencing. Make sure you take a look at them.
Log files are located under [filename]`/usr/local/pf/logs`. Except
[filename]`packetfence.log` which contains logs from different services, each
service has its own log file. You can see full list of log files available when using _Audit -> Live logs_ menu in web admin.

The main logging configuration file is [filename]`/usr/local/pf/conf/log.conf`. It contains the configuration for the `packetfence.log` file (`Log::Log4Perl`) and you normally don't need to modify it. The logging configuration files for every service are located under [filename]`/usr/local/pf/conf/log.conf.d/`.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ export default [
]
},
{
name: 'mariadb_error.log',
name: 'mariadb.log',
items: [
{
title: 'Number of events', // i18n defer
metric: 'packetfence.logs.mariadb_error_log',
metric: 'packetfence.logs.mariadb_log',
mode: modes.COMBINED,
library: libraries.DYGRAPH,
cols: 12
Expand Down Expand Up @@ -90,4 +90,4 @@ export default [
}
]
}
]
]
1 change: 0 additions & 1 deletion lib/pf/action.pm
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ use pf::class qw(class_view);
use pf::security_event qw(security_event_force_close);
use pf::Connection::ProfileFactory;
use pf::constants::scan qw($POST_SCAN_SECURITY_EVENT_ID $PRE_SCAN_SECURITY_EVENT_ID $SCAN_SECURITY_EVENT_ID);
use pf::file_paths qw($security_event_log);

our $logger = get_logger();

Expand Down
11 changes: 2 additions & 9 deletions lib/pf/cmd/pf/fixpermissions.pm
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,13 @@ Fix the permissions on pf and fingerbank files
sub action_all {
my $pfcmd = "${bin_dir}/pfcmd";
my @extra_var_dirs = map { catfile($var_dir,$_) } qw(run cache conf sessions redis_cache redis_queue);
_changeFilesToOwner('pf',@log_files, @stored_config_files, $install_dir, $bin_dir, $conf_dir, $var_dir, $lib_dir, $log_dir, $generated_conf_dir, $tt_compile_cache_dir, $pfconfig_cache_dir, @extra_var_dirs, $config_version_file, $iptable_config_file);
_changeFilesToOwner('pf', @stored_config_files, $install_dir, $bin_dir, $conf_dir, $var_dir, $lib_dir, $generated_conf_dir, $tt_compile_cache_dir, $pfconfig_cache_dir, @extra_var_dirs, $config_version_file, $iptable_config_file);
_changePathToOwnerRecursive('pf', $html_dir);
_changeFilesToOwner('root',$pfcmd);
chmod($PFCMD_MODE, $pfcmd);
chmod(0664, @stored_config_files, $iptable_config_file, $config_version_file);
chmod($DIR_MODE, $conf_dir, $var_dir, $log_dir, "$var_dir/redis_cache", "$var_dir/redis_queue");
chmod($DIR_MODE, $conf_dir, $var_dir, "$var_dir/redis_cache", "$var_dir/redis_queue");
_fingerbank();
find({ wanted => \&wanted,untaint => 1}, $log_dir);
print "Fixed permissions.\n";
return $EXIT_SUCCESS;
}
Expand Down Expand Up @@ -164,12 +163,6 @@ sub _fingerbank {
fingerbank::Util::fix_permissions();
}

sub wanted {
return if $File::Find::name eq $log_dir;
my $perm = -d $File::Find::name ? 02775 : 0664;
chmod $perm, untaint_chain($File::Find::name);
}

=head1 AUTHOR

Inverse inc. <info@inverse.ca>
Expand Down
Loading