protected function buildData($line, $line_number = null) { $row = parent::buildData($line, $line_number); if (isset($row[$this->structConfig['config']['date_field']])) { if ($row['type'] == 'mmsc') { $datetime = DateTime::createFromFormat($this->structConfig['config']['date_format'], preg_replace('/^(\\d+)\\+(\\d)$/', '$1+0$2:00', $row[$this->structConfig['config']['date_field']])); $matches = array(); if (preg_match("/^\\+*(\\d+)\\//", $row['recipent_addr'], $matches)) { $row['called_number'] = $matches[1]; } } else { if (isset($row[$this->structConfig['config']['date_field']])) { $offset = (isset($this->structConfig['config']['date_offset']) && isset($row[$this->structConfig['config']['date_offset']]) ? ($row[$this->structConfig['config']['date_offset']] > 0 ? "+" : "") . $row[$this->structConfig['config']['date_offset']] : "00") . ':00'; $datetime = DateTime::createFromFormat($this->structConfig['config']['date_format'], $row[$this->structConfig['config']['date_field']] . $offset); } } if (isset($row[$this->structConfig['config']['calling_number_field']])) { $row[$this->structConfig['config']['calling_number_field']] = Billrun_Util::msisdn($row[$this->structConfig['config']['calling_number_field']]); } if (isset($row[$this->structConfig['config']['called_number_field']])) { $row[$this->structConfig['config']['called_number_field']] = Billrun_Util::msisdn($row[$this->structConfig['config']['called_number_field']]); } $row['urt'] = new MongoDate($datetime->format('U')); } return $row; }
protected function triggerCallingNumber($line) { $calling_number = Billrun_Util::msisdn($line['calling_number']); $query = array('calling_number' => $calling_number, 'in_circuit_group' => isset($line['in_circuit_group']) ? $line['in_circuit_group'] : '', 'date' => (int) date('Ymd', $line['urt']->sec)); $update = array('$inc' => array('usagev' => $line['usagev'], 'eventsCount' => 1)); $options = array('upsert' => true, 'w' => 0); try { Billrun_Factory::log()->log("Fraud plugin - calling " . $calling_number . " with usagev of " . $line['usagev'] . " upserted to the fraud calling collection", Zend_Log::DEBUG); $fraud_connection = Billrun_Factory::db(Billrun_Factory::config()->getConfigValue('fraud2.db'))->callingCollection(); $fraud_connection->update($query, $update, $options); } catch (Exception $e) { // @TODO: dump to file for durability Billrun_Factory::log()->log("Fraud plugin - Failed insert line with the stamp: " . $line['stamp'] . " to the fraud calling, got Exception : " . $e->getCode() . " : " . $e->getMessage(), Zend_Log::ERR); } }
/** * @see Billrun_Plugin_Interface_IParser::parseData */ public function parseData($type, $data, \Billrun_Parser &$parser) { if ($this->getName() != $type) { return FALSE; } $asnObject = Asn_Base::parseASNString($data); $parser->setLastParseLength($asnObject->getRawDataLength() + self::RECORD_PADDING); $type = $asnObject->getType(); $cdrLine = false; if (isset($this->ggsnConfig[$type])) { $cdrLine = $this->getASNDataByConfig($asnObject, $this->ggsnConfig[$type], $this->ggsnConfig['fields']); if ($cdrLine && !isset($cdrLine['record_type'])) { $cdrLine['record_type'] = $type; } //convert to unified time GMT time. $timeOffset = isset($cdrLine['ms_timezone']) ? $cdrLine['ms_timezone'] : date('P'); $cdrLine['urt'] = new MongoDate(Billrun_Util::dateTimeConvertShortToIso($cdrLine['record_opening_time'], $timeOffset)); if (is_array($cdrLine['rating_group'])) { $fbc_uplink_volume = $fbc_downlink_volume = 0; $cdrLine['org_fbc_uplink_volume'] = $cdrLine['fbc_uplink_volume']; $cdrLine['org_fbc_downlink_volume'] = $cdrLine['fbc_downlink_volume']; $cdrLine['org_rating_group'] = $cdrLine['rating_group']; foreach ($cdrLine['rating_group'] as $key => $rateVal) { if (isset($this->ggsnConfig['rating_groups'][$rateVal])) { $fbc_uplink_volume += $cdrLine['fbc_uplink_volume'][$key]; $fbc_downlink_volume += $cdrLine['fbc_downlink_volume'][$key]; } } $cdrLine['fbc_uplink_volume'] = $fbc_uplink_volume; $cdrLine['fbc_downlink_volume'] = $fbc_downlink_volume; $cdrLine['rating_group'] = 0; } else { if ($cdrLine['rating_group'] == 10) { return false; } } } else { Billrun_Factory::log()->log("couldn't find definition for {$type}", Zend_Log::INFO); } if (isset($cdrLine['calling_number'])) { $cdrLine['calling_number'] = Billrun_Util::msisdn($cdrLine['calling_number']); } if (isset($cdrLine['called_number'])) { $cdrLine['called_number'] = Billrun_Util::msisdn($cdrLine['called_number']); } //Billrun_Factory::log()->log($asnObject->getType() . " : " . print_r($cdrLine,1) , Zend_Log::DEBUG); return $cdrLine; }
/** * Pull required fields from the CDR nested tree to the surface. * @param type $cdrLine the line to monipulate. */ protected function surfaceCDRFields(&$cdrLine, $mapping) { foreach ($mapping as $key => $fieldToMap) { $val = Billrun_Util::getNestedArrayVal($cdrLine, $fieldToMap, null); if ($val !== null && Billrun_Util::getFieldVal($this->tap3Config['fields_to_save'][$key], false)) { $cdrLine[$key] = $val; } } if (Billrun_Util::getNestedArrayVal($cdrLine, $mapping['localTimeStamp']) !== null) { $offset = $this->currentFileHeader['networkInfo']['UtcTimeOffsetInfoList'][Billrun_Util::getNestedArrayVal($cdrLine, $mapping['TimeOffsetCode'])]; $cdrLine['urt'] = new MongoDate(Billrun_Util::dateTimeConvertShortToIso(Billrun_Util::getNestedArrayVal($cdrLine, $mapping['localTimeStamp']), $offset)); $cdrLine['tzoffset'] = $offset; } if (Billrun_Util::getNestedArrayVal($cdrLine, $mapping['tele_srv_code']) !== null && isset($cdrLine['record_type'])) { $tele_service_code = Billrun_Util::getNestedArrayVal($cdrLine, $mapping['tele_srv_code']); $record_type = $cdrLine['record_type']; if ($record_type == '9') { if ($tele_service_code == '11') { if (Billrun_Util::getNestedArrayVal($cdrLine, $mapping['dialed_digits'])) { $cdrLine['called_number'] = Billrun_Util::getNestedArrayVal($cdrLine, $mapping['dialed_digits']); } else { $cdrLine['called_number'] = Billrun_Util::getNestedArrayVal($cdrLine, $mapping['called_number']); //$cdrLine['basicCallInformation']['Desination']['CalledNumber']; } } else { if ($tele_service_code == '22') { if (Billrun_Util::getNestedArrayVal($cdrLine, $mapping['dialed_digits'])) { $cdrLine['called_number'] = Billrun_Util::getNestedArrayVal($cdrLine, $mapping['dialed_digits']); } else { if (isset($cdrLine['basicCallInformation']['Desination']['CalledNumber'])) { // @todo check with sefi. reference: db.lines.count({'BasicServiceUsedList.BasicServiceUsed.BasicService.BasicServiceCode.TeleServiceCode':"22",record_type:'9','basicCallInformation.Desination.DialedDigits':{$exists:false}});) $cdrLine['called_number'] = Billrun_Util::getNestedArrayVal($cdrLine, $mapping['called_number']); } } } } } else { if ($record_type == 'a') { if ($tele_service_code == '11') { if (Billrun_Util::getNestedArrayVal($cdrLine, $mapping['called_number'])) { $cdrLine['called_number'] = Billrun_Util::getNestedArrayVal($cdrLine, $mapping['called_number']); //$cdrLine['basicCallInformation']['Desination']['CalledNumber']; } } } } } if (isset($cdrLine['called_number'])) { $cdrLine['called_number'] = Billrun_Util::msisdn($cdrLine['called_number']); } // if (!Billrun_Util::getNestedArrayVal($cdrLine, $mapping['calling_number']) && isset($tele_service_code) && isset($record_type) ) { // if ($record_type == 'a' && ($tele_service_code == '11' || $tele_service_code == '21')) { // if (Billrun_Util::getNestedArrayVal($cdrLine, $mapping['call_org_number'])) { // for some calls (incoming?) there's no calling number // $cdrLine['calling_number'] = Billrun_Util::getNestedArrayVal($cdrLine, $mapping['call_org_number']); // } // } // } if (Billrun_Util::getNestedArrayVal($cdrLine, $mapping['serving_network']) !== null) { $cdrLine['serving_network'] = Billrun_Util::getNestedArrayVal($cdrLine, $mapping['serving_network']); } else { $cdrLine['serving_network'] = $this->currentFileHeader['header']['sending_source']; } if (Billrun_Util::getNestedArrayVal($cdrLine, $mapping['sdr']) !== null) { $sdrs = Billrun_Util::getNestedArrayVal($cdrLine, $mapping['sdr'], null, TRUE); $sum = $this->sumup_arrays($sdrs, 20); $cdrLine['sdr'] = $sum; $cdrLine['exchange_rate'] = $this->exchangeRates[Billrun_Util::getNestedArrayVal($cdrLine, $mapping['exchange_rate_code'], 0)]; } if (Billrun_Util::getNestedArrayVal($cdrLine, $mapping['sdr_tax']) !== null) { $cdrLine['sdr_tax'] = Billrun_Util::getNestedArrayVal($cdrLine, $mapping['sdr_tax']) / $this->sdr_division_value; } //save the sending source in each of the lines $cdrLine['sending_source'] = $this->currentFileHeader['header']['sending_source']; }
/** * @see Billrun_Plugin_Interface_IParser::parseData */ public function parseData($type, $line, Billrun_Parser &$parser) { if ($type != $this->getName()) { return FALSE; } $data = array(); $offset = 0; $data['record_length'] = $this->parseField(substr($line, $offset, 2), array('decimal' => 2)); $offset += 2; $data['record_type'] = $this->parseField(substr($line, $offset, 1), array('bcd_encode' => 1)); $offset += 1; //Billrun_Factory::log()->log("Record_type : {$data['record_type']}",Zend_log::DEBUG); if (isset($this->nsnConfig[$data['record_type']])) { foreach ($this->nsnConfig[$data['record_type']] as $key => $fieldDesc) { if ($fieldDesc) { if (isset($this->nsnConfig['fields'][$fieldDesc])) { $length = intval(current($this->nsnConfig['fields'][$fieldDesc]), 10); $data[$key] = $this->parseField(substr($line, $offset, $length), $this->nsnConfig['fields'][$fieldDesc]); /* if($data['record_type'] == "12") {//DEBUG... Billrun_Factory::log()->log("Data $key : {$data[$key]} , offset: ". dechex($offset),Zend_log::DEBUG); } */ $offset += $length; } else { throw new Exception("Nsn:parse - Couldn't find field: {$fieldDesc} "); } } } $data['urt'] = new MongoDate(Billrun_Util::dateTimeConvertShortToIso((string) (isset($data['charging_start_time']) && $data['charging_start_time'] ? $data['charging_start_time'] : $data['call_reference_time']), date("P", strtotime($data['call_reference_time'])))); //Use the actual charing time duration instead of the duration that was set by the switch if (isset($data['duration'])) { $data['org_dur'] = $data['duration']; // save the original duration. } if (isset($data['charging_end_time']) && isset($data['charging_start_time']) && (strtotime($data['charging_end_time']) > 0 && strtotime($data['charging_start_time']) > 0)) { $computed_dur = strtotime($data['charging_end_time']) - strtotime($data['charging_start_time']); if ($computed_dur >= 0) { $data['duration'] = $computed_dur; } else { Billrun_Factory::log("Processor received line (cf : " . $data['call_reference'] . " , cft : " . $data['call_reference_time'] . " ) with computed duration of {$computed_dur} using orginal duration field : {$data['duration']} ", Zend_Log::ALERT); } } //Remove the "10" in front of the national call with an international prefix // if (isset($data['in_circuit_group_name']) && preg_match("/^RCEL/", $data['in_circuit_group_name']) && strlen($data['called_number']) > 10 && substr($data['called_number'], 0, 2) == "10") { // will fail when in_circuit_group_name is empty / called_number length is exactly 10 if (isset($data['calling_number'])) { $data['calling_number'] = Billrun_Util::msisdn($data['calling_number']); } if (isset($data['called_number'])) { if (isset($data['out_circuit_group']) && in_array($data['out_circuit_group'], array('2100', '2101', '2499')) && substr($data['called_number'], 0, 2) == "10") { $data['called_number'] = substr($data['called_number'], 2); } else { if (in_array($data['record_type'], array('30', '31')) && preg_match($this->ild_called_number_regex, $data['called_number'])) { $data['ild_prefix'] = substr($data['called_number'], 0, 3); $data['called_number'] = substr($data['called_number'], 3); } } if (!isset($data['out_circuit_group']) || isset($data['out_circuit_group']) && !($data['out_circuit_group'] >= '2000' && $data['out_circuit_group'] <= '2069' || $data['out_circuit_group'] >= '2500' && $data['out_circuit_group'] <= '2529' || $data['out_circuit_group'] >= '1230' && $data['out_circuit_group'] <= '1233')) { $data['called_number'] = Billrun_Util::msisdn($data['called_number']); } } } else { // Billrun_Factory::log()->log("unsupported NSN record type : {$data['record_type']}",Zend_log::DEBUG); } $parser->setLastParseLength($data['record_length']); //@TODO add unifiom field translation. ('record_opening_time',etc...) return isset($this->nsnConfig[$data['record_type']]) ? $data : false; }