Created
February 17, 2026 20:56
-
-
Save bentito/2f5b07cf6f95cc5eec519356439b6f12 to your computer and use it in GitHub Desktop.
sosreport gathering automation (NIDS focus)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # Configuration | |
| OUTPUT_DIR="./sos-diagnostics" | |
| IMAGE="registry.redhat.io/rhel9/support-tools:latest" | |
| NAMESPACE="default" | |
| mkdir -p "$OUTPUT_DIR" | |
| TIMESTAMP=$(date +%Y%m%d-%H%M) | |
| echo "--- OpenShift NIDS SOS Report Generator (Final Fix) ---" | |
| # Target Worker Nodes | |
| NODES=$(oc get nodes -l node-role.kubernetes.io/worker -o jsonpath='{.items[*].metadata.name}') | |
| IFS=' ' read -r -a NODE_ARRAY <<< "$NODES" | |
| for NODE in "${NODE_ARRAY[@]}"; do | |
| echo "================================================================" | |
| echo "Node: $NODE" | |
| # 1. CLEANUP | |
| echo " > Cleaning up previous sessions..." | |
| oc debug node/"$NODE" -n "$NAMESPACE" --quiet=true -- \ | |
| chroot /host podman rm -f sos-collector > /dev/null 2>&1 | |
| # 2. RUN SOS REPORT | |
| echo " > Starting SOS collection (Streaming logs)..." | |
| oc debug node/"$NODE" -n "$NAMESPACE" -- \ | |
| chroot /host /bin/bash -c " | |
| if ! podman image exists $IMAGE; then | |
| echo ' ! Image not found locally. Attempting pull...' | |
| podman pull $IMAGE | |
| fi | |
| podman run --name sos-collector \ | |
| --privileged \ | |
| --ipc=host \ | |
| --net=host \ | |
| --pid=host \ | |
| -e HOST=/host \ | |
| -v /:/host \ | |
| -v /var/log:/var/log \ | |
| -v /run:/run \ | |
| -v /var/tmp:/var/tmp \ | |
| $IMAGE \ | |
| sos report --batch \ | |
| --sysroot /host \ | |
| --tmp-dir /var/tmp \ | |
| --name $NODE-$TIMESTAMP \ | |
| --all-logs \ | |
| -o openshift,openshift_ovn,openvswitch,networking,crio,podman \ | |
| -k crio.all=on -k crio.logs=on \ | |
| --plugin-timeout=300 | |
| " | |
| # 3. CHECK & RETRIEVE (FIXED) | |
| echo " > Checking for report..." | |
| # FIX: We list ALL sosreports sorted by time (newest first) and grab the top one. | |
| # We no longer match on the exact filename string because sos prepends hostnames. | |
| FILE_PATH=$(oc debug node/"$NODE" -n "$NAMESPACE" -- \ | |
| chroot /host sh -c "ls -t /var/tmp/sosreport*.tar.xz 2>/dev/null | head -n 1") | |
| CLEAN_PATH=$(echo "$FILE_PATH" | grep -o "/var/tmp/sosreport.*.tar.xz") | |
| if [ -n "$CLEAN_PATH" ]; then | |
| FILENAME=$(basename "$CLEAN_PATH") | |
| echo " > Found: $FILENAME" | |
| echo " > Downloading..." | |
| oc debug node/"$NODE" -n "$NAMESPACE" -- \ | |
| chroot /host cat "$CLEAN_PATH" > "$OUTPUT_DIR/$FILENAME" | |
| if [ -s "$OUTPUT_DIR/$FILENAME" ]; then | |
| echo " > SUCCESS: Saved to $OUTPUT_DIR/$FILENAME" | |
| # Cleanup remote file | |
| oc debug node/"$NODE" -n "$NAMESPACE" -- chroot /host rm -f "$CLEAN_PATH" > /dev/null 2>&1 | |
| else | |
| echo " ! ERROR: File downloaded but is 0 bytes." | |
| fi | |
| else | |
| echo " ! ERROR: No sosreport found in /var/tmp/." | |
| fi | |
| # Final Cleanup | |
| oc debug node/"$NODE" -n "$NAMESPACE" --quiet=true -- \ | |
| chroot /host podman rm -f sos-collector > /dev/null 2>&1 | |
| done | |
| echo "================================================================" |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
A haproxy-gather.sh for MacOS: