diff --git a/get-all-logs.sh b/get-all-logs.sh index 1d6af76..051d286 100755 --- a/get-all-logs.sh +++ b/get-all-logs.sh @@ -1,11 +1,12 @@ #!/bin/bash -version="23/02/23" -echo "get-all-logs $version" PRMT="[$(whoami)@$(hostname -s) ]" about_platform(){ +if [[ -z $logtype ]];then + logtype=$1; +fi; for ONE in vm dci; do @@ -15,8 +16,10 @@ done if [[ -z "${PLATFORM}" ]]; then echo "No ISPsystem Software found" && exit; else - LOGDIR="${HOME}/${PLATFORM}_logs_$(date +"%Y_%m_%d_%H_%M_%S")" && mkdir -p ${LOGDIR} - ARCNAME=$(date +"${HOME}/${PLATFORM}_logs_%Y_%m_%d_%H_%M_%S.tar.gz") +# echo "${HOME}/${PLATFORM}_${logtype}_$(date +"%Y_%m_%d_%H_%M_%S")"; + LOGDIR="${HOME}/${PLATFORM}_${logtype}_$(date +"%Y_%m_%d_%H_%M_%S")" && mkdir -p ${LOGDIR} +# LOGDIR="${HOME}/${PLATFORM}_logs_$(date +"%Y_%m_%d_%H_%M_%S")" && mkdir -p ${LOGDIR} + ARCNAME=$(date +"${HOME}/${PLATFORM}_${logtype}_%Y_%m_%d_%H_%M_%S.tar.gz") 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') @@ -102,16 +105,8 @@ mysql_connect(){ 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; + echo -e "\n exec $query \n">> ${LOGDIR}/$logfile; eval $fullcmd; } @@ -121,53 +116,60 @@ node_connect() { ssh_port=$2; cmd=$4; logfile=$3; - testcmd="docker exec --tty --interactive vm_box ssh -o BatchMode=yes -o ConnectTimeout=5 -o \"StrictHostKeyChecking no\" -i /opt/ispsystem/vm/etc/.ssh/vmmgr.1 $ip_addr -p $ssh_port echo ok 2>&1"; - echo $testcmd; - status=$(eval $testcmd); - echo $status; - - if [[ $status == "ok" ]] ; then - echo "node $ip_addr on $node_port connected!"; - 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; - elif [[ $status == "Permission denied"* ]] ; then - echo "node $ip_addr on $node_port not authorized!"; - else - echo "node $ip_addr on $node_port not connected!"; - fi + $(docker exec --tty --interactive vm_box ssh -o BatchMode=yes -o ConnectTimeout=5 -o "StrictHostKeyChecking no" -q -i /opt/ispsystem/vm/etc/.ssh/vmmgr.1 $ip_addr -p $ssh_port exit) && connected=1 || connected=0; + if [[ ${connected} == 1 ]];then +# echo "node $ip_addr on $node_port connected!"; + 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; + else + echo "node $ip_addr on $node_port not connected!"; + echo "node $ip_addr on $node_port not connected!">> ${LOGDIR}/$logfile; + echo -e "\n not executed $cmd \n">> ${LOGDIR}/$logfile; + fi } _help(){ -echo -e "Usage : $0 -type"; -echo -e "\n available types:\n\n"; -echo -e "-logs or 1"; -echo -e "-short-logs or 2"; -echo -e "-lic or 3"; -echo -e "-node or 4 \ \"; + +version="23/02/23" + +echo -e "Log's script ver.: $version Usage : $0 [arguments]"; +echo -e "\n arguments:\n"; +echo -e " -logs or 1"; +echo -e " -short-logs or 2"; +echo -e " -lic or 3"; +echo -e " -node or 4 \n"; PS3='Please enter your choice(enter number): ' -options=("Full logs" "Short logs" "License\'s logs" "Node\'s logs" "Quit") +options=("Full logs" "Short logs" "License's logs" "Node's logs" "Quit") select opt in "${options[@]}" do case $opt in "Full logs") + logtype="logs"; + about_platform; _logs; break; ;; "Short logs") + logtype="short-logs"; + about_platform; _short_logs; break; ;; - "License\'s logs") + "License's logs") + logtype="lic"; + about_platform; _lic; break; ;; - "Node\'s logs") + "Node's logs") + logtype="node"; read -p "Enter IP address: " node_ip read -p "Enter port: " node_port + about_platform; _node $node_ip $node_port; break; ;; @@ -205,7 +207,6 @@ _lic() { } _vm_host() { - echo $type_log; echo "it's coming soon!"; vm_name=$1; vm_id=$2; @@ -214,14 +215,14 @@ _vm_host() { _node() { node_ip=$1; node_port=$2; - mysql_connect "${node_ip}_db.log" "'select id,name from vm_node where ip_addr=\\\"$node_ip\\\";'" + mysql_connect "${node_ip}_db.log" "'select id,name,comment,cluster,ram_mib,max_vcpu_number,cpu_number,ip_addr,ssh_port,host_max_num,state,connection_error,libvirt_error,gray_ips,disk_params,property,host_creation_blocked,mon_installed,mon_install_date,metrics_timestamp,os_version,kernel_version,uptime,libvirt_version,qemu_version,overselling,hostname,vnc_addr,selinux_enforcing,problems,hdd_overselling,ip_addr_v6,bird_error,lxd_error,lxd_version,host_limit,socket_number,ha_state,ha_disable_failed,ha_error,update_dc_networks_failed,network_settings_lock,network_error,frr_error,host_filter,vm5_data,additional_data,vcpu_limit,spice_error from vm_node where ip_addr=\\\"$node_ip\\\"\\G;'" 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}_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'"; @@ -251,22 +252,33 @@ _node() { 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"; + echo "collected logs about node $node_ip $node_port"; finish; } -about_platform; - if [[ "$1" == "-logs" || "$1" == "1" ]]; then + logtype="logs"; + about_platform; _logs; elif [[ "$1" == "-short-logs" || "$1" == "2" ]]; then + logtype="short-logs"; + about_platform; _short_logs; elif [[ "$1" == "-lic" || "$1" == "3" ]]; then + logtype="lic"; + about_platform; _lic; elif [[ "$1" == "-node" || "$1" == "4" ]]; then + logtype="node"; if [[ -z $2 || -z $3 ]]; then echo "please set IP address and port of node!"; + read -p "Enter IP address: " node_ip + read -p "Enter port: " node_port + about_platform; + _node $node_ip $node_port; exit; else + about_platform; _node $2 $3; fi #elif [[ "$1" == "-vm-host" || "$1" == "5" ]]; then