From 3c1de0360ef1cae899fa3c97ecdea93706d072aa Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Tue, 12 May 2020 07:11:12 -0400 Subject: [PATCH] Bug 25464 - Add ability to specify client IP and SIP account used in SIP2 logging Bug 15253 originally had the ability to specify the incoming IP address used for a given log statement via SIP, as well as the SIP2 account that was in use at the time. This data is very helpful for debugging purposes, and should be brought back. Test Plan: 1) Apply this patch 2) Update you SIP ConversionPattern to "[%d] [%p] %X{accountid}@%X{peeraddr}: %m %l %n" 3) Restart SIP 4) Use the SIP cli tester to make some SIP requests 5) View the SIP2 log, note the account id and client ip address show in the log! --- C4/SIP/SIPServer.pm | 8 ++++++++ debian/koha-common.postinst | 2 +- debian/templates/log4perl-site.conf.in | 2 +- etc/log4perl.conf | 2 +- 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/C4/SIP/SIPServer.pm b/C4/SIP/SIPServer.pm index 7af355465d..b14aaa9862 100755 --- a/C4/SIP/SIPServer.pm +++ b/C4/SIP/SIPServer.pm @@ -105,6 +105,10 @@ sub process_request { $self->{account} = undef; # Clear out the account from the last request, it may be different $self->{logger} = set_logger( Koha::Logger->get( { interface => 'sip' } ) ); + # Flush previous MDCs to prevent accidentally leaking incorrect MDC-entries + Log::Log4perl::MDC->put( "accountid", undef ); + Log::Log4perl::MDC->put( "peeraddr", undef ); + my $sockname = getsockname(STDIN); # Check if socket connection is IPv6 before resolving address @@ -179,6 +183,10 @@ sub raw_transport { ) ); + # Set MDCs after properly authenticating + Log::Log4perl::MDC->put( "accountid", $self->{account}->{id} ); + Log::Log4perl::MDC->put( "peeraddr", $self->{server}->{peeraddr} ); + siplog("LOG_DEBUG", "raw_transport: uname/inst: '%s/%s'", $self->{account}->{id}, $self->{account}->{institution}); diff --git a/debian/koha-common.postinst b/debian/koha-common.postinst index 46bc087d2b..173f700aba 100644 --- a/debian/koha-common.postinst +++ b/debian/koha-common.postinst @@ -182,7 +182,7 @@ log4perl.appender.SIP=Log::Log4perl::Appender::File log4perl.appender.SIP.filename=/var/log/koha/$site/sip.log log4perl.appender.SIP.mode=append log4perl.appender.SIP.layout=PatternLayout -log4perl.appender.SIP.layout.ConversionPattern=[%d] [%p] %m %l %n +log4perl.appender.SIP.layout.ConversionPattern=[%d] [%p] %X{accountid}@%X{peeraddr}: %m %l %n log4perl.appender.SIP.utf8=1 EOF diff --git a/debian/templates/log4perl-site.conf.in b/debian/templates/log4perl-site.conf.in index df61c9a9ec..e43797314c 100644 --- a/debian/templates/log4perl-site.conf.in +++ b/debian/templates/log4perl-site.conf.in @@ -35,5 +35,5 @@ log4perl.appender.SIP=Log::Log4perl::Appender::File log4perl.appender.SIP.filename=__LOG_DIR__/sip.log log4perl.appender.SIP.mode=append log4perl.appender.SIP.layout=PatternLayout -log4perl.appender.SIP.layout.ConversionPattern=[%d] [%p] %m %l %n +log4perl.appender.SIP.layout.ConversionPattern=[%d] [%p] %X{accountid}@%X{peeraddr}: %m %l %n log4perl.appender.SIP.utf8=1 diff --git a/etc/log4perl.conf b/etc/log4perl.conf index df61c9a9ec..e43797314c 100644 --- a/etc/log4perl.conf +++ b/etc/log4perl.conf @@ -35,5 +35,5 @@ log4perl.appender.SIP=Log::Log4perl::Appender::File log4perl.appender.SIP.filename=__LOG_DIR__/sip.log log4perl.appender.SIP.mode=append log4perl.appender.SIP.layout=PatternLayout -log4perl.appender.SIP.layout.ConversionPattern=[%d] [%p] %m %l %n +log4perl.appender.SIP.layout.ConversionPattern=[%d] [%p] %X{accountid}@%X{peeraddr}: %m %l %n log4perl.appender.SIP.utf8=1 -- 2.24.2 (Apple Git-127)