3 # */5 * * * /home/ivan/freeside/bin/cdr-netsapiens.import ivan exportnum
9 use FS::UID qw(adminsuidsetup dbh);
10 use FS::Record qw(qsearchs);
16 my $user = shift or die &usage;
19 my $exportnum = shift or die &usage;
20 my $part_export = qsearchs('part_export', { 'exportnum' => $exportnum } )
21 or die "unknown exportnum $exportnum\n";
27 #find max time_release
28 my $sth = dbh->prepare('SELECT MAX(enddate) FROM cdr') #XXX and imported from this netsapens switch
31 $sth->execute or die $sth->errstr;
32 my $time_relase = time2str('%Y-%m-%d %x', $sth->fetchrow_arrayref->[0]);
34 #my $time_release = '2009-01-01 00:00:00';
36 #retreive CDRs >= this time
38 my $ns = $part_export->ns_command( 'GET', '/cdr/',
39 'time_release' => '$time_release,',
40 '_sort' => '+time_release',
43 #loop over them, double check duplicates, insert the rest
45 my $content = $ns->responseContent;
49 #<a href="/tac2/cdr/20090219201719000016%40SkyNet360.Com">20090219201719000016@SkyNet360.Com</a>
50 # <form method="post" action="/tac2/cdr/20090219201719000016%40SkyNet360.Com">
52 s/^.*?<form method="post" action="\/tac2\/cdr\/(\d+)\%40[^"]*">//is )
56 warn "$accountcode\n" if $DEBUG;
58 $content =~ s/(.*?)<\/form>//is;
62 while ( $cdr_content =~
63 s/.*?<input name="(\w+)" type="\w+" value="([^"]+)" \/>//is )
65 warn " $1 => $2\n" if $DEBUG > 1;
71 my $cdr = new FS::cdr {
72 'src' => $cdr{'orig_sub'}, #orig_from_user?
73 'dst' => $cdr{'term_sub'},
74 'startdate' => FS::cdr::_cdr_date_parse($cdr{'time_start'}),
75 'enddate' => FS::cdr::_cdr_date_parse($cdr{'time_release'}),
76 'duration' => $cdr{'duration'},
77 'billsec' => $cdr{'time_talking'},
79 'accountcode' => $accountcode,
88 "Usage: \n cdr-netsapiens.import user exportnum\n";
94 orig_req_host => residential.skynet360.com
96 orig_from_host => 63.251.149.5
97 batch_tim_beg => 2009-02-19 20:17:19
98 term_match => sip:7865457300@residential.skynet360.com
99 term_domain => residential.skynet360.com
100 term_sub => 7865457300
101 orig_req_user => 7865457300
102 orig_callid => 5D1164E6-44E011D6-8C84C368-EA5A0BC4@63.251.149.5
103 term_ip => 63.251.148.137:1453
104 term_to_uri => sip:7865457300@residential.skynet360.com
106 time_start => 2009-02-19 20:17:19.0
108 orig_from_user => 9046384544
110 term_logi_uri => sip:7865457300@residential.skynet360.com
112 orig_from_uri => sip:9046384544@63.251.149.5
114 orig_logi_uri => sip:9046384544@63.251.149.5
116 time_insert => 2009-02-19 15:17:38.0
117 orig_to_user => 7865457300
118 rly_prt_a => 63.251.149.18:21972
120 orig_to_host => 63.251.149.18
121 orig_match => sip:*@63.251.149.5
122 time_release => 2009-02-19 20:17:37
124 orig_req_uri => sip:7865457300@residential.skynet360.com
125 orig_to_uri => sip:7865457300@63.251.149.18
127 orig_ip => 63.251.149.5:57326
128 release_text => Orig: Cancel
130 time_ringing => 2009-02-19 20:17:19
133 orig_req_host => residential.skynet360.com
135 orig_from_host => 63.251.149.5
136 batch_tim_beg => 2009-02-19 20:17:19
137 term_match => sip:7865457300@residential.skynet360.com
138 term_domain => residential.skynet360.com
139 time_start => 2009-02-19 20:17:19.0
140 term_sub => 7865457300
141 orig_req_user => 7865457300
142 orig_callid => 5D1164E6-44E011D6-8C84C368-EA5A0BC4@63.251.149.5
143 term_ip => 63.251.148.137:1453
144 term_to_uri => sip:7865457300@residential.skynet360.com
146 time_start => 2009-02-19 20:17:19.0
148 orig_from_user => 9046384544
150 term_logi_uri => sip:7865457300@residential.skynet360.com
152 orig_from_uri => sip:9046384544@63.251.149.5
154 orig_logi_uri => sip:9046384544@63.251.149.5
156 time_insert => 2009-02-19 15:17:38.0
157 orig_to_user => 7865457300
158 rly_prt_a => 63.251.149.18:21972
160 orig_to_host => 63.251.149.18
161 orig_match => sip:*@63.251.149.5
162 time_release => 2009-02-19 20:17:37
164 orig_req_uri => sip:7865457300@residential.skynet360.com
165 orig_to_uri => sip:7865457300@63.251.149.18
167 orig_ip => 63.251.149.5:57326
168 release_text => Orig: Cancel
170 time_ringing => 2009-02-19 20:17:19
173 list of freeside CDR fields, useful ones marked with *
176 *[1] calldate - Call timestamp (SQL timestamp)
177 clid - Caller*ID with text
178 * src - Caller*ID number / Source number
179 * dst - Destination extension
180 dcontext - Destination context
181 channel - Channel used
182 dstchannel - Destination channel if appropriate
183 lastapp - Last application if appropriate
184 lastdata - Last application data
185 * startdate - Start of call (UNIX-style integer timestamp)
186 answerdate - Answer time of call (UNIX-style integer timestamp)
187 * enddate - End time of call (UNIX-style integer timestamp)
188 * duration - Total time in system, in seconds
189 * billsec - Total time call is up, in seconds
190 *[2] disposition - What happened to the call: ANSWERED, NO ANSWER, BUSY
191 amaflags - What flags to use: BILL, IGNORE etc, specified on a per
192 channel basis like accountcode.
193 *[3] accountcode - CDR account number to use: account
194 uniqueid - Unique channel identifier (Unitel/RSLCOM Event ID)
195 userfield - CDR user-defined field
196 cdr_type - CDR type - see FS::cdr_type (Usage = 1, S&E = 7, OC&C = 8)
197 *[4] charged_party - Service number to be billed
198 upstream_currency - Wholesale currency from upstream
199 *[5] upstream_price - Wholesale price from upstream
200 upstream_rateplanid - Upstream rate plan ID
201 rated_price - Rated (or re-rated) price
202 distance - km (need units field?)
203 islocal - Local - 1, Non Local = 0
204 *[6] calltypenum - Type of call - see FS::cdr_calltype
205 description - Description (cdr_type 7&8 only) (used for
206 cust_bill_pkg.itemdesc)
207 quantity - Number of items (cdr_type 7&8 only)
208 carrierid - Upstream Carrier ID (see FS::cdr_carrier)
209 upstream_rateid - Upstream Rate ID
210 svcnum - Link to customer service (see FS::cust_svc)
211 freesidestatus - NULL, done (or something)
213 [1] Auto-populated from startdate if not present
214 [2] Package options available to ignore calls without a specific disposition
215 [3] When using 'cdr-charged_party-accountcode' config
216 [4] Auto-populated from src (normal calls) or dst (toll free calls) if not present
217 [5] When using 'upstream_simple' rating method.
218 [6] Set to usage class classnum when using pre-rated CDRs and usage class-based
219 taxation (local/intrastate/interstate/international)