This repository has been archived on 2024-12-17. You can view files and clone it, but cannot push or open issues or pull requests.
get-all-logs/get-all-logs.sh

244 lines
8.2 KiB
Bash
Raw Normal View History

2023-02-17 02:09:28 +08:00
#!/bin/bash
PRMT="[$(whoami)@$(hostname -s) ]"
about_platform(){
for ONE in vm dci;
do
test -d /opt/ispsystem/${ONE} && PLATFORM=${ONE};
done
if [[ -z "${PLATFORM}" ]]; then
echo "No ISPsystem Software found" && exit;
else
LOGDIR="${HOME}/${PLATFORM}_${type_log}_$(date +"%Y_%m_%d_%H_%M_%S")" && mkdir -p ${LOGDIR}
ARCNAME=$(date +"${HOME}/${PLATFORM}_${type_log}_%Y_%m_%d_%H_%M_%S.tar.gz")
2023-02-22 01:58:55 +08:00
LicenseToken=$(grep -oP '\"LicenseToken\":"[^"]*\"' /opt/ispsystem/${PLATFORM}/config.json | sed -e 's/\"LicenseToken\"://g' -e 's/\"//g')
CurrentVersion=$(grep -oP '\"CurrentVersion\":"[^"]*\"' /opt/ispsystem/${PLATFORM}/config.json | sed -e 's/\"CurrentVersion\"://g' -e 's/\"//g')
Stage=$(grep -oP '\"Stage\":"[^"]*\"' /opt/ispsystem/${PLATFORM}/config.json | sed -e 's/\"Stage\"://g' -e 's/\"//g')
DomainName=$(grep -oP '\"DomainName\":"[^"]*\"' /opt/ispsystem/${PLATFORM}/config.json | sed -e 's/\"DomainName\"://g' -e 's/\"//g')
2023-02-17 02:09:28 +08:00
cp /opt/ispsystem/${PLATFORM}/config.json ${LOGDIR}
cp /opt/ispsystem/${PLATFORM}/install.log ${LOGDIR}
cp /opt/ispsystem/${PLATFORM}/docker-compose.yaml ${LOGDIR}
fi;
}
newlog() {
LOGINFO=${LOGDIR}/$1 && date > ${LOGINFO}
}
cmdlog() {
test -z "${LOGINFO}" && return
local CMD=$*;(echo "${PRMT} ${CMD}";echo;eval ${CMD};echo) >> ${LOGINFO}
}
about_server() {
newlog hostinfo_$(hostname).log
echo "log $LOGINFO"
cmdlog hostnamectl
cmdlog cat /etc/*release
cmdlog lscpu
cmdlog timedatectl
cmdlog free -m
cmdlog df -h --exclude tmpfs --exclude devtmpfs --exclude squashfs --exclude overlay
cmdlog ip -br a
}
about_docker(){
newlog docker_$(hostname).log
cmdlog docker version
cmdlog docker ps
cmdlog "docker inspect --format ' {{.Name}} - {{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $(docker ps -aq)"
}
plaform_logs(){
DOCKER_CONTAINER_NAMES=`docker ps --format '{{.Names}}'`
SERVICES=($DOCKER_CONTAINER_NAMES)
cd ${LOGDIR}
for service in ${SERVICES[@]}
do
echo -e "----\033[0;31mCopying logs from $service\033[0m----\n"
mkdir -p $service
docker cp $service:/var/log/. $service/.
docker logs $service > $service/${service}_stdout.log 2>&1
done
}
about_license(){
curl -vvv -k "https://license6.ispsystem.com/lic6/check" -H "X-auth-token:$LicenseToken" > ${LOGDIR}/license_${PLATFORM}.log 2>&1
echo -e "\n${PLATFORM} Version:$CurrentVersion\n" >>${LOGDIR}/license_${PLATFORM}.log;
echo "${PLATFORM} LicenseToken:$LicenseToken" >>${LOGDIR}/license_${PLATFORM}.log;
echo "${PLATFORM} Stage:$Stage" >>${LOGDIR}/license_${PLATFORM}.log;
echo "${PLATFORM} DomainName:$DomainName" >>${LOGDIR}/license_${PLATFORM}.log;
auth_back_dir="${LOGDIR}/${PLATFORM}_auth_back_1" && mkdir -p ${auth_back_dir}
input_dir="${LOGDIR}/${PLATFORM}_input_1" && mkdir -p ${input_dir}
docker cp ${PLATFORM}_auth_back_1:/var/log/. ${auth_back_dir}
docker cp ${PLATFORM}_input_1:/var/log/nginx/. ${input_dir}
}
finish() {
tar -cvzf ${ARCNAME} -C ${LOGDIR} .
echo -e "\nISPsystem Software found:\n";
echo "${PLATFORM} DomainName:$DomainName";
echo "${PLATFORM} LicenseToken=$LicenseToken"
echo "${PLATFORM} CurrentVersion=$CurrentVersion"
echo "${PLATFORM} Stage=$Stage"
echo -e "\ndirectory with logs $LOGDIR\n"
echo -e "Please send this logs archive to ISP system support\n"
du -h ${ARCNAME}
}
2023-02-17 03:41:05 +08:00
mysql_connect(){
logfile=$1;
query=$2;
fullcmd="docker exec -it mysql bash -c \"mysql isp -p\\\$MYSQL_ROOT_PASSWORD -e "$query"\" >> ${LOGDIR}/$logfile";
#./1.sh "'select id,name,node from vm_host;'"
#q=$1;
#func(){
#query=$1;
#eval "docker exec -it mysql bash -c \"mysql isp -p\\\$MYSQL_ROOT_PASSWORD -e "$query"\"";
#}
#func "$q";
echo $fullcmd;
echo -e "\n $cmd \n">> ${LOGDIR}/$logfile;
eval $fullcmd;
}
2023-02-17 02:09:28 +08:00
node_connect() {
ip_addr=$1;
ssh_port=$2;
cmd=$4;
logfile=$3;
fullcmd="docker exec --tty --interactive vm_box ssh -o \"StrictHostKeyChecking no\" -i /opt/ispsystem/vm/etc/.ssh/vmmgr.1 $ip_addr -p $ssh_port $cmd >> ${LOGDIR}/$logfile";
echo $fullcmd;
echo -e "\n $cmd \n">> ${LOGDIR}/$logfile;
eval $fullcmd;
}
_help(){
cat <<- EOF
============================================
Usage : get-all-logs -type
available types:
-logs or 1
-short-logs or 2
-lic or 3
-node or 4 <IP-address> <SSH-port>
=============================================
EOF
}
_logs() {
about_server;
about_docker;
about_license;
plaform_logs;
finish;
}
_short_logs() {
about_server;
about_docker;
about_license;
plaform_logs;
find ${LOGDIR} -type f -mtime +7 -delete;
finish;
}
_lic() {
about_server;
about_docker;
about_license;
finish;
}
_vm_host() {
echo $type_log;
echo "it's coming soon!";
2023-02-22 01:58:55 +08:00
vm_name=$1;
vm_id=$2;
2023-02-17 02:09:28 +08:00
}
_node() {
node_ip=$1;
node_port=$2;
2023-02-17 03:41:05 +08:00
mysql_connect "${node_ip}_db.log" "'select id,name from vm_node where ip_addr=\\\"$node_ip\\\";'"
2023-02-17 02:09:28 +08:00
node_connect $node_ip $node_port "${node_ip}_hostnamectl.log" "hostnamectl";
node_connect $node_ip $node_port "${node_ip}_release.log" "\"cat /etc/*release\"";
node_connect $node_ip $node_port "${node_ip}_dmesg.log" "\"dmesg | grep -i -E 'error|failed|critical|bug|panic'\"";
node_connect $node_ip $node_port "${node_ip}_services.log" "\"journalctl | grep -i -E 'error|failed|critical|bug|panic'\"";
node_connect $node_ip $node_port "${node_ip}_services.log" "\"systemctl status libvirtd -l\"";
node_connect $node_ip $node_port "${node_ip}_services.log" "\"systemctl show libvirtd\"";
node_connect $node_ip $node_port "${node_ip}_sshd_config" "\"cat /etc/ssh/sshd_config\"";
node_connect $node_ip $node_port "${node_ip}_hwinfo.log" "lscpu";
node_connect $node_ip $node_port "${node_ip}_hwinfo.log" "lscpu | grep -i -E 'socket|core|thread'";
node_connect $node_ip $node_port "${node_ip}_hwinfo.log" "dmidecode";
node_connect $node_ip $node_port "${node_ip}_time.log" "timedatectl";
node_connect $node_ip $node_port "${node_ip}_time.log" "uptime";
node_connect $node_ip $node_port "${node_ip}_time.log" "\"last reboot | head -10\"";
node_connect $node_ip $node_port "${node_ip}_virsh.log" "\"virsh list --all\"";
node_connect $node_ip $node_port "${node_ip}_virsh.log" "\"virsh pool-list --all\"";
node_connect $node_ip $node_port "${node_ip}_virsh.log" "\"virt-host-validate\"";
node_connect $node_ip $node_port "${node_ip}_mem.log" "\"free -m\"";
node_connect $node_ip $node_port "${node_ip}_network.log" "\"ip -br a\"";
node_connect $node_ip $node_port "${node_ip}_network.log" "\"brctl show\"";
node_connect $node_ip $node_port "${node_ip}_network.log" "\"curl -v download.ispsystem.com\"";
node_connect $node_ip $node_port "${node_ip}_firewall.log" "\"systemctl status nftables\"";
node_connect $node_ip $node_port "${node_ip}_firewall.log" "\"systemctl status firewalld\"";
node_connect $node_ip $node_port "${node_ip}_firewall.log" "\"firewall-cmd --list-ports\"";
node_connect $node_ip $node_port "${node_ip}_firewall.log" "\"nft list ruleset\"";
node_connect $node_ip $node_port "${node_ip}_firewall.log" "\"ss -tulpn | grep 16514\"";
node_connect $node_ip $node_port "${node_ip}_firewall.log" "\"ss -tulpn '( sport >= 49152 and sport <= 49215 )'\"";
node_connect $node_ip $node_port "${node_ip}_firewall.log" "\"ss -tulpn '( sport >= 5900 and sport <= 6900 )'\"";
node_connect $node_ip $node_port "${node_ip}_firewall.log" "\"ss -tulpn '( sport = 179 or sport = 4789 )'\"";
node_connect $node_ip $node_port "${node_ip}_firewall.log" "\"ss -tulpn | grep 16514\"";
node_connect $node_ip $node_port "${node_ip}_firewall.log" "\"ss -tulpn | grep -E ':179|:4789'\"";
node_connect $node_ip $node_port "${node_ip}_disks.log" "\"df -h --exclude tmpfs --exclude devtmpfs --exclude squashfs --exclude overlay\"";
node_connect $node_ip $node_port "${node_ip}_disks.log" "\"df -i\"";
node_connect $node_ip $node_port "${node_ip}_disks.log" "lsblk";
finish;
}
if [[ "$1" == "-logs" || "$1" == "1" ]]; then
type_log="logs";
about_platform;
_logs;
elif [[ "$1" == "-short-logs" || "$1" == "2" ]]; then
type_log="short-logs";
about_platform;
_short_logs;
elif [[ "$1" == "-lic" || "$1" == "3" ]]; then
type_log="lic";
about_platform;
_lic;
elif [[ "$1" == "-node" || "$1" == "4" ]]; then
type_log="node";
about_platform;
if [[ -z $2 || -z $3 ]]; then
echo "please set IP address and port of node!";
exit;
else
_node $2 $3;
fi
elif [[ "$1" == "-vm-host" || "$1" == "5" ]]; then
type_log="vm-host";
about_platform;
_vm_host;
else
_help;
fi