3 # */5 * * * /home/ivan/freeside/bin/cdr-netsapiens.import ivan exportnum
8 use FS::UID qw(adminsuidsetup);
9 use FS::Record qw(qsearchs);
15 my $user = shift or die &usage;
18 my $exportnum = shift or die &usage;
19 my $part_export = qsearchs('part_export', { 'exportnum' => $exportnum } )
20 or die "unknown exportnum $exportnum\n";
22 #find max time_release
25 my $time_release = '2009-01-01 00:00:00';
27 #retreive CDRs >= this time
28 #XXX (in pages, this tops out at 20) _start=>0, _limit=>20
30 my $ns = $part_export->ns_command( 'GET', '/cdr/',
31 'time_release' => '$time_release,',
32 '_sort' => '+time_release',
35 #loop over them, double check duplicates, insert the rest
37 my $content = $ns->responseContent;
39 #<a href="/tac2/cdr/20090219201719000016%40SkyNet360.Com">20090219201719000016@SkyNet360.Com</a>
40 # <form method="post" action="/tac2/cdr/20090219201719000016%40SkyNet360.Com">
42 s/^.*?<form method="post" action="\/tac2\/cdr\/(\d+)\%40[^"]*">//is )
46 warn "$accountcode\n" if $DEBUG;
48 $content =~ s/(.*?)<\/form>//is;
51 while ( $cdr_content =~
52 s/.*?<input name="(\w+)" type="\w+" value="([^"]+)" \/>//is )
54 warn " $1 => $2\n" if $DEBUG > 1;
56 my $cdr = new FS::cdr {
59 # 'startdate' => 'time_start', #XXX needs parsing
60 # 'enddate' => 'time_release', #XXX needs parsing
61 'duration' => 'duration',
62 'billsec' => 'time_talking',
64 'accountcode' => $accountcode,
74 "Usage: \n cdr-netsapiens.import user exportnum\n";
80 orig_req_host => residential.skynet360.com
82 orig_from_host => 63.251.149.5
83 batch_tim_beg => 2009-02-19 20:17:19
84 term_match => sip:7865457300@residential.skynet360.com
85 term_domain => residential.skynet360.com
86 term_sub => 7865457300
87 orig_req_user => 7865457300
88 orig_callid => 5D1164E6-44E011D6-8C84C368-EA5A0BC4@63.251.149.5
89 term_ip => 63.251.148.137:1453
90 term_to_uri => sip:7865457300@residential.skynet360.com
92 time_start => 2009-02-19 20:17:19.0
94 orig_from_user => 9046384544
96 term_logi_uri => sip:7865457300@residential.skynet360.com
98 orig_from_uri => sip:9046384544@63.251.149.5
100 orig_logi_uri => sip:9046384544@63.251.149.5
102 time_insert => 2009-02-19 15:17:38.0
103 orig_to_user => 7865457300
104 rly_prt_a => 63.251.149.18:21972
106 orig_to_host => 63.251.149.18
107 orig_match => sip:*@63.251.149.5
108 time_release => 2009-02-19 20:17:37
110 orig_req_uri => sip:7865457300@residential.skynet360.com
111 orig_to_uri => sip:7865457300@63.251.149.18
113 orig_ip => 63.251.149.5:57326
114 release_text => Orig: Cancel
116 time_ringing => 2009-02-19 20:17:19
119 orig_req_host => residential.skynet360.com
121 orig_from_host => 63.251.149.5
122 batch_tim_beg => 2009-02-19 20:17:19
123 term_match => sip:7865457300@residential.skynet360.com
124 term_domain => residential.skynet360.com
125 time_start => 2009-02-19 20:17:19.0
126 term_sub => 7865457300
127 orig_req_user => 7865457300
128 orig_callid => 5D1164E6-44E011D6-8C84C368-EA5A0BC4@63.251.149.5
129 term_ip => 63.251.148.137:1453
130 term_to_uri => sip:7865457300@residential.skynet360.com
132 time_start => 2009-02-19 20:17:19.0
134 orig_from_user => 9046384544
136 term_logi_uri => sip:7865457300@residential.skynet360.com
138 orig_from_uri => sip:9046384544@63.251.149.5
140 orig_logi_uri => sip:9046384544@63.251.149.5
142 time_insert => 2009-02-19 15:17:38.0
143 orig_to_user => 7865457300
144 rly_prt_a => 63.251.149.18:21972
146 orig_to_host => 63.251.149.18
147 orig_match => sip:*@63.251.149.5
148 time_release => 2009-02-19 20:17:37
150 orig_req_uri => sip:7865457300@residential.skynet360.com
151 orig_to_uri => sip:7865457300@63.251.149.18
153 orig_ip => 63.251.149.5:57326
154 release_text => Orig: Cancel
156 time_ringing => 2009-02-19 20:17:19
159 list of freeside CDR fields, useful ones marked with *
162 *[1] calldate - Call timestamp (SQL timestamp)
163 clid - Caller*ID with text
164 * src - Caller*ID number / Source number
165 * dst - Destination extension
166 dcontext - Destination context
167 channel - Channel used
168 dstchannel - Destination channel if appropriate
169 lastapp - Last application if appropriate
170 lastdata - Last application data
171 * startdate - Start of call (UNIX-style integer timestamp)
172 answerdate - Answer time of call (UNIX-style integer timestamp)
173 * enddate - End time of call (UNIX-style integer timestamp)
174 * duration - Total time in system, in seconds
175 * billsec - Total time call is up, in seconds
176 *[2] disposition - What happened to the call: ANSWERED, NO ANSWER, BUSY
177 amaflags - What flags to use: BILL, IGNORE etc, specified on a per
178 channel basis like accountcode.
179 *[3] accountcode - CDR account number to use: account
180 uniqueid - Unique channel identifier (Unitel/RSLCOM Event ID)
181 userfield - CDR user-defined field
182 cdr_type - CDR type - see FS::cdr_type (Usage = 1, S&E = 7, OC&C = 8)
183 *[4] charged_party - Service number to be billed
184 upstream_currency - Wholesale currency from upstream
185 *[5] upstream_price - Wholesale price from upstream
186 upstream_rateplanid - Upstream rate plan ID
187 rated_price - Rated (or re-rated) price
188 distance - km (need units field?)
189 islocal - Local - 1, Non Local = 0
190 *[6] calltypenum - Type of call - see FS::cdr_calltype
191 description - Description (cdr_type 7&8 only) (used for
192 cust_bill_pkg.itemdesc)
193 quantity - Number of items (cdr_type 7&8 only)
194 carrierid - Upstream Carrier ID (see FS::cdr_carrier)
195 upstream_rateid - Upstream Rate ID
196 svcnum - Link to customer service (see FS::cust_svc)
197 freesidestatus - NULL, done (or something)
199 [1] Auto-populated from startdate if not present
200 [2] Package options available to ignore calls without a specific disposition
201 [3] When using 'cdr-charged_party-accountcode' config
202 [4] Auto-populated from src (normal calls) or dst (toll free calls) if not present
203 [5] When using 'upstream_simple' rating method.
204 [6] Set to usage class classnum when using pre-rated CDRs and usage class-based
205 taxation (local/intrastate/interstate/international)