Last active
May 10, 2023 20:46
-
-
Save Oats87/e015bc46d2bff45956d426a5445c7a24 to your computer and use it in GitHub Desktop.
This is a WIP attempt to write a parsing file that can take the drone logs download of a provisioning-tests failure and spit out the information in an easy-to-digest format.
This file contains 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/sh | |
FILE=$1 | |
if [ -z "${FILE}" ]; then | |
echo "A file must be specified" | |
exit 1 | |
fi | |
BLOB=$(cat ${FILE} | grep -A 1 "wait failed on" | grep -v "wait failed on") | |
if [ $? != 0 ]; then | |
echo "Unable to parse the input file" | |
exit 1 | |
fi | |
if [ "${BLOB}" = "" ]; then | |
echo "log content was not found" | |
exit 1 | |
fi | |
PARSED_DIR=${FILE}-parsed | |
mkdir -p ${PARSED_DIR}/source | |
cp ${FILE} ${PARSED_DIR}/source | |
cp $0 ${PARSED_DIR}/source | |
for object in cluster rkecontrolplane mgmtCluster capiCluster infraCluster | |
do | |
echo "${BLOB}" | base64 --decode | gzip -d | jq -r .${object} | yq -P > ${PARSED_DIR}/${object}.yaml | |
done | |
for object in machineDeployments machineSets machines rkeBootstraps rkeBootstrapTemplates infraMachines; do | |
mkdir -p ${PARSED_DIR}/${object} | |
obj=$(echo "${BLOB}" | base64 --decode | gzip -d | jq -c ".${object}.items" 2>/dev/null) | |
if [ $? != 0 ] || [ -z "${obj}" ] || [ "${obj}" == "[]" ]; then | |
continue | |
fi | |
items=$(echo "${obj}" | jq -c '. | keys[] as $k | {key: $k, item: .[$k] | @base64}'); | |
for o in ${items}; do | |
item=$(echo $o | jq -r '.item | @base64d') | |
name=$(echo $item | jq -r .metadata.name) | |
echo $o | jq -r '.item | @base64d' | yq -P > ${PARSED_DIR}/${object}/${name}.yaml | |
done | |
done | |
for i in $(echo "${BLOB}" | base64 --decode | gzip -d | jq -c '.podLogs | keys[] as $k | {key: $k, logs: .[$k]}'); do | |
POD=$(echo $i | jq -r .key) | |
mkdir -p ${PARSED_DIR}/logs/${POD} | |
KL=$(echo $i | jq -r .logs.kubeletLogs) | |
if [ "${KL}" != "null" ]; then | |
echo $KL | base64 --decode | gzip -d | sed -e 's/SnewlineG/\n/g' > ${PARSED_DIR}/logs/${POD}/kubelet.log | |
fi | |
echo $i | jq -r .logs.logs | base64 --decode | gzip -d | sed -e 's/SnewlineG/\n/g' > ${PARSED_DIR}/logs/${POD}/pod.log | |
echo $i | jq -r .logs.logs | base64 --decode | gzip -d | sed -e 's/SnewlineG/\n/g' | grep "rke2\[" > ${PARSED_DIR}/logs/${POD}/rke2.log | |
echo $i | jq -r .logs.logs | base64 --decode | gzip -d | sed -e 's/SnewlineG/\n/g' | grep "k3s\[" > ${PARSED_DIR}/logs/${POD}/k3s.log | |
echo $i | jq -r .logs.logs | base64 --decode | gzip -d | sed -e 's/SnewlineG/\n/g' | grep "rancher-system-agent\[" > ${PARSED_DIR}/logs/${POD}/rancher-system-agent.log | |
done | |
RL=$(cat ${FILE} | grep "RANCHER-LOG-DUMP-START" -A 1 | grep -v "RANCHER-LOG-DUMP-START") | |
if [ $? = 0 ]; then | |
echo $RL | base64 --decode | gzip -d > ${PARSED_DIR}/logs/rancher.log | |
fi | |
K3SL=$(cat ${FILE} | grep "K3S-LOG-DUMP-START" -A 1 | grep -v "K3S-LOG-DUMP-START") | |
if [ $? = 0 ]; then | |
echo $K3SL | base64 --decode | gzip -d > ${PARSED_DIR}/logs/k3s-local.log | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment