blib/lib/Net/Frame/Layer/Syslog.pm

filter: Statementstmt 93.5% 203 / 217 Branchbran 56.5% 26 / 46 Conditioncond 54.5% 6 / 11 MC/DCmcdc 16.6% 1 / 6 Subroutinesub 97.9% 48 / 49 Podpod 100% 9 / 9 totaltotal 86.6% 293 / 338 CC 30 SCAR 12.9
CC
30
Cov
86%
unpack
11.4
print
6.1
getLength
6.0
CRAP 3.6
↑ Summary
1 #
2 # $Id: Syslog.pm 49 2012-11-19 13:15:34Z VinsWorldcom $
3 #
4 package Net::Frame::Layer::Syslog;
5 7 ▶use strict; use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 7 our $VERSION = '1.05';
8  
9 7 ▶use Net::Frame::Layer qw(:consts :subs);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 7 ▶use Exporter;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 7 our @ISA = qw(Net::Frame::Layer Exporter);
12  
13 7 our %EXPORT_TAGS = (
14 consts => [qw(
15 NF_SYSLOG_FACILITY_KERNEL
16 NF_SYSLOG_FACILITY_USER
17 NF_SYSLOG_FACILITY_MAIL
18 NF_SYSLOG_FACILITY_SYSTEM
19 NF_SYSLOG_FACILITY_SECURITY
20 NF_SYSLOG_FACILITY_INTERNAL
21 NF_SYSLOG_FACILITY_PRINTER
22 NF_SYSLOG_FACILITY_NEWS
23 NF_SYSLOG_FACILITY_UUCP
24 NF_SYSLOG_FACILITY_CLOCK
25 NF_SYSLOG_FACILITY_SECURITY2
26 NF_SYSLOG_FACILITY_FTP
27 NF_SYSLOG_FACILITY_NTP
28 NF_SYSLOG_FACILITY_AUDIT
29 NF_SYSLOG_FACILITY_ALERT
30 NF_SYSLOG_FACILITY_CLOCK2
31 NF_SYSLOG_FACILITY_LOCAL0
32 NF_SYSLOG_FACILITY_LOCAL1
33 NF_SYSLOG_FACILITY_LOCAL2
34 NF_SYSLOG_FACILITY_LOCAL3
35 NF_SYSLOG_FACILITY_LOCAL4
36 NF_SYSLOG_FACILITY_LOCAL5
37 NF_SYSLOG_FACILITY_LOCAL6
38 NF_SYSLOG_FACILITY_LOCAL7
39 NF_SYSLOG_SEVERITY_EMERGENCY
40 NF_SYSLOG_SEVERITY_ALERT
41 NF_SYSLOG_SEVERITY_CRITICAL
42 NF_SYSLOG_SEVERITY_ERROR
43 NF_SYSLOG_SEVERITY_WARNING
44 NF_SYSLOG_SEVERITY_NOTICE
45 NF_SYSLOG_SEVERITY_INFORMATIONAL
46 NF_SYSLOG_SEVERITY_DEBUG
47 )],
48 subs => [qw(
49 priorityAton
50 priorityNtoa
51 )],
52 );
53 our @EXPORT_OK = (
54 7 @{$EXPORT_TAGS{consts}},
55 7 @{$EXPORT_TAGS{subs}},
56 );
57  
58 7 ▶use constant NF_SYSLOG_FACILITY_KERNEL => 0;
Subroutine BEGIN: called CC=1 SCAR=0.0
59 7 ▶use constant NF_SYSLOG_FACILITY_USER => 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
60 7 ▶use constant NF_SYSLOG_FACILITY_MAIL => 2;
Subroutine BEGIN: called CC=1 SCAR=0.0
61 7 ▶use constant NF_SYSLOG_FACILITY_SYSTEM => 3;
Subroutine BEGIN: called CC=1 SCAR=0.0
62 7 ▶use constant NF_SYSLOG_FACILITY_SECURITY => 4;
Subroutine BEGIN: called CC=1 SCAR=0.0
63 7 ▶use constant NF_SYSLOG_FACILITY_INTERNAL => 5;
Subroutine BEGIN: called CC=1 SCAR=0.0
64 7 ▶use constant NF_SYSLOG_FACILITY_PRINTER => 6;
Subroutine BEGIN: called CC=1 SCAR=0.0
65 7 ▶use constant NF_SYSLOG_FACILITY_NEWS => 7;
Subroutine BEGIN: called CC=1 SCAR=0.0
66 7 ▶use constant NF_SYSLOG_FACILITY_UUCP => 8;
Subroutine BEGIN: called CC=1 SCAR=0.0
67 7 ▶use constant NF_SYSLOG_FACILITY_CLOCK => 9;
Subroutine BEGIN: called CC=1 SCAR=0.0
68 7 ▶use constant NF_SYSLOG_FACILITY_SECURITY2 => 10;
Subroutine BEGIN: called CC=1 SCAR=0.0
69 7 ▶use constant NF_SYSLOG_FACILITY_FTP => 11;
Subroutine BEGIN: called CC=1 SCAR=0.0
70 7 ▶use constant NF_SYSLOG_FACILITY_NTP => 12;
Subroutine BEGIN: called CC=1 SCAR=0.0
71 7 ▶use constant NF_SYSLOG_FACILITY_AUDIT => 13;
Subroutine BEGIN: called CC=1 SCAR=0.0
72 7 ▶use constant NF_SYSLOG_FACILITY_ALERT => 14;
Subroutine BEGIN: called CC=1 SCAR=0.0
73 7 ▶use constant NF_SYSLOG_FACILITY_CLOCK2 => 15;
Subroutine BEGIN: called CC=1 SCAR=0.0
74 7 ▶use constant NF_SYSLOG_FACILITY_LOCAL0 => 16;
Subroutine BEGIN: called CC=1 SCAR=0.0
75 7 ▶use constant NF_SYSLOG_FACILITY_LOCAL1 => 17;
Subroutine BEGIN: called CC=1 SCAR=0.0
76 7 ▶use constant NF_SYSLOG_FACILITY_LOCAL2 => 18;
Subroutine BEGIN: called CC=1 SCAR=0.0
77 7 ▶use constant NF_SYSLOG_FACILITY_LOCAL3 => 19;
Subroutine BEGIN: called CC=1 SCAR=0.0
78 7 ▶use constant NF_SYSLOG_FACILITY_LOCAL4 => 20;
Subroutine BEGIN: called CC=1 SCAR=0.0
79 7 ▶use constant NF_SYSLOG_FACILITY_LOCAL5 => 21;
Subroutine BEGIN: called CC=1 SCAR=0.0
80 7 ▶use constant NF_SYSLOG_FACILITY_LOCAL6 => 22;
Subroutine BEGIN: called CC=1 SCAR=0.0
81 7 ▶use constant NF_SYSLOG_FACILITY_LOCAL7 => 23;
Subroutine BEGIN: called CC=1 SCAR=0.0
82 7 ▶use constant NF_SYSLOG_SEVERITY_EMERGENCY => 0;
Subroutine BEGIN: called CC=1 SCAR=0.0
83 7 ▶use constant NF_SYSLOG_SEVERITY_ALERT => 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
84 7 ▶use constant NF_SYSLOG_SEVERITY_CRITICAL => 2;
Subroutine BEGIN: called CC=1 SCAR=0.0
85 7 ▶use constant NF_SYSLOG_SEVERITY_ERROR => 3;
Subroutine BEGIN: called CC=1 SCAR=0.0
86 7 ▶use constant NF_SYSLOG_SEVERITY_WARNING => 4;
Subroutine BEGIN: called CC=1 SCAR=0.0
87 7 ▶use constant NF_SYSLOG_SEVERITY_NOTICE => 5;
Subroutine BEGIN: called CC=1 SCAR=0.0
88 7 ▶use constant NF_SYSLOG_SEVERITY_INFORMATIONAL => 6;
Subroutine BEGIN: called CC=1 SCAR=0.0
89 7 ▶use constant NF_SYSLOG_SEVERITY_DEBUG => 7;
Subroutine BEGIN: called CC=1 SCAR=0.0
90  
91 7 our @FACILITY = qw(kernel user mail system security internal printer news uucp clock security2 FTP NTP audit alert clock2 local0 local1 local2 local3 local4 local5 local6 local7);
92 7 our @SEVERITY = qw(Emergency Alert Critical Error Warning Notice Informational Debug);
93  
94 7 our @AS = qw(
95 facility
96 severity
97 timestamp
98 host
99 tag
100 content
101 msg
102 );
103 7 __PACKAGE__->cgBuildIndices;
104 7 __PACKAGE__->cgBuildAccessorsScalar(\@AS);
105  
106 #no strict 'vars';
107  
108 7 ▶use Sys::Hostname;
Subroutine BEGIN: called CC=1 SCAR=0.0
109  
110 7 $Net::Frame::Layer::UDP::Next->{514} = "Syslog";
111  
112 3 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
113 3 my $time = _getTime();
114 3 my $host = _getHost();
115 3 my $tag = _getTag();
116  
117 shift->SUPER::new(
118 3 facility => NF_SYSLOG_FACILITY_LOCAL7,
119 severity => NF_SYSLOG_SEVERITY_INFORMATIONAL,
120 timestamp => $time,
121 host => $host,
122 tag => $tag,
123 content => 'syslog message',
124 @_,
125 );
126 }
127  
128 1 ▶sub message {
Subroutine message: called CC=1 SCAR=0.0
Pod documented
129 1 my $time = _getTime();
130 1 my $host = _getHost();
131 1 my $tag = _getTag();
132  
133 shift->SUPER::new(
134 1 msg => "<190>$time $host $tag syslog message",
135 @_,
136 );
137 }
138  
139 0 ▶sub getLength {
Subroutine getLength: not called CC=2 SCAR=17.9
Pod documented
140 0 my $self = shift;
141  
142 0 ▶ if (defined($self->msg)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->msg) { } 0 0 0
143 0 return length($self->msg)
144 } else {
145  
146 0 my $priority = priorityAton($self->facility, $self->severity);
147 0 my $len =
148 length($priority) +
149 length($self->timestamp) +
150 length($self->host) +
151 length($self->tag) +
152 length($self->content) +
153 5;
154  
155 0 return $len
156 }
157 }
158  
159 3 ▶sub pack {
Subroutine pack: called CC=4 SCAR=14.0
Pod documented
160 3 my $self = shift;
161  
162 3 my $raw;
163 3 ▶ if (defined($self->msg)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->msg) { } 1 2 3
164 1 ▶ $raw = $self->SUPER::pack('a*',
Branch: 1 branch
BranchTrueFalseTotal
$raw = $self->SUPER::pack("a*", $self->msg) or return 1 0 1
165 $self->msg
166 ) or return;
167 } else {
168 2 my $priority = priorityAton($self->facility, $self->severity);
169  
170 2 ▶ $raw = $self->SUPER::pack('a*',
Branch: 1 branch
BranchTrueFalseTotal
$raw = $self->SUPER::pack("a*", '<' . $priority . '>' . $self->timestamp . ' ' . $self->host . ' ' . $self->tag . ' ' . $self->content) or return 2 0 2
171 "<" .
172 $priority .
173 ">" .
174 $self->timestamp .
175 " " .
176 $self->host .
177 " " .
178 $self->tag .
179 " " .
180 $self->content
181 ) or return;
182 }
183  
184 3 return $self->raw($raw);
185 }
186  
187 1 ▶sub unpack {
Subroutine unpack: called CC=10 SCAR=24.3
Pod documented
188 1 my $self = shift;
189  
190 1 ▶ my ($payload) =
Branch: 1 branch
BranchTrueFalseTotal
my($payload) = $self->SUPER::unpack("a*", $self->raw) or return 1 0 1
191 $self->SUPER::unpack('a*', $self->raw)
192 or return;
193  
194 1 my $regex = '<(\d{1,3})>[\d{1,}: \*]*((?:[JFMASONDjfmasond]\w\w) {1,2}(?:\d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[0-9A-Fa-f]{1,4}){1,4})|(?:(?::[0-9A-Fa-f]{1,4}){0,2}:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(?:(?:[0-9A-Fa-f]{1,4}:){2}(?:(?:(?::[0-9A-Fa-f]{1,4}){1,5})|(?:(?::[0-9A-Fa-f]{1,4}){0,3}:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(?:(?:[0-9A-Fa-f]{1,4}:){1}(?:(?:(?::[0-9A-Fa-f]{1,4}){1,6})|(?:(?::[0-9A-Fa-f]{1,4}){0,4}:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(?::(?:(?:(?::[0-9A-Fa-f]{1,4}){1,7})|(?:(?::[0-9A-Fa-f]{1,4}){0,5}:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))(?:%.+)?) )?(.*)';
196 1 my $Cregex = qr/$regex/;
197  
198 1 ▶ if ($payload =~ /$Cregex/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($payload =~ /$Cregex/) { } 1 0 1
199  
200 1 my $priority = $1;
201 1 ▶ my $timestamp = $2 || '0';
Condition50%1/2
$2 || '0'
l!l
10
MC/DC0%0/1
$2 || '0'
$2
Truth table50%1/2
A
A= $2
Aresult
11
00
202 1 ▶ my $hostname = $3 || '0';
Condition50%1/2
$3 || '0'
l!l
10
MC/DC0%0/1
$3 || '0'
$3
Truth table50%1/2
A
A= $3
Aresult
11
00
203 1 my $message = $4;
204 1 my ($facility, $severity) = priorityNtoa($priority);
205  
206 1 $self->facility($facility);
207 1 $self->severity($severity);
208 1 $self->timestamp($timestamp);
209  
210 1 $hostname =~ s/\s+//;
211 1 $self->host($hostname);
212  
213 1 my %chars;
214 1 $chars{bracket} = index($message,"]");
215 1 $chars{colon} = index($message,":");
216 1 $chars{space} = index($message," ");
217 1 my $win = 0;
218 1 foreach my $ch (sort {$chars{$b} cmp $chars{$a}} keys %chars) {
219 3 ▶ if ($chars{$ch} > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($chars{$ch} > 0) 2 1 3
220 2 $win = $ch
221 }
222 }
223 1 ▶ if ($chars{$win} > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($chars{$win} > 0) { } 1 0 1
224 1 ▶ my $tag = substr($message, 0, $chars{$win}+1) || '0';
Condition50%1/2
substr($message, 0, $chars{$win} + 1) || '0'
l!l
10
MC/DC0%0/1
substr($message, 0, $chars{$win} + 1) || '0'
substr($message, 0, $chars{$win} + 1)
Truth table50%1/2
A
A= substr($message, 0, $chars{$win} + 1)
Aresult
11
00
225 1 ▶ my $content = substr($message, $chars{$win}+1) || '0';
Condition50%1/2
substr($message, $chars{$win} + 1) || '0'
l!l
10
MC/DC0%0/1
substr($message, $chars{$win} + 1) || '0'
substr($message, $chars{$win} + 1)
Truth table50%1/2
A
A= substr($message, $chars{$win} + 1)
Aresult
11
00
226 1 $self->tag($tag);
227 1 $self->content($content)
228 } else {
229 0 $self->tag('0');
230 0 $self->content($message)
231 }
232  
233 1 my $msg = substr $payload, index($payload,">")+1;
234 1 $self->msg($msg)
235  
236 } else {
237 0 $self->facility(undef);
238 0 $self->severity(undef);
239 0 $self->content(undef);
240 0 $self->msg($payload)
241 }
242  
243 1 return $self;
244 }
245  
246 1 ▶sub encapsulate {
Subroutine encapsulate: called CC=3 SCAR=12.0
Pod documented
247 1 my $self = shift;
248  
249 1 ▶ return $self->nextLayer if $self->nextLayer;
Branch: 1 branch
BranchTrueFalseTotal
if $self->nextLayer 0 1 1
250  
251 # Needed?
252 1 ▶ if ($self->payload) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->payload) 0 1 1
253 0 return 'Syslog';
254 }
255  
256 1 NF_LAYER_NONE;
257 }
258  
259 3 ▶sub print {
Subroutine print: called CC=6 SCAR=18.1
Pod documented
260 3 my $self = shift;
261  
262 3 my $l = $self->layer;
263 3 my $buf;
264  
265 3 ▶ if (defined($self->facility) && defined($self->severity)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->facility and defined $self->severity) 2 1 3
Condition66%2/3
defined $self->facility and defined $self->severity
!ll&&!rl&&r
102
MC/DC50%1/2
defined $self->facility and defined $self->severity
defined $self->facility defined $self->severity
Truth table66%2/3
A and B
A= defined $self->facilityB= defined $self->severity
ABresult
0X0
100
111
266 2 ▶ $buf = sprintf
Branch: 2 branches
BranchTrueFalseTotal
defined $Net::Frame::Layer::Syslog::FACILITY[$self->facility] ? : 2 0 2
defined $Net::Frame::Layer::Syslog::SEVERITY[$self->severity] ? : 2 0 2
267 "$l: facility:%d %s severity:%d %s\n",
268 $self->facility,
269 (defined $FACILITY[$self->facility]) ? "($FACILITY[$self->facility])" : '',
270 $self->severity,
271 (defined $SEVERITY[$self->severity]) ? "($SEVERITY[$self->severity])" : '';
272 }
273  
274 3 ▶ if (not defined($self->content)) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $self->content) { } 1 2 3
275 1 $buf .= sprintf
276 "$l: message:%s",
277 $self->msg;
278 } else {
279 2 $buf .= sprintf
280 "$l: timestamp:%s host:%s\n".
281 "$l: tag:%s\n".
282 "$l: content:%s",
283 $self->timestamp, $self->host,
284 $self->tag,
285 $self->content;
286 }
287  
288 3 return $buf;
289 }
290  
291 ####
292  
293 3 ▶sub priorityAton {
Subroutine priorityAton: called CC=2 SCAR=7.1
Pod documented
294 3 my ($fac, $sev) = @_;
295  
296 3 ▶ return undef if not defined $sev;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $sev 0 3 3
297 3 return (($fac << 3) | $sev)
298 }
299  
300 3 ▶sub priorityNtoa {
Subroutine priorityNtoa: called CC=3 SCAR=11.0
Pod documented
301 3 my ($pri, $flag) = @_;
302  
303 3 ▶ return undef if not defined $pri;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $pri 0 3 3
304 3 my $sev = $pri % 8;
305 3 my $fac = ($pri - $sev) / 8;
306  
307 3 ▶ if (defined($flag)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $flag) { } 1 2 3
308 1 return ($FACILITY[$fac], $SEVERITY[$sev])
309 } else {
310 2 return ($fac, $sev)
311 }
312 }
313  
314 4 ▶sub _getTime {
Subroutine _getTime: called CC=5 SCAR=17.8
315 4 my @month = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);
316 4 my @time = localtime();
317 4 ▶ my $ts =
Branch: 4 branches
BranchTrueFalseTotal
$time[3] < 10 ? : 0 4 4
$time[2] < 10 ? : 4 0 4
$time[1] < 10 ? : 0 4 4
$time[0] < 10 ? : 0 4 4
318 $month[ $time[4] ] . " "
319 . ( ( $time[3] < 10 ) ? ( " " . $time[3] ) : $time[3] ) . " "
320 . ( ( $time[2] < 10 ) ? ( "0" . $time[2] ) : $time[2] ) . ":"
321 . ( ( $time[1] < 10 ) ? ( "0" . $time[1] ) : $time[1] ) . ":"
322 . ( ( $time[0] < 10 ) ? ( "0" . $time[0] ) : $time[0] );
323  
324 4 return $ts
325 }
326  
327 4 ▶sub _getHost {
Subroutine _getHost: called CC=1 SCAR=0.0
328 4 return Sys::Hostname::hostname;
329 }
330  
331 4 ▶sub _getTag {
Subroutine _getTag: called CC=3 SCAR=13.3
332 4 my $name = $0;
333 4 ▶ if ($name =~ /.+\/(.+)/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($name =~ m[.+/(.+)]) { } 4 0 4
elsif ($name =~ /.+\\(.+)/) { } 0 0 0
334 4 $name = $1;
335 } elsif ($name =~ /.+\\(.+)/) {
336 0 $name = $1;
337 }
338  
339 4 return $name . "[" . $$ . "]"
340 }
341  
342 7 1;
343  
344 __END__
↑ Summary