First completely working version
This commit is contained in:
parent
b414e81081
commit
427fb181d1
@ -261,55 +261,51 @@ 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)
|
||||||
|
local now=$(date +%s)
|
||||||
|
local last_timestamp=$(date -d "$(awk '{print $1" "$2" "$3}' <<< "${line}")" +%s)
|
||||||
|
local time_diff=$(( now - last_timestamp ))
|
||||||
if [[ "${last_line}" == "${line}" ]]; then
|
if [[ "${last_line}" == "${line}" ]]; then
|
||||||
# line hasn't changed since last run, do nothing
|
# last line hasn't changed, check to see if we can clear alarms
|
||||||
|
if (( time_diff >= 3 )); then
|
||||||
|
# haven't seen a monitor alert for 3 seconds, see if we can clear them
|
||||||
|
if [[ -n "${current_alarms}" ]]; then
|
||||||
|
typeset -a alarms=( $(tr '|' ' ' <<< "$current_alarms") )
|
||||||
|
for alarm in ${alarms}; do
|
||||||
|
integer elapsed=$(( now - ${secs[${alarm}]} ))
|
||||||
|
if is_clear "${alarm}" && (( elapsed >= 300 )); then
|
||||||
|
current_alarms=$(sed -E "s/${alarm}\|?//" <<< "${current_alarms}")
|
||||||
|
last_alarm=$(awk -F'|' '{print $NF}' <<< "${current_alarms}")
|
||||||
|
unset "notice_sent[${alarm}]"
|
||||||
|
unset "secs[${alarm}]"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
sleep 1
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
|
||||||
sleep 1
|
sleep 1
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
last_line="${line}"
|
last_line="${line}"
|
||||||
local now=$(date +%s)
|
|
||||||
local last_timestamp=$(date -d $(awk '{print $1" "$2" "$3}' <<< "${line}") +%s)
|
|
||||||
local time_diff=$(( now - last_timestamp ))
|
|
||||||
if (( time_diff >= 3 )); then
|
|
||||||
# haven't seen a monitor alert for 3 seconds, see if we can clear them
|
|
||||||
if [[ -n "${current_alarms}" ]]; then
|
|
||||||
typeset -a alarms=( $(tr '|' ' ' <<< "$current_alarms") )
|
|
||||||
for alarm in ${alarms}; do
|
|
||||||
integer elapsed=$(( now - ${secs[${alarm}]} ))
|
|
||||||
if is_clear "${alarm}" && (( elapsed >= 300 )); then
|
|
||||||
current_alarms=$(sed -E "s/${alarm}\|?//" <<< "${current_alarms}")
|
|
||||||
last_alarm=$(awk -F'|' '{print $NF}' <<< "${current_alarms}")
|
|
||||||
unset "notice_sent[${alarm}]"
|
|
||||||
unset "secs[${alarm}]"
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
fi
|
|
||||||
sleep 1
|
|
||||||
continue
|
|
||||||
fi
|
|
||||||
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
|
sleep 1
|
||||||
last_alarm="${psi_type}"
|
continue
|
||||||
sleep 1
|
|
||||||
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
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user