From 6fc2479859f8c6b9bbc7241d20f37265fd7439c0 Mon Sep 17 00:00:00 2001 From: Alex Malek Date: Mon, 19 Oct 2020 10:42:48 -0400 Subject: [PATCH] take as an option database to save audit info to allows saving log info not connected to a valid datadase ie failed login with bad DB name consolidate all logging for a cluster --- bin/pgaudit_analyze | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/bin/pgaudit_analyze b/bin/pgaudit_analyze index e052d5b..69a3c1f 100755 --- a/bin/pgaudit_analyze +++ b/bin/pgaudit_analyze @@ -33,6 +33,7 @@ pgaudit_analyze [options] --socket-path socket directory used by PostgreSQL (default to system default directory) --log-file location of the log file for pgaudit_analyze (defaults to /var/log/pgaudit_analyze.log) --user specify postgres user instead of using pgaudit_analyze invoker + --database specify database name to save audit info to (default is database from log) General Options: --help display usage and exit @@ -121,6 +122,7 @@ my $iPort = 5432; my $strSocketPath; my $strLogOutFile = '/var/log/pgaudit_analyze.log'; my $strDbUser = getpwuid($<); +my $strDbOverride; GetOptions ('help' => \$bHelp, @@ -128,7 +130,8 @@ GetOptions ('help' => \$bHelp, 'port=s' => \$iPort, 'socket-path=s' => \$strSocketPath, 'log-file=s' => \$strLogOutFile, - 'user=s' => \$strDbUser) + 'user=s' => \$strDbUser, + 'database=s' => \$strDbOverride) or pod2usage(2); # Display version and exit if requested @@ -688,7 +691,7 @@ while(!$bDone) my $strSessionId = $$stryRow[LOG_FIELD_SESSION_ID]; my $lSessionLineNum = $$stryRow[LOG_FIELD_SESSION_LINE_NUM]; my $strUserName = $$stryRow[LOG_FIELD_USER_NAME]; - my $strDatabaseName = $$stryRow[LOG_FIELD_DATABASE_NAME]; + my $strDatabaseName = $strDbOverride || $$stryRow[LOG_FIELD_DATABASE_NAME]; if (defined($strUserName) && $strAuditUserName ne $strUserName && defined($strDatabaseName) && databaseGet($strDatabaseName) &&