Преглед изворни кода

Added working degrade detection in detail

aroz пре 1 година
родитељ
комит
d53904a370
2 измењених фајлова са 18 додато и 7 уклоњено
  1. 3 3
      mod/disk/raid/handler.go
  2. 15 4
      mod/disk/raid/raiddetails.go

+ 3 - 3
mod/disk/raid/handler.go

@@ -40,9 +40,9 @@ func (m *Manager) HandleLoadArrayDetail(w http.ResponseWriter, r *http.Request)
 		devName = "/dev/" + devName
 	}
 
-	//Check if it exists
-	if !m.RAIDDeviceExists(devName) {
-		utils.SendErrorResponse(w, "RAID device not exists")
+	//Check device exists
+	if !utils.FileExists(devName) {
+		utils.SendErrorResponse(w, "target device not exists")
 		return
 	}
 

+ 15 - 4
mod/disk/raid/raiddetails.go

@@ -85,7 +85,7 @@ func parseRAIDInfo(output string) *RAIDInfo {
 				updateTime, _ := time.Parse(time.ANSIC, updateTimeStr)
 				raidInfo.UpdateTime = updateTime
 			case "State":
-				raidInfo.State = fields[2]
+				raidInfo.State = strings.Join(fields[2:], " ")
 			case "Active":
 				raidInfo.ActiveDevices, _ = strconv.Atoi(fields[3])
 			case "Working":
@@ -103,10 +103,21 @@ func parseRAIDInfo(output string) *RAIDInfo {
 			case "Events":
 				raidInfo.Events, _ = strconv.Atoi(fields[2])
 			default:
-				if len(fields) >= 6 && fields[0] != "Number" {
+				if len(fields) >= 5 && fields[0] != "Number" {
 					deviceInfo := DeviceInfo{}
-					deviceInfo.State = fields[4 : len(fields)-1]
-					deviceInfo.DevicePath = fields[len(fields)-1]
+
+					if len(fields) > 5 {
+						//Only active disks have fields > 5, e.g.
+						// 0       8       16        0      active sync   /dev/sdb
+						deviceInfo.State = fields[4 : len(fields)-1]
+						deviceInfo.DevicePath = fields[len(fields)-1]
+					} else {
+						//Failed disk, e.g.
+						//  -       0        0        1      removed
+						deviceInfo.State = fields[4:]
+						//TODO: Add custom tags
+					}
+
 					raidInfo.DeviceInfo = append(raidInfo.DeviceInfo, deviceInfo)
 				}
 			}