From 418d4d41706b50baa845a59d4cd580c98fa96fcf Mon Sep 17 00:00:00 2001 From: Jared Vititoe Date: Tue, 6 Jan 2026 16:30:21 -0500 Subject: [PATCH] Fix Ceph OSD status parsing to correctly read up/down and in/out MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- driveAtlas.sh | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) 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="-"