#!/usr/bin/perl # # */5 * * * /home/ivan/freeside/bin/cdr-netsapiens.import ivan exportnum use strict; use vars qw( $DEBUG ); use Date::Format; use REST::Client; use FS::UID qw(adminsuidsetup dbh); use FS::Record qw(qsearchs); use FS::part_export; use FS::cdr; $DEBUG = 1; my $user = shift or die &usage; adminsuidsetup $user; my $exportnum = shift or die &usage; my $part_export = qsearchs('part_export', { 'exportnum' => $exportnum } ) or die "unknown exportnum $exportnum\n"; my $cdrbatch = 'NetSapiens import '. time2str('%Y-%m-%d %x', $^T); my $cdrs = 0; do { #find max time_release my $sth = dbh->prepare('SELECT MAX(enddate) FROM cdr') #XXX and imported from this netsapens switch or die dbh->errstr; $sth->execute or die $sth->errstr; my $time_release = time2str('%Y-%m-%d %X', $sth->fetchrow_arrayref->[0]); #retreive CDRs >= this time my $ns = $part_export->ns_command( 'GET', '/cdr/', 'time_release' => "$time_release,", '_sort' => '+time_release', '_limit' => '500', ); #loop over them, double check duplicates, insert the rest my $content = $ns->responseContent; $cdrs = 0; #20090219201719000016@SkyNet360.Com #