From e4ce1885b2641b30a596c095096d3b17687c52a0 Mon Sep 17 00:00:00 2001
From: zhangqian <zhangqian@123.com>
Date: 星期四, 02 十一月 2023 21:33:31 +0800
Subject: [PATCH] fix

---
 service/problem/check.go |   28 ++++++++++++++++++++++++----
 1 files changed, 24 insertions(+), 4 deletions(-)

diff --git a/service/problem/check.go b/service/problem/check.go
index a7110d6..b379b7b 100644
--- a/service/problem/check.go
+++ b/service/problem/check.go
@@ -3,9 +3,12 @@
 import (
 	"apsClient/conf"
 	"apsClient/constvar"
+	"apsClient/model"
 	"apsClient/pkg/sqlitex"
 	"apsClient/service"
 	"apsClient/service/plc_address"
+	"fmt"
+	"net"
 	"sync"
 )
 
@@ -71,15 +74,16 @@
 		case constvar.ProblemCodePlcConnect:
 			checkObj = &PlcConnect{}
 		}
-		checkResultList = append(checkResultList, &CheckResult{
+		checkResultListTemp = append(checkResultListTemp, &CheckResult{
 			ItemCode:    item,
 			ItemName:    itemNameMap[item],
 			CheckResult: checkObj.Check(),
 		})
 	}
 	mutex.Lock()
+	defer mutex.Unlock()
 	checkResultList = checkResultListTemp
-	mutex.Unlock()
+
 }
 
 func Get() []*CheckResult {
@@ -102,7 +106,19 @@
 type Network struct{}
 
 func (slf *Network) Check() bool {
-	return false
+	ifaces, err := net.Interfaces()
+	if err != nil {
+		fmt.Println("Error:", err)
+		return false
+	}
+	var netAllFailed bool
+	for _, iFace := range ifaces {
+		if iFace.Flags == net.FlagUp {
+			netAllFailed = false
+			fmt.Printf("Interface %s is DOWN, indicating a network issue.\n", iFace.Name)
+		}
+	}
+	return !netAllFailed
 }
 
 type DB struct{}
@@ -124,7 +140,11 @@
 type Nsq struct{}
 
 func (slf *Nsq) Check() bool {
-	return false
+	old, err := model.NewSystemStatusSearch().SetKey(constvar.SystemStatusKeyNsq).First()
+	if err != nil {
+		return false
+	}
+	return old.Value == constvar.SystemStatusValueNormal
 }
 
 type Device struct{}

--
Gitblit v1.8.0