From: Darold Gilles Date: Mon, 13 Aug 2012 20:44:27 +0000 (+0200) Subject: Adding new option --exclude-file to exclude specific commands with regex stated in... X-Git-Tag: v3.2~175 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a2ef14fdf96b4f8545ae01e42f46c5c5705d8c03;p=pgbadger Adding new option --exclude-file to exclude specific commands with regex stated in a file. This is a rewrite of the opened pull request 21 by neoeahit (Vipul) --- diff --git a/README b/README index b855b5d..5f838c9 100644 --- a/README +++ b/README @@ -39,7 +39,7 @@ SYNOPSIS -t | --top number : number of query to store/display. Default: 20 -u | --dbuser username : only report what concern the given user -v | --verbose : enable verbose or debug mode. Disabled by default. - -w | -watch-mode : only report errors just like logwatch could do. + -w | --watch-mode : only report errors just like logwatch could do. -x | --extension : output format. Values: text or html. Default: html -z | --zcat exec_path : set the full path to the zcat program. Use it if zcat is not on your path or you want to use gzcat. @@ -47,6 +47,8 @@ SYNOPSIS --exclude-query regex : any query matching the given regex will be excluded from the report. For example: "^(VACUUM|COMMIT)" you can use this option multiple time. + --exclude_file filename: path of the file which contains all the regex to use + to exclude queries from the report. One regex per line. --disable-error : do not generate error report. --disable-hourly : do not generate hourly reports. --disable-type : do not generate query type report. diff --git a/doc/pgBadger.pod b/doc/pgBadger.pod index bb0aff5..05a79b2 100644 --- a/doc/pgBadger.pod +++ b/doc/pgBadger.pod @@ -42,7 +42,7 @@ Options: -t | --top number : number of query to store/display. Default: 20 -u | --dbuser username : only report what concern the given user -v | --verbose : enable verbose or debug mode. Disabled by default. - -w | -watch-mode : only report errors just like logwatch could do. + -w | --watch-mode : only report errors just like logwatch could do. -x | --extension : output format. Values: text or html. Default: html -z | --zcat exec_path : set the full path to the zcat program. Use it if zcat is not on your path or you want to use gzcat. @@ -50,6 +50,8 @@ Options: --exclude-query regex : any query matching the given regex will be excluded from the report. For example: "^(VACUUM|COMMIT)" you can use this option multiple time. + --exclude_file filename: path of the file which contains all the regex to use + to exclude queries from the report. One regex per line. --disable-error : do not generate error report. --disable-hourly : do not generate hourly reports. --disable-type : do not generate query type report. diff --git a/pgbadger b/pgbadger index e002f89..8cc5b5a 100755 --- a/pgbadger +++ b/pgbadger @@ -64,6 +64,7 @@ my $quiet = 0; my $progress = 0; my $error_only = 0; my @exclude_query = (); +my $exclude_file = ''; my $disable_error = 0; my $disable_hourly = 0; my $disable_type = 0; @@ -119,6 +120,7 @@ my $result = GetOptions( "w|watch-mode!" => \$error_only, "v|verbose!" => \$debug, "exclude-query=s" => \@exclude_query, + "exclude-file=s" => \$exclude_file, "disable-error!" => \$disable_error, "disable-hourly!" => \$disable_hourly, "disable-type!" => \$disable_type, @@ -229,6 +231,19 @@ if ($error_only && $disable_error) { $regex_prefix_dbname = 'db=([^,]*)' if (!$regex_prefix_dbname); $regex_prefix_dbuser = 'user=([^,]*)' if (!$regex_prefix_dbuser); +# Loading excluded query from file if any +if ($exclude_file) { + open(IN, "$exclude_file") or die "FATAL: can't read file $exclude_file: $!\n"; + my @exclq = ; + close(IN); + chomp(@exclq); + map { s/ //; } @exclq; + foreach my $r (@exclq) { + &check_regex($r, '--exclude-file'); + } + push(@exclude_query, @exclq); +} + # Testing regex syntaxe if ($#exclude_query >= 0) { foreach my $r (@exclude_query) { @@ -684,7 +699,7 @@ Options: -t | --top number : number of query to store/display. Default: 20 -u | --dbuser username : only report what concern the given user -v | --verbose : enable verbose or debug mode. Disabled by default. - -w | -watch-mode : only report errors just like logwatch could do. + -w | --watch-mode : only report errors just like logwatch could do. -x | --extension : output format. Values: text or html. Default: html -z | --zcat exec_path : set the full path to the zcat program. Use it if zcat is not on your path or you want to use gzcat. @@ -692,6 +707,8 @@ Options: --exclude-query regex : any query matching the given regex will be excluded from the report. For example: "^(VACUUM|COMMIT)" you can use this option multiple time. + --exclude_file filename: path of the file which contains all the regex to use + to exclude queries from the report. One regex per line. --disable-error : do not generate error report. --disable-hourly : do not generate hourly reports. --disable-type : do not generate query type report.