Saftpresse/Plugin/GraphitLineFormat.pm

filter: Statementstmt 35.0% 7 / 20 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 12 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 50.0% 1 / 2 Podpod 100% 1 / 1 totaltotal 17.6% 9 / 51 SCAR 40.0
CC
9
Cov
18%
process
90.0
BEGIN
1.0
CRAP 54.5
« Saftpresse/Plugin/Role/Tracking.pm ↑ Summary Saftpresse/Plugin/Postfix/Recieved.pm »
1 package Log::Saftpresse::Plugin::GraphitLineFormat;
2  
3 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 # ABSTRACT: read metric values from logs and export them as counters
6 1 our $VERSION = '1.5'; # VERSION
7  
8 1 extends 'Log::Saftpresse::Plugin';
9  
10 1 with 'Log::Saftpresse::Plugin::Role::CounterUtils';
11  
12  
13 sub process {
14 0 ▶ my ( $self, $event ) = @_;
Subroutine process: not called CC=9 SCAR=45.0
Pod documented
15 0 my $program = $event->{'program'};
16 0 ▶ if( ! defined $program || $program ne 'metric' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $program or $program ne "metric") 0 0 0
Condition0%0/3
not defined $program or $program ne "metric"
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $program or $program ne "metric"
not defined $program $program ne "metric"
Truth table0%0/3
not(A) or B
A= not defined $programB= $program ne "metric"
ABresult
1X1
011
000
17 0 return;
18 }
19  
20 0 my ( $path, $value, $ts ) = split(/\s+/, $event->{'message'});
21  
22 0 ▶ if( ! defined $path || $path !~ /^[a-zA-Z0-9\-_\.]+$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $path and $path =~ /^[a-zA-Z0-9\-_\.]+$/) 0 0 0
Condition0%0/3
defined $path and $path =~ /^[a-zA-Z0-9\-_\.]+$/
!ll&&!rl&&r
000
MC/DC0%0/2
defined $path and $path =~ /^[a-zA-Z0-9\-_\.]+$/
defined $path $path =~ /^[a-zA-Z0-9\-_\.]+$/
Truth table0%0/3
A and B
A= defined $pathB= $path =~ /^[a-zA-Z0-9\-_\.]+$/
ABresult
0X0
100
111
23 0 return;
24 }
25 0 ▶ if( ! defined $value || $value !~ /^[+\-]?[0-9,\.]+$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $value and $value =~ /^[+\-]?[0-9,\.]+$/) 0 0 0
Condition0%0/3
defined $value and $value =~ /^[+\-]?[0-9,\.]+$/
!ll&&!rl&&r
000
MC/DC0%0/2
defined $value and $value =~ /^[+\-]?[0-9,\.]+$/
defined $value $value =~ /^[+\-]?[0-9,\.]+$/
Truth table0%0/3
A and B
A= defined $valueB= $value =~ /^[+\-]?[0-9,\.]+$/
ABresult
0X0
100
111
26 0 return;
27 }
28 0 ▶ if( ! defined $ts || $ts !~ /^\d+$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $ts and $ts =~ /^\d+$/) 0 0 0
Condition0%0/3
defined $ts and $ts =~ /^\d+$/
!ll&&!rl&&r
000
MC/DC0%0/2
defined $ts and $ts =~ /^\d+$/
defined $ts $ts =~ /^\d+$/
Truth table0%0/3
A and B
A= defined $tsB= $ts =~ /^\d+$/
ABresult
0X0
100
111
29 0 return;
30 }
31  
32 0 @$event{'type', 'path', 'value', 'timestamp'} =
33 ( 'metric', $path, $value, $ts );
34  
35 0 return;
36 }
37  
38 1 1;
39  
40 __END__
41  
42 =pod
43  
44 =encoding UTF-8
45  
46 =head1 NAME
47  
48 Log::Saftpresse::Plugin::GraphitLineFormat - read metric values from logs and export them as counters
49  
50 =head1 VERSION
51  
52 version 1.5
53  
54 =head1 Description
55  
56 This plugin parses the graphit line format.
57  
58 =head1 Synopsis
59  
60 <Plugin graphit>
61 module = "GraphitLineFormat"
62 </Plugin>
63  
64 =head1 Input Format
65  
66 The plugin expects a events with
67  
68 'program' => 'metric'
69  
70 and a 'message' field in graphit plaintext format:
71  
72 'message' => '<metric path> <metric value> <metric timestamp>'
73  
74 =head1 Output
75  
76 This plugin will add the following fields:
77  
78 =over
79  
80 =item type
81  
82 The value: 'metric'.
83  
84 =item path
85  
86 The metric path.
87  
88 =item value
89  
90 The metric value.
91  
92 =item timestamp
93  
94 The metric timestamp.
95  
96 =back
97  
98 =head1 AUTHOR
99  
100 Markus Benning <ich@markusbenning.de>
101  
102 =head1 COPYRIGHT AND LICENSE
103  
104 This software is Copyright (c) 1998 by James S. Seymour, 2015 by Markus Benning.
105  
106 This is free software, licensed under:
107  
108 The GNU General Public License, Version 2, June 1991
109  
110 =cut
« Saftpresse/Plugin/Role/Tracking.pm ↑ Summary Saftpresse/Plugin/Postfix/Recieved.pm »