lib/eris/role/context.pm

filter: Statementstmt 83.3% 15 / 18 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 60.0% 3 / 5 Podpod n/a totaltotal 78.2% 18 / 23 CC 1 SCAR 3.4
CC
1
Cov
83%
_build_field
2.0
_build_matcher
2.0
BEGIN
1.0
CRAP 1.4
« lib/eris/dictionary/eris/debug.pm ↑ Summary lib/eris/schema/syslog.pm »
1 package eris::role::context;
2 # ABSTRACT: Role for implementing a log context
3  
4 13 ▶use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 13 ▶use Types::Standard qw(Str Defined Int);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 13 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 13 our $VERSION = '0.008'; # VERSION
9  
10  
11 13 requires qw(
12 contextualize_message
13 sample_messages
14 );
15 13 with qw(
16 eris::role::plugin
17 );
18  
19 ########################################################################
20  
21  
22 13 has 'field' => (
23 is => 'ro',
24 isa => Str,
25 lazy => 1,
26 builder => '_build_field',
27 );
28  
29 0 ▶sub _build_field { 'program' }
Subroutine _build_field: not called CC=1 SCAR=6.9
30  
31  
32 13 has 'matcher' => (
33 is => 'ro',
34 isa => Defined,
35 lazy => 1,
36 builder => '_build_matcher',
37 );
38  
39 0 ▶sub _build_matcher { my ($self) = shift; $self->name; }
Subroutine _build_matcher: not called CC=1 SCAR=6.9
40  
41  
42 13 1;
43  
44 __END__
45  
46 =pod
47  
48 =encoding UTF-8
49  
50 =head1 NAME
51  
52 eris::role::context - Role for implementing a log context
53  
54 =head1 VERSION
55  
56 version 0.008
57  
58 =head1 ATTRIBUTES
59  
60 =head2 B<field>
61  
62 The field in the context of the log to use to use with the C<matcher> to select
63 a log for parsing. This defaults to the 'program' field and uses the
64 C<context> object's C<name> method as a default equality check.
65  
66 This means C<eris::log::context::sshd> will match any log with the 'program'
67 key set to 'sshd'.
68  
69 The rules for parsing are:
70  
71 =over 2
72  
73 =item B<*>
74  
75 Reserved for it's use as with C<matcher> set to '*', which forces the context
76 to be evaluated for every document.
77  
78 sub _build_field { '*' }
79 sub _build_matcher { '*' }
80  
81 Will run the contextualizer for every document.
82  
83 =item B<_exists_>
84  
85 Instead of apply the C<matcher> to the value, we'll check it against the key.
86  
87 Say we wanted to run a reverse DNS check on an IP we could:
88  
89 sub _build_field { '_exists_' }
90 sub _build_matcher { /_ip$/ }
91  
92 Exists supports the following matchers:
93  
94 =over 2
95  
96 =item B<String>
97  
98 Simple string match against the key
99  
100 =item B<Regex>
101  
102 Apply the regex to the key
103  
104 =item B<ArrayRef>
105  
106 Checks if the key is contained in the array
107  
108 =back
109  
110 =item B<String>
111  
112 The string is considered the name of the field in the document. That key is
113 used to check it's value against the C<matcher>. Using a string are a field name supports
114 the following C<matcher>'s.
115  
116 =over 2
117  
118 =item B<String>
119  
120 Check if the lowercase string matches the value at the key designated by B<field>, i.e.
121  
122 sub _build_field { 'program' }
123 sub _build_matcher { 'sshd' }
124  
125 This context will call C<contextualize_message> on documents with a field
126 'program' which has the value 'sshd'.
127  
128 =item B<Regex>
129  
130 Checks the value in the field for against the regex.
131  
132 sub _build_field { 'program' }
133 sub _build_matcher { /^postfix/ }
134  
135 This context will call C<contextualize_message> on documents with a field
136 'program' matching the regex '^postfix'.
137  
138 =item B<ArrayRef>
139  
140 Checks the value in the field against all values in the array.
141  
142 sub _build_field { 'program' }
143 sub _build_matcher { [qw(sort suricata)] }
144  
145 This context will call C<contextualize_message> on documents with a field
146 'program' that is either 'snort' or 'suricata'.
147  
148 =item B<CodeRef>
149  
150 Check the return value of the code reference passing the value at the field
151 into the function.
152  
153 sub _build_field { 'src_ip' }
154 sub _build_matcher { \&check_bad_ips }
155  
156 This context will call C<contextualize_message> on documents with a field
157 'src_ip' and call the C<check_bad_ips()> function with the value in the
158 'src_ip' field if the sub routine return true.
159  
160 =back
161  
162 =back
163  
164 =head2 B<matcher>
165  
166 Maybe a B<String>, B<Regex>, B<ArrayRef>, or a B<CodeRef>. See documentation on
167 L<field> for information on the combinations and how to use them.
168  
169 =head1 INTERFACE
170  
171 =head2 contextualize_message
172  
173 This method will be called every time a log matches this context. It receives
174 an C<eris::log> object. Call C<eris::log->add_context> with the name of the
175 context to add to the log context.
176  
177 =head2 sample_message
178  
179 This is used in sampling and the test suite.
180  
181 Return an array of log message you expect to use.
182  
183 This is helpful when developing or testing new elements, call:
184  
185 eris-context.pl --sample <name_of_context>
186  
187 To use those messages to see what the contextualizer is doing.
188  
189 =head1 SEE ALSO
190  
191 L<eris::log::contexts>, L<eris::log::contextualizer>, L<eris::role::plugin>,
192 L<eris::log::context::sshd>, L<eris::log::context::snort>
193  
194 =head1 AUTHOR
195  
196 Brad Lhotsky <brad@divisionbyzero.net>
197  
198 =head1 COPYRIGHT AND LICENSE
199  
200 This software is Copyright (c) 2015 by Brad Lhotsky.
201  
202 This is free software, licensed under:
203  
204 The (three-clause) BSD License
205  
206 =cut
« lib/eris/dictionary/eris/debug.pm ↑ Summary lib/eris/schema/syslog.pm »