From 170f5c87ed12d02f3475a39df06403d9d22918f2 Mon Sep 17 00:00:00 2001 From: Deon George Date: Fri, 2 Dec 2022 22:54:02 +1100 Subject: [PATCH] Log systems polling --- app/Classes/Protocol.php | 17 +++++-- app/Models/System.php | 5 +++ app/Models/SystemLog.php | 15 +++++++ .../2022_11_26_042014_sessionlog.php | 44 +++++++++++++++++++ resources/views/system/view.blade.php | 4 ++ 5 files changed, 81 insertions(+), 4 deletions(-) create mode 100644 app/Models/SystemLog.php create mode 100644 database/migrations/2022_11_26_042014_sessionlog.php diff --git a/app/Classes/Protocol.php b/app/Classes/Protocol.php index 998bc38..fca3007 100644 --- a/app/Classes/Protocol.php +++ b/app/Classes/Protocol.php @@ -9,7 +9,7 @@ use Illuminate\Support\Facades\Log; use App\Classes\File\{Receive,Send}; use App\Classes\Sock\SocketClient; use App\Classes\Sock\SocketException; -use App\Models\{Address,Setup,System}; +use App\Models\{Address,Setup,System,SystemLog}; abstract class Protocol { @@ -324,10 +324,19 @@ abstract class Protocol foreach ($this->node->aka_other as $aka) { Address::findFTN($aka,TRUE,$so); } - } - // @todo Log to history log in the DB. - //if ($this->node->start_time && $this->setup->cfg('CFG_HISTORY')) {} + // Log session in DB + $slo = new SystemLog; + $slo->items_sent = $this->send->total_sent; + $slo->items_sent_size = $this->send->total_sent_bytes; + $slo->items_recv = $this->recv->total_recv; + $slo->items_recv_size = $this->recv->total_recv_bytes; + $slo->sessiontype = $type; + $slo->sessiontime = $this->node->session_time; + $slo->result = ($rc & self::S_MASK); + + $so->logs()->save($slo); + } // @todo Optional after session execution event // if ($this->node->start_time && $this->setup->cfg('CFG_AFTERSESSION')) {} diff --git a/app/Models/System.php b/app/Models/System.php index da43890..725a3e6 100644 --- a/app/Models/System.php +++ b/app/Models/System.php @@ -39,6 +39,11 @@ class System extends Model ->FTNorder(); } + public function logs() + { + return $this->hasMany(SystemLog::class); + } + /** * Session Passwords for system * diff --git a/app/Models/SystemLog.php b/app/Models/SystemLog.php new file mode 100644 index 0000000..71022bc --- /dev/null +++ b/app/Models/SystemLog.php @@ -0,0 +1,15 @@ +belongsTo(System::class); + } +} \ No newline at end of file diff --git a/database/migrations/2022_11_26_042014_sessionlog.php b/database/migrations/2022_11_26_042014_sessionlog.php new file mode 100644 index 0000000..8eccded --- /dev/null +++ b/database/migrations/2022_11_26_042014_sessionlog.php @@ -0,0 +1,44 @@ +id(); + $table->timestamps(); + + $table->bigInteger('system_id'); + $table->foreign('system_id')->references('id')->on('systems'); + + $table->integer('items_sent')->nullable(); + $table->integer('items_sent_size')->nullable(); + $table->integer('items_recv')->nullable(); + $table->integer('items_recv_size')->nullable(); + + $table->integer('sessiontime'); + $table->integer('sessiontype'); + + $table->integer('result'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('system_logs'); + } +}; diff --git a/resources/views/system/view.blade.php b/resources/views/system/view.blade.php index a1cbe89..ae4c3b3 100644 --- a/resources/views/system/view.blade.php +++ b/resources/views/system/view.blade.php @@ -31,6 +31,10 @@ Mailer {{ $o->access_mailer }} + + Last Seen + {{ $o->logs->last()->created_at }} + @if($o->phone) Phone