public function __construct($options) { parent::__construct($options); $this->reportType = isset($options['report_type']) ? $options['report_type'] : $this->reportType; $this->reportBasePath = Billrun_Factory::config()->getConfigValue($this->reportType . '.reports.path', './'); $this->types = Billrun_Factory::config()->getConfigValue($this->reportType . '.reports.types', array('I' => 'International', 'M' => 'Mobile', 'N' => 'National', '4' => 'National', 'P' => 'National', 'Un' => 'Other')); $this->startDate = isset($options['start_date']) ? strtotime($options['start_date']) : (strlen($this->stamp) > 8 ? strtotime($this->stamp) : Billrun_Util::getLastChargeTime(true)); $this->endDate = isset($options['end_date']) ? strtotime($options['end_date']) : strtotime(date('Ymt', $this->startDate)); }
/** * method to collect data which need to be handle by event */ public function handlerCollect($options) { if ($this->getName() != $options['type']) { return FALSE; } Billrun_Factory::log()->log("ILDS fraud collect handler triggered", Zend_Log::DEBUG); $lines = Billrun_Factory::db()->linesCollection(); $charge_time = Billrun_Util::getLastChargeTime(true, Billrun_Factory::config()->getConfigValue('ilds.billrun.charging_day', 20)); $base_match = array('$match' => array('source' => 'ilds')); $where = array('$match' => array('event_stamp' => array('$exists' => false), 'deposit_stamp' => array('$exists' => false), 'urt' => array('$gte' => new MongoDate($charge_time)), 'aprice' => array('$exists' => true), 'billrun' => array('$exists' => false))); $group = array('$group' => array("_id" => '$caller_phone_no', 'msisdn' => array('$first' => '$caller_phone_no'), "total" => array('$sum' => '$aprice'), 'lines_stamps' => array('$addToSet' => '$stamp'))); $project = array('$project' => array('caller_phone_no' => '$_id', '_id' => 0, 'msidsn' => 1, 'total' => 1, 'lines_stamps' => 1)); $having = array('$match' => array('total' => array('$gte' => floatval(Billrun_Factory::config()->getConfigValue('ilds.threshold', 100))))); $ret = $lines->aggregate($base_match, $where, $group, $project, $having); Billrun_Factory::log()->log("ILDS fraud plugin found " . count($ret) . " items", Zend_Log::DEBUG); return $ret; }
/** * helper method to receive the last time of the monthly charge * * @param boolean $return_timestamp if set to true return time stamp else full format of yyyymmddhhmmss * * @return mixed timestamp or full format of time * @deprecated since version 0.4 use Billrun_Util::getLastChargeTime instead */ protected function get_last_charge_time($return_timestamp = false) { Billrun_Factory::log()->log("Billrun_Plugin_BillrunPluginFraud::get_last_charge_time is deprecated; please use Billrun_Util::getLastChargeTime()", Zend_Log::DEBUG); return Billrun_Util::getLastChargeTime($return_timestamp); }
/** * method to collect data which need to be handle by event */ public function handlerCollect($options) { if ($options['type'] != 'roaming') { return FALSE; } $lines = Billrun_Factory::db()->linesCollection(); $charge_time = Billrun_Util::getLastChargeTime(true); // true means return timestamp // TODO: take it to config ? how to handle variables ? $base_match = array('$match' => array('source' => 'nrtrde')); $where = array('$match' => array('record_type' => 'MOC', 'connectedNumber' => array('$regex' => '^972'), 'urt' => array('$gte' => new MongoDate($charge_time)), 'event_stamp' => array('$exists' => false), 'deposit_stamp' => array('$exists' => false), 'callEventDurationRound' => array('$gt' => 0))); $group = array('$group' => array("_id" => '$imsi', "moc_israel" => array('$sum' => '$callEventDurationRound'), 'lines_stamps' => array('$addToSet' => '$stamp'))); $project = array('$project' => array('imsi' => '$_id', '_id' => 0, 'moc_israel' => 1, 'lines_stamps' => 1)); $having = array('$match' => array('moc_israel' => array('$gte' => Billrun_Factory::config()->getConfigValue('nrtrde.thresholds.moc.israel', 9999999, 'int')))); $ret = array(); Billrun_Factory::log()->log("nrtrdePlugin::handlerCollect collecting moc_israel exceeders", Zend_Log::DEBUG); $moc_israel = $lines->aggregate($base_match, $where, $group, $project, $having); $this->normalize($ret, $moc_israel, 'moc_israel'); $where['$match']['connectedNumber']['$regex'] = '^(?!972)'; $group['$group']['moc_nonisrael'] = $group['$group']['moc_israel']; unset($group['$group']['moc_israel']); unset($having['$match']['moc_israel']); $having['$match']['moc_nonisrael'] = array('$gte' => Billrun_Factory::config()->getConfigValue('nrtrde.thresholds.moc.nonisrael', 9999999, 'int')); $project['$project']['moc_nonisrael'] = 1; unset($project['$project']['moc_israel']); Billrun_Factory::log()->log("nrtrdePlugin::handlerCollect collecting moc_nonisrael exceeders", Zend_Log::DEBUG); $moc_nonisrael = $lines->aggregate($base_match, $where, $group, $project, $having); $this->normalize($ret, $moc_nonisrael, 'moc_nonisrael'); $where['$match']['record_type'] = 'MTC'; unset($where['$match']['connectedNumber']); $group['$group']['mtc_all'] = $group['$group']['moc_nonisrael']; unset($group['$group']['moc_nonisrael']); unset($having['$match']['moc_nonisrael']); $having['$match']['mtc_all'] = array('$gte' => Billrun_Factory::config()->getConfigValue('nrtrde.thresholds.mtc', 9999999, 'int')); $project['$project']['mtc_all'] = 1; unset($project['$project']['moc_nonisrael']); Billrun_Factory::log()->log("nrtrdePlugin::handlerCollect collecting mtc_all exceeders", Zend_Log::DEBUG); $mtc = $lines->aggregate($base_match, $where, $group, $project, $having); $this->normalize($ret, $mtc, 'mtc_all'); $where['$match']['record_type'] = 'MOC'; $where['$match']['callEventDurationRound'] = 0; $group['$group']['sms_out'] = $group['$group']['mtc_all']; unset($group['$group']['mtc_all']); unset($having['$match']['mtc_all']); $group['$group']['sms_out'] = array('$sum' => 1); $having['$match']['sms_out'] = array('$gte' => Billrun_Factory::config()->getConfigValue('nrtrde.thresholds.smsout', 9999999, 'int')); $project['$project']['sms_out'] = 1; unset($project['$project']['mtc_all']); Billrun_Factory::log()->log("nrtrdePlugin::handlerCollect collecting sms_out exceeders", Zend_Log::DEBUG); $sms_out = $lines->aggregate($base_match, $where, $group, $project, $having); $this->normalize($ret, $sms_out, 'sms_out'); unset($group['$group']['sms_out']); unset($having['$match']['sms_out']); unset($project['$project']['sms_out']); $timeWindow = strtotime("-" . Billrun_Factory::config()->getConfigValue('nrtrde.hourly.timespan', '1h')); $where['$match']['urt'] = array('$gt' => new MongoDate($timeWindow)); $group['$group']['sms_hourly'] = array('$sum' => 1); $having['$match']['sms_hourly'] = array('$gte' => Billrun_Factory::config()->getConfigValue('nrtrde.hourly.thresholds.smsout', 9999999, 'int')); $project['$project']['sms_hourly'] = 1; Billrun_Factory::log()->log("nrtrdePlugin::handlerCollect collecting sms_hourly exceeders", Zend_Log::DEBUG); $sms_hourly = $lines->aggregate($base_match, $where, $group, $project, $having); $this->normalize($ret, $sms_hourly, 'sms_hourly'); unset($group['$group']['sms_hourly']); unset($having['$match']['sms_hourly']); unset($project['$project']['sms_hourly']); $where['$match']['urt'] = array('$gt' => new MongoDate($timeWindow)); $where['$match']['callEventDurationRound'] = array('$gt' => 0); $group['$group']['moc_nonisrael_hourly'] = array('$sum' => '$callEventDurationRound'); $having['$match']['moc_nonisrael_hourly'] = array('$gte' => Billrun_Factory::config()->getConfigValue('nrtrde.hourly.thresholds.mocnonisrael', 9999999)); $project['$project']['moc_nonisrael_hourly'] = 1; Billrun_Factory::log()->log("nrtrdePlugin::handlerCollect collecting moc_nonisrael_hourly exceeders", Zend_Log::DEBUG); $moc_nonisrael_hourly = $lines->aggregate($base_match, $where, $group, $project, $having); $this->normalize($ret, $moc_nonisrael_hourly, 'moc_nonisrael_hourly'); Billrun_Factory::log()->log("NRTRDE plugin locate " . count($ret) . " items as fraud events", Zend_Log::INFO); return $ret; }
/** * Mark the lines that generated the event as dealt with. * @param type $event the event that relate to the lines. */ protected function markEventLines($event) { //mark deposit for the lines on the current imsi Billrun_Log::getInstance()->log("Fraud alerts mark event lines " . $event['deposit_stamp'], Zend_Log::INFO); $imsi = isset($event['imsi']) && $event['imsi'] ? $event['imsi'] : null; $msisdn = isset($event['msisdn']) && $event['msisdn'] ? $event['msisdn'] : null; $lines_where = array(); if ($imsi) { $lines_where['imsi'] = $imsi; } if ($msisdn) { $lines_where['msisdn'] = $msisdn; } // if (isset($event['effects'])) { // $lines_where[$event['effects']['key']] = $event['effects']['filter']; // } else { // $lines_where['type'] = $event['source']; // } // $lines_where['process_time'] = array('$gt' => date(Billrun_Base::base_dateformat, Billrun_Util::getLastChargeTime())); $lines_where['process_time'] = array('$lt' => date(Billrun_Base::base_dateformat, $this->startTime)); $lines_where['deposit_stamp'] = array('$exists' => false); if (!($imsi || $msisdn)) { Billrun_Log::getInstance()->log("fraudAlertsPlugin::markEventLines cannot find IMSI nor NDC_SN on event, marking CDR lines with event_stamp of : " . print_r($event['stamps'], 1), Zend_Log::INFO); $lines_where['event_stamp'] = array('$in' => $event['stamps']); } // the update will done manually due to performance with collection update (not supported with hint) // @TODO: when update command will suport hint will use update (see remark code after foreach loop) $rows = $this->linesCol->query($lines_where)->cursor()->hint(array('imsi' => 1)); foreach ($rows as $row) { $row->collection($this->linesCol); $row->set('deposit_stamp', $event['deposit_stamp']); $row->save($this->linesCol); } // forward compatibility // $lines_update_set = array( // '$set' => array( 'deposit_stamp' => $event['deposit_stamp'] ) // ); // $update_options = array( 'multiple' => 1 ); // // $this->linesCol->update($lines_where, $lines_update_set, $update_options); }