bmc-debug-tools/logs.inc

116 lines
2.2 KiB
Bash

#!/usr/bin/env bash
#
# KGPE-D16 firmware boot process debugging tools via BMC
#
# Desc: log management
#
# Copyright (C) 2024 Adrien 'neox' Bourmault <neox@gnu.org>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
source ssh.inc
# colors
black='\033[0;30m'
red='\033[0;31m'
green='\033[0;32m'
yellow='\033[0;33m'
blue='\033[0;34m'
magenta='\033[0;35m'
cyan='\033[0;36m'
white='\033[0;37m'
lightgrey='\033[1;30m'
lightred='\033[1;31m'
lightgreen='\033[1;32m'
lightyellow='\033[1;33m'
lightblue='\033[1;34m'
lightmagenta='\033[1;35m'
lightcyan='\033[1;36m'
lightwhite='\033[1;37m'
color_reset='\033[0m'
get_logs()
{
ssh_bmc /usr/bin/microcom /dev/ttyS0 -s 115200
}
stop_logs()
{
ssh_bmc killall microcom
}
start_logs()
{
get_logs > ${1} &
}
check_logs_still_on()
{
if [ $(ssh_bmc top -n 1 | grep microcom | wc -l) -ge 1 ]; then
echo Stopping logs before starting...
stop_logs
fi
}
find_in_logs()
{
keyword=$1
while IFS= read -r line
do
echo "$line" | grep "$keyword" &> /dev/null
if [ $? -eq 0 ]; then
echo -e "${lightgreen}Found : ${line}${color_reset}"
break
fi
done
}
find_print_and_do()
{
keyword=${1}
while IFS= read -r line
do
echo "$line" | grep "$keyword" &> /dev/null
if [ $? -eq 0 ]; then
echo -e "${2}${4} : ${line}${color_reset}"
${3}
fi
done
}
wait_for()
{
tail -F ${1} | find_in_logs ${2}
}
react_to_info()
{
tail -F ${1} | find_print_and_do ${3} ${cyan} ${2} INFO
}
react_to_warn()
{
tail -F ${1} | find_print_and_do ${3} ${yellow} ${2} WARN
}
react_to_err()
{
tail -F ${1} | find_print_and_do ${3} ${red} ${2} ERR
}
react_to_critical()
{
tail -F ${1} | find_print_and_do ${3} ${lightred} ${2} CRIT
}