GetNodeDiskSmart retrieves the SMART status for a specific disk on a node.
(nodeName, diskPath string)
| 68 | |
| 69 | // GetNodeDiskSmart retrieves the SMART status for a specific disk on a node. |
| 70 | func (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 | } |