-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheckLibCmd.go
95 lines (80 loc) · 2.28 KB
/
checkLibCmd.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package main
import (
"fmt"
"log"
"os"
"os/exec"
"strconv"
"strings"
"github.com/infrasonar/go-libagent"
)
func CheckLibCmd(_ *libagent.Check) (map[string][]map[string]any, error) {
state := map[string][]map[string]any{}
libCmdPhysicalExec := os.Getenv("LIB_CMD_PHYSICAL_EXEC")
if libCmdPhysicalExec == "" {
libCmdPhysicalExec = "lib_cmd display library physical all"
}
out, err := exec.Command("bash", "-c", libCmdPhysicalExec).Output()
var matches []string
lsms := []map[string]any{}
caps := []map[string]any{}
if err == nil {
lines := reSplit.Split(string(out), -1)
for _, line := range lines {
line = strings.TrimSpace(line)
if line == "" {
continue
}
matches = reLSM.FindStringSubmatch(line)
if matches != nil {
driveCount, err := strconv.ParseInt(matches[5], 10, 64)
if err != nil {
return nil, fmt.Errorf("failed to parse LSM Drive Count: %v", err)
}
volCount, err := strconv.ParseInt(matches[6], 10, 64)
if err != nil {
return nil, fmt.Errorf("failed to parse LSM Vol Count: %v", err)
}
freeCellCount, err := strconv.ParseInt(matches[7], 10, 64)
if err != nil {
return nil, fmt.Errorf("failed to parse LSM Free Cell Count: %v", err)
}
lsms = append(lsms, map[string]any{
"name": matches[1],
"type": matches[2],
"status": matches[3],
"state": matches[4],
"driveCount": driveCount,
"volCount": volCount,
"freeCellCount": freeCellCount,
})
}
matches = reCAP.FindStringSubmatch(line)
if matches != nil {
size, err := strconv.ParseInt(matches[6], 10, 64)
if err != nil {
return nil, fmt.Errorf("failed to parse CAP Size: %v", err)
}
caps = append(caps, map[string]any{
"name": matches[1],
"mode": matches[2],
"state": matches[3],
"status": matches[4],
"condition": matches[5],
"size": size,
"availability": matches[7],
})
}
}
} else {
log.Printf("Failed to execute: bash -c \"%v\" (%v)\n", libCmdPhysicalExec, err)
}
// Add the LSM type
state["LSM"] = lsms
// Add the CAP type
state["CAP"] = caps
// Print debug dump
// b, _ := json.MarshalIndent(state, "", " ")
// log.Fatal(string(b))
return state, nil
}