From c5701561d53776ba4b7a1ed0163b27d9d91679bb Mon Sep 17 00:00:00 2001 From: liupei Date: Mon, 24 Nov 2025 09:53:41 +0800 Subject: [PATCH] =?UTF-8?q?=E8=8E=B7=E5=8F=96=E8=A6=81=E4=BF=9D=E7=95=99?= =?UTF-8?q?=E5=92=8C=E5=88=A0=E9=99=A4=E7=9A=84=E6=99=BA=E8=83=BD=E8=BF=81?= =?UTF-8?q?=E7=A7=BB=E7=9B=B8=E5=85=B3=E8=B5=84=E6=BA=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- models/health.go | 58 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 57 insertions(+), 1 deletion(-) diff --git a/models/health.go b/models/health.go index 900bdc4..e4c1b66 100644 --- a/models/health.go +++ b/models/health.go @@ -178,4 +178,60 @@ func getHealthInuseList(nodeName string) []string { } } return pronInuse -} \ No newline at end of file +} + +func GetResource() (map[string]string, map[string]string) { + healthDeleteList := map[string]string{} + healthRevList := map[string]string{} + + cmdGetType := "cibadmin -Q -o resources | xmllint --xpath '//primitive/@type' - | awk -F 'type=\"|\"' '{print $2}'" + cmdGetResource := "cibadmin -Q -o resources | xmllint --xpath '//primitive/@id' - | awk -F 'type=\"|\"' '{print $2}'" + getType, _ := utils.RunCommand(cmdGetType) + getResource, _ := utils.RunCommand(cmdGetResource) + getTypeRes := utils.SplitLinesScanner(string(getType)) + getResourceRes := utils.SplitLinesScanner(string(getResource)) + + resourceDict := map[string]string{} + for i, k := range getResourceRes { + if i < len(getTypeRes) { + resourceDict[k] = getTypeRes[i] + } + } + + listType := []string{"HealthCPU", "HealthMEM", "SysInfo"} + resBak := []string{} + for key, value := range resourceDict { + if utils.Contains(listType, value) { + resBak = append(resBak, key) + } + } + + cmdGetSingleName := "crm_resource | grep 'Clone Set:' | awk -F '[' '{print $2}' | awk -F ']:' '{print $1}'" + getSingleName, _ := utils.RunCommand(cmdGetSingleName) + singleName := utils.SplitLinesScanner(string(getSingleName)) + + listName := []string{"sysinfo", "health_mem", "health_cpu"} + listTest := []string{} + + for _, single := range singleName { + if utils.Contains(listName, single) { + listTest = append(listTest, single) + } + } + + for _, i := range listTest { + for key, value := range resourceDict { + if i == key && ((key == "sysinfo" && value == "SysInfo") || (key == "health_mem" && value == "HealthMEM") || (key == "health_cpu" && value == "HealthCPU")) { + resBak = removeAll(resBak, i) + healthRevList[key] = value + } + } + } + + for key, value := range resourceDict { + if utils.Contains(resBak, key) { + healthDeleteList[key] = value + } + } + return healthDeleteList, healthRevList +} -- Gitee