2010-11-29 22:41:08 +00:00
|
|
|
<?php defined('SYSPATH') or die('No direct access allowed.');
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This class is able to collect traffic information for People Agent
|
|
|
|
*
|
2013-03-19 22:35:19 +00:00
|
|
|
* @package ADSL
|
|
|
|
* @category Service
|
2010-11-29 22:41:08 +00:00
|
|
|
* @author Deon George
|
2013-03-19 22:35:19 +00:00
|
|
|
* @copyright (c) 2009-2013 Open Source Billing
|
2010-11-29 22:41:08 +00:00
|
|
|
* @license http://dev.osbill.net/license.html
|
|
|
|
*/
|
|
|
|
class Service_Traffic_ADSL_PeopleAgent extends Service_Traffic_ADSL {
|
|
|
|
private $login_user_field = 'username';
|
|
|
|
private $login_pass_field = 'password';
|
|
|
|
private $date_field = 'date';
|
|
|
|
|
|
|
|
protected function getdata($date) {
|
|
|
|
// Assume we have a bad fetch, unless otherwise specified.
|
|
|
|
$this->fetchresult = FALSE;
|
|
|
|
|
2013-04-05 12:50:08 +00:00
|
|
|
$result = array();
|
2010-11-29 22:41:08 +00:00
|
|
|
$url_suffix = sprintf('traffic_V34_%s.xml',date('Ymd',strtotime($date)));
|
|
|
|
|
|
|
|
try {
|
|
|
|
$data = Remote::get($this->so->stats_url.$url_suffix,$this->curlopts+array(
|
|
|
|
CURLOPT_HTTPAUTH => CURLAUTH_BASIC,
|
|
|
|
CURLOPT_USERPWD => sprintf('%s:%s',$this->so->stats_username,$this->so->stats_password),
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
catch (Exception $e) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->fetchresult = TRUE;
|
2012-07-05 03:06:17 +00:00
|
|
|
foreach (XML::factory(NULL,NULL,$data)->get('user') as $user) {
|
2010-11-29 22:41:08 +00:00
|
|
|
$attrs = array();
|
|
|
|
|
|
|
|
$userattrs = $user->attributes();
|
|
|
|
$attrs['service'] = $userattrs['username'];
|
|
|
|
$attrs['date'] = $date;
|
|
|
|
|
|
|
|
foreach ($user->year->month->day->get('hour') as $hour => $traffic) {
|
|
|
|
foreach (array('external'=>'down_peak','internal'=>'internal','peering'=>'peer') as $t => $k) {
|
|
|
|
$tatters = $traffic->$t->attributes();
|
|
|
|
|
|
|
|
// Traffic is in bytes, need to convert to MB
|
|
|
|
if (empty($attrs[$k]))
|
|
|
|
$attrs[$k] = $tatters['bytes']/1000/1000;
|
|
|
|
else
|
|
|
|
$attrs[$k] += $tatters['bytes']/1000/1000;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-05 12:50:08 +00:00
|
|
|
array_push($result,$attrs);
|
2010-11-29 22:41:08 +00:00
|
|
|
}
|
|
|
|
|
2013-04-05 12:50:08 +00:00
|
|
|
return $result;
|
2010-11-29 22:41:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
?>
|