Skip to content

Instantly share code, notes, and snippets.

@naa0yama
Last active October 25, 2024 09:59
Show Gist options
  • Save naa0yama/dc7dd728af7d6e3f9e0ed837329a7dfc to your computer and use it in GitHub Desktop.
Save naa0yama/dc7dd728af7d6e3f9e0ed837329a7dfc to your computer and use it in GitHub Desktop.
show tech-support command for Promox VE.
#!/usr/bin/env bash
set -eu
# ==============================================================================
# =
# = Proxmox VE configuration dump
# = License: AGPL 3.0
# = Gist: https://gist.github.com/naa0yama/dc7dd728af7d6e3f9e0ed837329a7dfc
# =
# = download command
# = curl -fSL -O https://gist.githubusercontent.com/naa0yama/dc7dd728af7d6e3f9e0ed837329a7dfc/raw/pve-config-dump.sh
# =
# = How to use
# = > bash pve-config-dump.sh
# = > bash pve-config-dump.sh dumps/main.txt # Compare main.txt with latest txt
# =
# = Required as a dependency
# = > apt -y install jq lshw
# ==============================================================================
paths=(
"/etc/network/interfaces"
"/etc/network/interfaces.d/sdn"
"/proc/net/bonding/"
"/etc/pve/sdn/*.cfg"
"/etc/frr/frr.conf"
"/etc/frr/frr.conf.local"
"/etc/sysctl.conf"
"/etc/sysctl.d/*.conf"
"/etc/pve/*.cfg"
"/etc/pve/firewall/*"
"/etc/pve/ha/*"
"/etc/apt/sources.list"
"/etc/apt/sources.list.d/*"
"/etc/hosts"
)
outputdir="dumps"
hostname="$(hostnamectl hostname)"
mkdir -p "${outputdir}"
newfile="${outputdir}/${hostname}_$(date -u '+%Y-%m-%dT%H%M%S%Z').txt"
oldfile=$(find "${outputdir}/" -name '*.txt' -type f -printf '%T@ %p\n' | sort -n | tail -1 | cut -d' ' -f2-)
output=""
output+=$(printf '#%.0s' {1..80})
output+="\n#\n"
output+="# Hostname: ${hostname}\n"
output+="# dumpname: ${newfile}\n"
output+="#\n\n"
for command in "apt-cache" "cat" "diff" "find" "grep" "ip" "jq" "less" "lshw" "pve-firewall" "pveversion"
do
type -p "${command}"
done
set +u
if [ -n "${1}" ]; then
oldfile="${1}"
fi
set -u
# - ----------------------------------------------------------------------------
# - collecting command
# - ----------------------------------------------------------------------------
for path in "${paths[@]}"; do
for file in $path; do
if [ -f "${file}" ]; then
echo -e "collecting file...\t\t${file}"
output+=$(printf '#%.0s' {1..80})
output+="\n#\n"
output+="# filename ${file}\n"
output+="#\n\n"
if [ "${file%/*}" == "/etc/sysctl.d" ] || [ "${file}" == "/etc/sysctl.conf" ]; then
set +e
output+=$(grep -v -E '^$|^#' "${file}")
set -e
else
output+=$(cat "${file}")
fi
output+="\n\n"
fi
done
done
# - ----------------------------------------------------------------------------
# - collecting command
# - ----------------------------------------------------------------------------
for command in "pve-firewall status" \
"pve-firewall localnet" \
"ip address show" \
"ip route" \
"ip neighbor" \
"apt-cache policy" \
"pveversion --verbose" \
"lshw -class network -short" \
"lshw -class network -json"
do
echo -e "collecting command...\t\t${command}"
output+=$(printf '#%.0s' {1..80})
output+="\n#\n"
output+="# ${command}\n"
output+="#\n\n"
output+=$(${command})
output+="\n\n"
done
# - ----------------------------------------------------------------------------
# - collecting vtysh command
# - ----------------------------------------------------------------------------
command=("show version" "show interface brief")
## logical
interfaces=$(lshw -class network -json | jq -r '.[] | select(.description | contains("Ethernet interface")) | .logicalname' | sort)
for interface in $interfaces; do
command+=("show interface ${interface}")
done
## virtual
while IFS= read -r -d '' interface
do
command+=("show interface ${interface##*/}")
done < <(find /sys/devices/virtual/net/ -maxdepth 1 -type d -not -name 'fw*' -and -not -name 'net' -print0)
command+=("show ip route" \
"show ip route bgp" \
"show ip bgp" \
"show ip bgp summary" \
"show ip bgp l2vpn evpn" \
"show evpn vni" \
"show evpn arp-cache vni all" \
"show evpn mac vni all" \
"show evpn vni detail")
set +e
_vtysh=$(type -p vtysh)
set -e
if [ "${_vtysh##*/}" == "vtysh" ]; then
for command in "${command[@]}"
do
echo -e "collecting vtysh command...\t${command}"
output+=$(printf '#%.0s' {1..80})
output+="\n#\n"
output+="# vtysh -c ${command}\n"
output+="#\n\n"
output+=$(vtysh -c "${command}")
output+="\n\n"
done
fi
echo -e "${output}" > "${newfile}"
echo "Configuration dump saved to ${newfile}"
set -x
diff --side-by-side --width "$(tput cols)" "${oldfile}" "${newfile}" | less -R
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment