-
Notifications
You must be signed in to change notification settings - Fork 3
/
topfilters
executable file
·126 lines (91 loc) · 2.34 KB
/
topfilters
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#!/usr/bin/perl -w
# Find the most popular search filters
use strict;
use warnings;
$::VERSION = 0.2;
sub version()
{
print STDERR "$0 version $::VERSION\n";
exit 0;
}
sub usage()
{
print STDERR "Usage: $0\n";
exit 1;
}
my %opt = (
'h' => 0, # Help
'v' => 0, # Version
);
while (@ARGV) {
my $arg = shift @ARGV;
if ($arg =~ m{^-h$|^--help$}) {
$opt{h} = 1;
} elsif ($arg =~ m{^-v$|^--version$}) {
$opt{v} = 1;
} else {
push @ARGV, $arg;
last;
}
}
version if $opt{v};
usage if $opt{h};
my %filter;
while (<>) {
chomp;
if (my ($scope,$filter) = m{SEARCH REQ.* scope=(\S+) filter="([^\"]+)"}) {
next if $scope =~ m{baseObject};
$filter = lc($filter);
$filter =~ s{\(([a-z0-9_-]+)=[^\*\)]+\*?\)}{($1=EQUALITY)}gi;
$filter =~ s{\(([a-z0-9_-]+)>=[^\*\)]+\)}{($1=ORDERING)}gi;
$filter =~ s{\(([a-z0-9_-]+)<=[^\*\)]+\)}{($1=ORDERING)}gi;
$filter =~ s{\(([a-z0-9_-]+)=\*\)}{($1=PRESENCE)}gi;
$filter =~ s{\(([a-z0-9_-]+)=[^\*]*\*[^\)]*\)}{($1=SUBSTRING)}gi;
$filter{$filter}++;
}
}
format STDOUT_TOP =
frequency filter
.
format =
@>>>>>>>>> ^*
$::freq, $::filt
.
foreach our $filt (sort { $filter{$b} <=> $filter{$a} } keys(%filter)) {
our $freq = $filter{$filt};
write;
}
1;
__END__
=head1 NAME
topfilters - analyze search filters in OpenDJ logs
=head1 SYNOPSIS
topfilters
topfilters -h
topfilters -v
=head1 DESCRIPTION
OpenDJ access log files include the filters used for all search operations.
Filters for baseObject searches are not indexable, but all others are.
This tool outputs a list of filter types, ordered by frequency. Note this does
not mean that the server requires an index for every term, so the output is only
a guide to what might need indexing.
=head1 OPTIONS
=over
=item B<-h> display help text.
=item B<-v> report the tool version.
=back
=head1 EXAMPLE
$ topfilters < access
frequency filter
3002 (objectclass=EQUALITY)
430 (objectclass=PRESENCE)
25 (ds-task-id=EQUALITY)
7 (telephonenumber=EQUALITY)
1 (&(cn=PRESENCE)(telephonenumber=EQUALITY))
=head1 SEE ALSO
L<http://opendj.forgerock.org>
=head1 AUTHOR
Chris Ridd E<lt>[email protected]<gt>
=head1 COPYRIGHT
Copyright (c) 2013-2022 Chris Ridd. All rights reserved. This tool is free software;
you can redistribute it and/or modify it under the same terms as Perl itself.