diff --git a/driveAtlas.sh b/driveAtlas.sh index 6ef0796..2855332 100644 --- a/driveAtlas.sh +++ b/driveAtlas.sh @@ -240,10 +240,22 @@ for bay in $(printf '%s\n' "${!DRIVE_MAP[@]}" | grep -E '^[0-9]+$' | sort -n); d if [[ -n "$osd_id" ]]; then # Get in/out and up/down status from ceph osd tree osd_num=$(echo "$osd_id" | sed 's/osd\.//') - in_status=$(ceph osd tree 2>/dev/null | grep "osd.$osd_num " | awk '{print $5}') - up_status=$(ceph osd tree 2>/dev/null | grep "osd.$osd_num " | awk '{print $6}') - [[ "$up_status" == "1" ]] && up_status="up" || up_status="down" - [[ "$in_status" == "1" ]] && in_status="in" || in_status="out" + # Parse ceph osd tree output - column 5 is STATUS (up/down), column 6 is REWEIGHT (1.0 = in, 0 = out) + tree_line=$(ceph osd tree 2>/dev/null | grep -E "^\s*${osd_num}\s+" | grep "osd.${osd_num}") + up_status=$(echo "$tree_line" | awk '{print $5}') + reweight=$(echo "$tree_line" | awk '{print $6}') + + # Default to unknown if we can't parse + [[ -z "$up_status" ]] && up_status="unknown" + [[ -z "$reweight" ]] && reweight="0" + + # Determine in/out based on reweight (1.0 = in, 0 = out) + if (( $(echo "$reweight > 0" | bc -l 2>/dev/null || echo 0) )); then + in_status="in" + else + in_status="out" + fi + ceph_status="${up_status}/${in_status}" else osd_id="-"