Browse Source

TCP阻断检测提醒次数(到达设定次数后节点自动进入维护状态)

admin 7 năm trước cách đây
mục cha
commit
8a39b288b5

+ 20 - 1
app/Console/Commands/AutoCheckNodeStatus.php

@@ -9,6 +9,7 @@ use App\Http\Models\EmailLog;
 use App\Http\Models\SsNode;
 use App\Http\Models\SsNodeInfo;
 use App\Mail\nodeCrashWarning;
+use Cache;
 use Mail;
 use Log;
 
@@ -63,9 +64,27 @@ class AutoCheckNodeStatus extends Command
                         $text = '正常';
                 }
 
+                // 已通知次数
+                $cacheKey = 'tcp_check_warning_times_' . $node->id;
+                if (Cache::has($cacheKey)) {
+                    $times = Cache::get($cacheKey);
+                } else {
+                    Cache::put($cacheKey, 1, 725); // 因为每小时检测一次,最多设置提醒12次,12*60=720分钟缓存时效,多5分钟防止异常
+                    $times = 1;
+                }
+
                 // 异常才发通知消息
                 if ($tcpCheck > 0) {
-                    $this->notifyMaster($title, "节点**{$node->name}【{$node->ip}】**:**" . $text . "**", $node->name, $node->server);
+                    if ($times < self::$config['tcp_check_warning_times']) {
+                        Cache::increment('tcp_check_warning_times_' . $node->id);
+
+                        $this->notifyMaster($title, "节点**{$node->name}【{$node->ip}】**:**" . $text . "**", $node->name, $node->server);
+                    } elseif ($times >= self::$config['tcp_check_warning_times']) {
+                        Cache::forget('tcp_check_warning_times_' . $node->id);
+                        SsNode::query()->where('id', $node->id)->update(['status' => 0]);
+
+                        $this->notifyMaster($title, "节点**{$node->name}【{$node->ip}】**:**" . $text . "**,节点自动进入维护状态", $node->name, $node->server);
+                    }
                 }
 
                 Log::info("【TCP阻断检测】" . $node->name . ' - ' . $node->ip . ' - ' . $text);

+ 36 - 2
resources/views/admin/system.blade.php

@@ -562,11 +562,27 @@
                                                                 <span class="help-block"> 创建消息通道后,在二维码上点击右键“复制图片地址”,展示于个人中心 </span>
                                                             </div>
                                                         </div>
+                                                        <div class="col-md-6"></div>
+                                                    </div>
+                                                    <div class="form-group">
                                                         <div class="col-md-6">
-                                                            <label for="is_tcp_check" class="col-md-3 control-label">TCP阻断探测</label>
+                                                            <label for="is_tcp_check" class="col-md-3 control-label">TCP阻断测</label>
                                                             <div class="col-md-9">
                                                                 <input type="checkbox" class="make-switch" @if($is_tcp_check) checked @endif id="is_tcp_check" data-on-color="success" data-off-color="danger" data-on-text="启用" data-off-text="关闭">
-                                                                <span class="help-block"> 自动检测是否被墙TCP阻断并提醒 </span>
+                                                                <span class="help-block"> 每小时自动检测节点是否被TCP阻断并提醒 </span>
+                                                            </div>
+                                                        </div>
+                                                        <div class="col-md-6">
+                                                            <label for="tcp_check_warning_times" class="col-md-3 control-label">阻断检测提醒</label>
+                                                            <div class="col-md-9">
+                                                                <div class="input-group">
+                                                                    <input class="form-control" type="text" name="tcp_check_warning_times" value="{{$tcp_check_warning_times}}" id="tcp_check_warning_times" placeholder="" />
+                                                                    <span class="input-group-addon">次</span>
+                                                                    <span class="input-group-btn">
+                                                                        <button class="btn btn-success" type="button" onclick="setTcpCheckWarningTimes()">修改</button>
+                                                                    </span>
+                                                                </div>
+                                                                <span class="help-block"> 提醒几次后自动下线节点,为0时不限制,不超过12 </span>
                                                             </div>
                                                         </div>
                                                     </div>
@@ -1311,6 +1327,24 @@
             });
         }
 
+        // 设置TCP阻断检测提醒次数
+        function setTcpCheckWarningTimes() {
+            var tcp_check_warning_times = $("#tcp_check_warning_times").val();
+
+            if (tcp_check_warning_times < 0 || tcp_check_warning_times > 12) {
+                layer.msg('只能在0-12之间', {time:1000});
+                return ;
+            }
+
+            $.post("{{url('admin/setConfig')}}", {_token:'{{csrf_token()}}', name:'tcp_check_warning_times', value:tcp_check_warning_times}, function (ret) {
+                layer.msg(ret.message, {time:1000}, function() {
+                    if (ret.status == 'fail') {
+                        window.location.reload();
+                    }
+                });
+            });
+        }
+
         // 设置订阅封禁阈值
         function setSubscribeBanTimes() {
             var subscribe_ban_times = $("#subscribe_ban_times").val();

+ 1 - 0
sql/db.sql

@@ -346,6 +346,7 @@ INSERT INTO `config` VALUES ('64', 'namesilo_key', '');
 INSERT INTO `config` VALUES ('65', 'website_logo', '');
 INSERT INTO `config` VALUES ('66', 'website_home_logo', '');
 INSERT INTO `config` VALUES ('67', 'is_tcp_check', 0);
+INSERT INTO `config` VALUES ('68', 'tcp_check_warning_times', 3);
 
 
 -- ----------------------------

+ 2 - 0
sql/update/20180911.sql

@@ -0,0 +1,2 @@
+-- 加入TCP阻断检测提醒次数
+INSERT INTO `config` VALUES ('68', 'tcp_check_warning_times', 3);