From 8598408a592612d7137950b7cda1bdb2ff760a87 Mon Sep 17 00:00:00 2001 From: Deon George Date: Fri, 26 Aug 2011 09:21:39 +1000 Subject: [PATCH] Fixed Service Traffic alerting --- .../controller/lnapp/templatedefault.php | 2 +- modules/emailtemplate/classes/emailtemplate.php | 5 ++--- modules/service/classes/model/service/adsl.php | 17 ++++++++++++----- .../service/classes/service/traffic/adsl.php | 2 +- modules/task/classes/model/task.php | 4 ++++ 5 files changed, 20 insertions(+), 10 deletions(-) diff --git a/application/classes/controller/lnapp/templatedefault.php b/application/classes/controller/lnapp/templatedefault.php index eb77e050..34e90cf6 100644 --- a/application/classes/controller/lnapp/templatedefault.php +++ b/application/classes/controller/lnapp/templatedefault.php @@ -149,7 +149,7 @@ abstract class Controller_lnApp_TemplateDefault extends Controller_Template { if ($this->auto_render) { // Application Title - $this->meta->title = 'Application Title'; + $this->meta->title = Kohana::Config('config.appname'); $this->template->title = ''; // Style Sheets Properties diff --git a/modules/emailtemplate/classes/emailtemplate.php b/modules/emailtemplate/classes/emailtemplate.php index 3c40d529..c3da2150 100644 --- a/modules/emailtemplate/classes/emailtemplate.php +++ b/modules/emailtemplate/classes/emailtemplate.php @@ -19,7 +19,6 @@ class EmailTemplate { private $components = array('subject','message_text','message_html'); public function __construct($template,$language_id=NULL) { - $this->template = ORM::factory('emailtemplate',array('name'=>$template)); if (! $this->template->loaded()) @@ -107,7 +106,8 @@ class EmailTemplate { public function send($admin=FALSE) { $e = Email::connect(); - $sm = Swift_Message::newInstance(); + $sm = Swift_Message::newInstance() + ->setFrom(Kohana::config('config.email_from')); foreach ($this->components as $component) { $s = $this->template_mail->$component; @@ -131,7 +131,6 @@ class EmailTemplate { } } - // @todo This should go to the admin defined in email_setup if ($admin OR ($admin = Config::testmail($this->template->name))) { $sm->setTo($admin); diff --git a/modules/service/classes/model/service/adsl.php b/modules/service/classes/model/service/adsl.php index e4c113ae..f49f5b99 100644 --- a/modules/service/classes/model/service/adsl.php +++ b/modules/service/classes/model/service/adsl.php @@ -224,7 +224,10 @@ class Model_Service_ADSL extends Model_Service { ); $return = array(); - $allowance = $this->adsl_plan->allowance(FALSE); + if ($this->service->product->prod_plugin_file != 'ADSL') + throw new Kohana_Exception('Huh? How did this get called, for a non ADSL product (:ppf)',array(':ppf'=>$this->service_id)); + + $allowance = $this->service->product->plugin()->allowance(FALSE); $period = strtotime('yesterday'); $traffic_data = $this->get_traffic_data_daily($period,FALSE); @@ -249,7 +252,7 @@ class Model_Service_ADSL extends Model_Service { $google->series(array( 'title'=>array((isset($friendly['cumulative_'.$k]) ? $friendly['cumulative_'.$k] : 'cumulative_'.$k)), 'axis'=>'r', - 'data'=>array((isset($friendly['cumulative_'.$k]) ? $friendly['cumulative_'.$k] : 'cumulative_'.$k)=>$this->cumulative($traffic_data['cumulative_'.$k])))); + 'data'=>array((isset($friendly['cumulative_'.$k]) ? $friendly['cumulative_'.$k] : 'cumulative_'.$k)=>$this->cumulative($traffic_data[$k])))); foreach ($array as $item) { switch ($item) { @@ -305,13 +308,17 @@ class Model_Service_ADSL extends Model_Service { * + last day of the period */ public function report_traffic() { - $allowance = $this->adsl_plan->allowance(FALSE); + if ($this->service->product->prod_plugin_file != 'ADSL') + throw new Kohana_Exception('Huh? How did this get called, for a non ADSL product (:ppf)',array(':ppf'=>$this->service_id)); + + $allowance = $this->service->product->plugin()->allowance(FALSE); $period = strtotime('yesterday'); $traffic_data = $this->get_traffic_data_daily($period,FALSE); $traffic = $this->get_traffic_data_month($period); $traffic_type = $this->get_traffic_data_daily($period,TRUE); + // @todo If no data comes in, then this can be stuck reporting traffic for an old date. $day = count($traffic_type) ? max(array_keys($traffic_type)) : 1; $lastday = date('d',strtotime('last day of',$period)); @@ -321,11 +328,11 @@ class Model_Service_ADSL extends Model_Service { return TRUE; // If we are at 80% usage - if ($v/($allowance[$k] > 0 ? $allowance[$k] : 1) >= .8 AND $day%3 == 3) + if ($v/($allowance[$k] > 0 ? $allowance[$k] : 1) >= .8 AND $day%3 == 0) return TRUE; // If our average is greater than our allowance - if ($day%5 == 5 AND ($v/$day > $allowance[$k]/$day)) + if ($day%5 == 0 AND ($v/$day > $allowance[$k]/$day)) return TRUE; } diff --git a/modules/service/classes/service/traffic/adsl.php b/modules/service/classes/service/traffic/adsl.php index f4532897..64cdf44b 100644 --- a/modules/service/classes/service/traffic/adsl.php +++ b/modules/service/classes/service/traffic/adsl.php @@ -148,7 +148,7 @@ class Service_Traffic_ADSL { continue; // Get our variable data - $et->to = array($so->account->email=>sprintf('%s %s',$so->account->first_name,$so->account->last_name)); + $et->to = array('account'=>array($so->account_id)); $et->variables = $so->service_adsl->template_variables($et->variables()); $et->send(); diff --git a/modules/task/classes/model/task.php b/modules/task/classes/model/task.php index 45d02bbe..b00a9fb3 100644 --- a/modules/task/classes/model/task.php +++ b/modules/task/classes/model/task.php @@ -67,6 +67,10 @@ class Model_Task extends ORMOSB { catch (Exception $e) { $tlo->result = $e->getCode(); $tlo->message = $e->getMessage(); + + $this->running = 0; + $this->running_host = NULL; + $this->save(); } }