Browse Source

update: sort leave alert

tokumeikoi 3 years ago
parent
commit
f896370e64

+ 65 - 0
app/Console/Commands/CheckServer.php

@@ -0,0 +1,65 @@
+<?php
+
+namespace App\Console\Commands;
+
+use App\Services\ServerService;
+use App\Services\TelegramService;
+use App\Utils\CacheKey;
+use Illuminate\Console\Command;
+use Illuminate\Support\Facades\Cache;
+
+class CheckServer extends Command
+{
+    /**
+     * The name and signature of the console command.
+     *
+     * @var string
+     */
+    protected $signature = 'check:server';
+
+    /**
+     * The console command description.
+     *
+     * @var string
+     */
+    protected $description = '节点检查任务';
+
+    /**
+     * Create a new command instance.
+     *
+     * @return void
+     */
+    public function __construct()
+    {
+        parent::__construct();
+    }
+
+    /**
+     * Execute the console command.
+     *
+     * @return mixed
+     */
+    public function handle()
+    {
+        $this->checkOffline();
+    }
+
+    private function checkOffline()
+    {
+        $serverService = new ServerService();
+        $servers = $serverService->getAllServers();
+        foreach ($servers as $server) {
+            if ($server['parent_id']) continue;
+            if ($server['last_check_at'] && (time() - $server['last_check_at']) > 1800) {
+                $telegramService = new TelegramService();
+                $message = sprintf(
+                    "节点掉线通知\r\n----\r\n节点名称:%s\r\n节点地址:%s\r\n",
+                    $server['name'],
+                    $server['host']
+                );
+                $telegramService->sendMessageWithAdmin($message);
+                Cache::forget(CacheKey::get(sprintf("SERVER_%s_LAST_CHECK_AT", strtoupper($server['type'])), $server->id));
+            }
+        }
+    }
+}

+ 1 - 9
app/Http/Controllers/Admin/Server/ManageController.php

@@ -15,16 +15,8 @@ class ManageController extends Controller
     public function getNodes(Request $request)
     {
         $serverService = new ServerService();
-        $servers = array_merge(
-            $serverService->getShadowsocksServers(),
-            $serverService->getV2rayServers(),
-            $serverService->getTrojanServers()
-        );
-        $serverService->mergeData($servers);
-        $tmp = array_column($servers, 'sort');
-        array_multisort($tmp, SORT_ASC, $servers);
         return response([
-            'data' => $servers
+            'data' => $serverService->getAllServers()
         ]);
     }
 

+ 13 - 0
app/Services/ServerService.php

@@ -358,4 +358,17 @@ class ServerService
             }
         }
     }
+
+    public function getAllServers()
+    {
+        $servers = array_merge(
+            $this->getShadowsocksServers(),
+            $this->getV2rayServers(),
+            $this->getTrojanServers()
+        );
+        $this->mergeData($servers);
+        $tmp = array_column($servers, 'sort');
+        array_multisort($tmp, SORT_ASC, $servers);
+        return $servers;
+    }
 }

+ 1 - 1
config/app.php

@@ -236,5 +236,5 @@ return [
     | The only modification by laravel config
     |
     */
-    'version' => '1.5.2.1622635807521'
+    'version' => '1.5.2.1623150408913'
 ];

File diff suppressed because it is too large
+ 0 - 0
public/assets/admin/umi.js


Some files were not shown because too many files changed in this diff