First completely working version

This commit is contained in:
Trey Blancher 2023-08-25 17:35:58 -04:00
parent b414e81081
commit 427fb181d1

View File

@ -261,24 +261,19 @@ check_dunst_id_is_visible () {
} }
local current_alarm="" local current_alarm=""
local last_alarm=""
typeset -A notice_sent typeset -A notice_sent
typeset -A secs typeset -A secs
integer last_dunst_id=-1 integer last_dunst_id=-1
local last_line="" local last_line=""
set -x #set -x
while true; do while true; do
local line=$(journalctl -u ${svc} -n1) local line=$(journalctl -u ${svc} -n1)
if [[ "${last_line}" == "${line}" ]]; then
# line hasn't changed since last run, do nothing
sleep 1
continue
fi
last_line="${line}"
local now=$(date +%s) local now=$(date +%s)
local last_timestamp=$(date -d $(awk '{print $1" "$2" "$3}' <<< "${line}") +%s) local last_timestamp=$(date -d "$(awk '{print $1" "$2" "$3}' <<< "${line}")" +%s)
local time_diff=$(( now - last_timestamp )) local time_diff=$(( now - last_timestamp ))
if [[ "${last_line}" == "${line}" ]]; then
# last line hasn't changed, check to see if we can clear alarms
if (( time_diff >= 3 )); then if (( time_diff >= 3 )); then
# haven't seen a monitor alert for 3 seconds, see if we can clear them # haven't seen a monitor alert for 3 seconds, see if we can clear them
if [[ -n "${current_alarms}" ]]; then if [[ -n "${current_alarms}" ]]; then
@ -296,20 +291,21 @@ while true; do
sleep 1 sleep 1
continue continue
fi fi
sleep 1
continue
fi
last_line="${line}"
local psi_type="$(grep -Eo "(CPU|MEM|IO) PSI event" <<< "${line}" | grep -Eo "CPU|MEM|IO")" local psi_type="$(grep -Eo "(CPU|MEM|IO) PSI event" <<< "${line}" | grep -Eo "CPU|MEM|IO")"
if [[ -n "${psi_type}" ]]; then if [[ -n "${psi_type}" ]]; then
secs+=(${psi_type} ${now}) secs+=(${psi_type} ${now})
if [[ "${psi_type}" != "${last_alarm}" ]]; then
if [[ ! ${notice_sent[${psi_type}]} ]]; then if [[ ! ${notice_sent[${psi_type}]} ]]; then
last_dunst_id=$(exec_notices "${psi_type}" "${current_alarms}") last_dunst_id=$(exec_notices "${psi_type}" "${current_alarms}")
notice_sent+=(${psi_type} true) notice_sent+=(${psi_type} true)
elif (( last_dunst_id >= 0 )) && check_dunst_id_is_visible "${last_dunst_id}"; then elif (( last_dunst_id >= 0 )) && check_dunst_id_is_visible "${last_dunst_id}"; then
last_alarm="${psi_type}"
sleep 1 sleep 1
continue continue
fi fi
fi
last_alarm="${psi_type}"
if [[ -z "${current_alarms}" ]]; then if [[ -z "${current_alarms}" ]]; then
current_alarms="${psi_type}" current_alarms="${psi_type}"
else else
@ -320,5 +316,5 @@ while true; do
fi fi
sleep 1 sleep 1
done done
set +x #set +x