First completely working version
This commit is contained in:
parent
b414e81081
commit
427fb181d1
@ -261,24 +261,19 @@ check_dunst_id_is_visible () {
|
||||
}
|
||||
|
||||
local current_alarm=""
|
||||
local last_alarm=""
|
||||
typeset -A notice_sent
|
||||
typeset -A secs
|
||||
integer last_dunst_id=-1
|
||||
local last_line=""
|
||||
|
||||
set -x
|
||||
#set -x
|
||||
while true; do
|
||||
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 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 ))
|
||||
if [[ "${last_line}" == "${line}" ]]; then
|
||||
# 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
|
||||
@ -296,20 +291,21 @@ while true; do
|
||||
sleep 1
|
||||
continue
|
||||
fi
|
||||
|
||||
sleep 1
|
||||
continue
|
||||
fi
|
||||
last_line="${line}"
|
||||
local psi_type="$(grep -Eo "(CPU|MEM|IO) PSI event" <<< "${line}" | grep -Eo "CPU|MEM|IO")"
|
||||
if [[ -n "${psi_type}" ]]; then
|
||||
secs+=(${psi_type} ${now})
|
||||
if [[ "${psi_type}" != "${last_alarm}" ]]; then
|
||||
if [[ ! ${notice_sent[${psi_type}]} ]]; then
|
||||
last_dunst_id=$(exec_notices "${psi_type}" "${current_alarms}")
|
||||
notice_sent+=(${psi_type} true)
|
||||
elif (( last_dunst_id >= 0 )) && check_dunst_id_is_visible "${last_dunst_id}"; then
|
||||
last_alarm="${psi_type}"
|
||||
sleep 1
|
||||
continue
|
||||
fi
|
||||
fi
|
||||
last_alarm="${psi_type}"
|
||||
if [[ -z "${current_alarms}" ]]; then
|
||||
current_alarms="${psi_type}"
|
||||
else
|
||||
@ -320,5 +316,5 @@ while true; do
|
||||
fi
|
||||
sleep 1
|
||||
done
|
||||
set +x
|
||||
#set +x
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user