| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
#=============================================================================== |
|
2
|
|
|
|
|
|
|
# |
|
3
|
|
|
|
|
|
|
# FILE: EDR.pm |
|
4
|
|
|
|
|
|
|
# |
|
5
|
|
|
|
|
|
|
# DESCRIPTION: Module for reading/writing Event Details Records |
|
6
|
|
|
|
|
|
|
# |
|
7
|
|
|
|
|
|
|
# NOTES: --- |
|
8
|
|
|
|
|
|
|
# AUTHOR: Michael Bochkaryov (Rattler), |
|
9
|
|
|
|
|
|
|
# COMPANY: Net.Style |
|
10
|
|
|
|
|
|
|
# CREATED: 28.08.2009 16:43:02 EEST |
|
11
|
|
|
|
|
|
|
#=============================================================================== |
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=head1 NAME |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
NetSDS::EDR - read/write Event Details Records |
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
use NetSDS::EDR; |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
my $edr = NetSDS::EDR->new( |
|
22
|
|
|
|
|
|
|
filename => '/mnt/billing/call-stats.dat', |
|
23
|
|
|
|
|
|
|
); |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
... |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
$edr->write( |
|
28
|
|
|
|
|
|
|
{ |
|
29
|
|
|
|
|
|
|
callerid => '80441234567', |
|
30
|
|
|
|
|
|
|
clip => '89001234567', |
|
31
|
|
|
|
|
|
|
start_time => '2006-12-55 12:21:46', |
|
32
|
|
|
|
|
|
|
end_time => '2008-12-55 12:33:22' |
|
33
|
|
|
|
|
|
|
} |
|
34
|
|
|
|
|
|
|
); |
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
C module implements API for writing EDR (Event Details Record) files |
|
39
|
|
|
|
|
|
|
form applications. |
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
EDR itself is set of structured data describing details of some event. Exact |
|
42
|
|
|
|
|
|
|
structure depends on event type and so hasn't fixed structure. |
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
In NetSDS EDR data is written to plain text files as JSON structures one row per record. |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=cut |
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
package NetSDS::EDR; |
|
49
|
|
|
|
|
|
|
|
|
50
|
2
|
|
|
2
|
|
5853
|
use 5.8.0; |
|
|
2
|
|
|
|
|
8
|
|
|
|
2
|
|
|
|
|
84
|
|
|
51
|
2
|
|
|
2
|
|
10
|
use strict; |
|
|
2
|
|
|
|
|
5
|
|
|
|
2
|
|
|
|
|
56
|
|
|
52
|
2
|
|
|
2
|
|
9
|
use warnings; |
|
|
2
|
|
|
|
|
3
|
|
|
|
2
|
|
|
|
|
50
|
|
|
53
|
|
|
|
|
|
|
|
|
54
|
2
|
|
|
2
|
|
1162
|
use JSON; |
|
|
2
|
|
|
|
|
20318
|
|
|
|
2
|
|
|
|
|
16
|
|
|
55
|
2
|
|
|
2
|
|
1596
|
use NetSDS::Util::DateTime; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
use base 'NetSDS::Class::Abstract'; |
|
57
|
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
use version; our $VERSION = '1.301'; |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
#=============================================================================== |
|
61
|
|
|
|
|
|
|
# |
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=head1 CLASS API |
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=over |
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=item B - class constructor |
|
68
|
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
Parameters: |
|
70
|
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
* filename - EDR file name |
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
Example: |
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
my $edr = NetSDS::EDR->new( |
|
76
|
|
|
|
|
|
|
filename => '/mnt/stat/ivr.dat', |
|
77
|
|
|
|
|
|
|
); |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=cut |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
#----------------------------------------------------------------------- |
|
82
|
|
|
|
|
|
|
sub new { |
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
my ( $class, %params ) = @_; |
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
my $self = $class->SUPER::new(%params); |
|
87
|
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
# Create JSON encoder for EDR data processing |
|
89
|
|
|
|
|
|
|
$self->{encoder} = JSON->new(); |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
# Initialize file to write |
|
92
|
|
|
|
|
|
|
if ( $params{filename} ) { |
|
93
|
|
|
|
|
|
|
$self->{edr_file} = $params{filename}; |
|
94
|
|
|
|
|
|
|
} else { |
|
95
|
|
|
|
|
|
|
return $class->error("Absent mandatory parameter 'filename'"); |
|
96
|
|
|
|
|
|
|
} |
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
return $self; |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
} |
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
#*********************************************************************** |
|
103
|
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=item B - write EDR to file |
|
105
|
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
This methods converts records to JSON and write to file. |
|
107
|
|
|
|
|
|
|
Each record writing to one separate string. |
|
108
|
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
Example: |
|
110
|
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
$edr->write({from => '380441234567', to => '5552222', status => 'busy'}); |
|
112
|
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=cut |
|
114
|
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
#----------------------------------------------------------------------- |
|
116
|
|
|
|
|
|
|
sub write { |
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
my ( $self, @records ) = @_; |
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
open EDRF, ">>$self->{edr_file}"; |
|
121
|
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
# Write records - one record per line |
|
123
|
|
|
|
|
|
|
foreach my $rec (@records) { |
|
124
|
|
|
|
|
|
|
my $edr_json = $self->{encoder}->encode($rec); |
|
125
|
|
|
|
|
|
|
print EDRF "$edr_json\n"; |
|
126
|
|
|
|
|
|
|
} |
|
127
|
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
close EDRF; |
|
129
|
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
} |
|
131
|
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
1; |
|
133
|
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
__END__ |