@@ -18,23 +18,16 @@ class AutoCheckNodeStatusJob extends Command
1818 protected $ signature = 'command:autoCheckNodeStatusJob ' ;
1919 protected $ description = '自动监测节点是否宕机 ' ;
2020 protected $ cacheKey = 'node_shutdown_warning_ ' ;
21- protected static $ config ;
2221
2322 public function __construct ()
2423 {
2524 parent ::__construct ();
26-
27- $ config = Config ::query ()->get ();
28- $ data = [];
29- foreach ($ config as $ vo ) {
30- $ data [$ vo ->name ] = $ vo ->value ;
31- }
32-
33- self ::$ config = $ data ;
3425 }
3526
3627 public function handle ()
3728 {
29+ $ config = $ this ->systemConfig ();
30+
3831 $ nodeList = SsNode ::query ()->where ('status ' , 1 )->get ();
3932 foreach ($ nodeList as $ node ) {
4033 // 10分钟内无节点信息则认为是宕机,因为每个节点的负载信息最多保存10分钟
@@ -49,9 +42,9 @@ public function handle()
4942 $ content = "系统监测到节点【 {$ node ->name }】( {$ node ->server })可能宕机了,请及时检查。 " ;
5043
5144 // 发邮件通知管理员
52- if (self :: $ config ['is_node_crash_warning ' ] && self :: $ config ['crash_warning_email ' ]) {
45+ if ($ config ['is_node_crash_warning ' ] && $ config ['crash_warning_email ' ]) {
5346 try {
54- Mail ::to (self :: $ config ['crash_warning_email ' ])->send (new nodeCrashWarning (self :: $ config ['website_name ' ], $ node ->name , $ node ->server ));
47+ Mail ::to ($ config ['crash_warning_email ' ])->send (new nodeCrashWarning ($ config ['website_name ' ], $ node ->name , $ node ->server ));
5548 $ this ->sendEmailLog (1 , $ title , $ content );
5649 } catch (\Exception $ e ) {
5750 $ this ->sendEmailLog (1 , $ title , $ content , 0 , $ e ->getMessage ());
@@ -62,9 +55,9 @@ public function handle()
6255 }
6356
6457 // 通过ServerChan发微信消息提醒管理员
65- if (self :: $ config ['is_server_chan ' ] && self :: $ config ['server_chan_key ' ]) {
58+ if ($ config ['is_server_chan ' ] && $ config ['server_chan_key ' ]) {
6659 $ serverChan = new ServerChan ();
67- $ result = $ serverChan ->send ($ title , $ content , self :: $ config ['server_chan_key ' ]);
60+ $ result = $ serverChan ->send ($ title , $ content , $ config ['server_chan_key ' ]);
6861 if ($ result ->errno > 0 ) {
6962 $ this ->sendEmailLog (1 , '[ServerChan] ' . $ title , $ content );
7063 } else {
@@ -99,4 +92,16 @@ private function sendEmailLog($user_id, $title, $content, $status = 1, $error =
9992 $ emailLogObj ->created_at = date ('Y-m-d H:i:s ' );
10093 $ emailLogObj ->save ();
10194 }
95+
96+ // 系统配置
97+ private function systemConfig ()
98+ {
99+ $ config = Config ::query ()->get ();
100+ $ data = [];
101+ foreach ($ config as $ vo ) {
102+ $ data [$ vo ->name ] = $ vo ->value ;
103+ }
104+
105+ return $ data ;
106+ }
102107}
0 commit comments