Fix Ceph OSD status parsing to correctly read up/down and in/out

Fixed parsing of ceph osd tree output:
- Column 5 is STATUS (up/down) not column 6
- Column 6 is REWEIGHT (1.0 = in, 0 = out)
- Now correctly shows up/in for active OSDs

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-01-06 16:30:21 -05:00
parent 1800b59a25
commit 418d4d4170

View File

@@ -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="-"