MCPcopy Create free account
hub / github.com/devnullvoid/pvetui / GetNodeDiskSmart

Method GetNodeDiskSmart

pkg/api/node_disks.go:70–108  ·  view source on GitHub ↗

GetNodeDiskSmart retrieves the SMART status for a specific disk on a node.

(nodeName, diskPath string)

Source from the content-addressed store, hash-verified

68
69// GetNodeDiskSmart retrieves the SMART status for a specific disk on a node.
70func (c *Client) GetNodeDiskSmart(nodeName, diskPath string) (*SmartStatus, error) {
71 var res map[string]interface{}
72 // /nodes/{node}/disks/smart?disk={diskPath}
73 path := fmt.Sprintf("/nodes/%s/disks/smart?disk=%s", nodeName, url.QueryEscape(diskPath))
74
75 if err := c.GetWithCache(path, &res, NodeDataTTL); err != nil {
76 return nil, fmt.Errorf("failed to get disk smart info: %w", err)
77 }
78
79 data, ok := res["data"].(map[string]interface{})
80 if !ok {
81 return nil, fmt.Errorf("invalid smart response format")
82 }
83
84 smart := &SmartStatus{
85 Health: getString(data, "health"),
86 Type: getString(data, "type"),
87 Text: getString(data, "text"),
88 }
89
90 if attrs, ok := data["attributes"].([]interface{}); ok {
91 for _, a := range attrs {
92 if aMap, ok := a.(map[string]interface{}); ok {
93 attr := SmartAttribute{
94 ID: int(getFloat(aMap, "id")),
95 Name: getString(aMap, "name"),
96 Value: int(getFloat(aMap, "value")),
97 Worst: int(getFloat(aMap, "worst")),
98 Thresh: int(getFloat(aMap, "thresh")),
99 Fail: getBool(aMap, "fail"), // Uses utils.go implementation
100 Raw: getString(aMap, "raw"),
101 }
102 smart.Attributes = append(smart.Attributes, attr)
103 }
104 }
105 }
106
107 return smart, nil
108}

Callers 1

TestGetNodeDiskSmartFunction · 0.95

Calls 4

GetWithCacheMethod · 0.95
getStringFunction · 0.85
getFloatFunction · 0.85
getBoolFunction · 0.85

Tested by 1

TestGetNodeDiskSmartFunction · 0.76