This commit is contained in:
xenia 2025-02-03 21:56:57 -05:00
parent 87bf9f5e0c
commit d0dfe01002
3 changed files with 23 additions and 122 deletions

View File

@ -1,4 +1,5 @@
{
lib,
fetchFromGitHub,
stdenv,
meson,

View File

@ -1,15 +1,15 @@
From 95b873fee26403dbd149e159016eb85c37c07f61 Mon Sep 17 00:00:00 2001
From 21f833bf906d07ea491d0938b716528be61ed9b6 Mon Sep 17 00:00:00 2001
From: xenia <xenia@awoo.systems>
Date: Mon, 3 Feb 2025 21:36:29 -0500
Subject: [PATCH] ZED: add support for libnotify (notify-send)
---
cmd/zed/zed.d/zed-functions.sh | 63 ++++++++++++++++++++++++++++++++++
cmd/zed/zed.d/zed.rc | 6 ++++
2 files changed, 69 insertions(+)
cmd/zed/zed.d/zed-functions.sh | 71 ++++++++++++++++++++++++++++++++++
cmd/zed/zed.d/zed.rc | 6 +++
2 files changed, 77 insertions(+)
diff --git a/cmd/zed/zed.d/zed-functions.sh b/cmd/zed/zed.d/zed-functions.sh
index 3a2519633..7a1561ee1 100644
index 3a2519633..111e477c5 100644
--- a/cmd/zed/zed.d/zed-functions.sh
+++ b/cmd/zed/zed.d/zed-functions.sh
@@ -209,6 +209,10 @@ zed_notify()
@ -23,7 +23,7 @@ index 3a2519633..7a1561ee1 100644
[ "${num_success}" -gt 0 ] && return 0
[ "${num_failure}" -gt 0 ] && return 1
return 2
@@ -624,6 +628,65 @@ zed_notify_ntfy()
@@ -624,6 +628,73 @@ zed_notify_ntfy()
}
@ -32,7 +32,7 @@ index 3a2519633..7a1561ee1 100644
+# Send a notification via libnotify <https://gitlab.gnome.org/GNOME/libnotify>.
+# The variable (ZED_USE_LIBNOTIFY) defines whether to use libnotify.
+#
+# Requires libnotify executables to be installed in the standard PATH.
+# Requires libnotify and sudo executables to be installed in the standard PATH.
+#
+# References
+# https://man.archlinux.org/man/notify-send.1.en
@ -56,6 +56,7 @@ index 3a2519633..7a1561ee1 100644
+ local msg_body
+ local msg_out
+ local msg_err
+ local exit_status=0
+
+ [ -n "${ZED_USE_LIBNOTIFY}" ] || return 2
+
@ -76,14 +77,21 @@ index 3a2519633..7a1561ee1 100644
+ subject=""
+ fi
+
+ # Send the notification and check for errors.
+ notify-send -a ZFS -u critical -i drive-harddisk-symbolic "$subject" "$msg_body"; rv=$?
+ # Send the notification to all users with a dbus session and check for errors.
+ for dir in /run/user/*; do
+ if [ -S "$dir/bus" ]; then
+ sudo -u "#$(basename $dir)" \
+ -E DBUS_SESSION_BUS_ADDRESS=unix:path=$dir/bus \
+ notify-send -a ZFS -u critical -i drive-harddisk-symbolic \
+ "$subject" "$msg_body"; rv=$?
+
+ if [ "${rv}" -ne 0 ]; then
+ zed_log_err "notify-send exit=${rv}"
+ return 1
+ fi
+ return 0
+ if [ "${rv}" -ne 0 ]; then
+ zed_log_err "notify-send exit=${rv}"
+ exit_status=1
+ fi
+ fi
+ done
+ return $exit_status
+}
+

View File

@ -1,108 +0,0 @@
From 2bcec9d74e3bf5d963ecb21bc96233e0989587dd Mon Sep 17 00:00:00 2001
From: xenia <xenia@awoo.systems>
Date: Mon, 3 Feb 2025 21:36:29 -0500
Subject: [PATCH] ZED: add support for libnotify (notify-send)
---
cmd/zed/zed.d/zed-functions.sh | 63 ++++++++++++++++++++++++++++++++++
cmd/zed/zed.d/zed.rc | 6 ++++
2 files changed, 69 insertions(+)
diff --git a/cmd/zed/zed.d/zed-functions.sh b/cmd/zed/zed.d/zed-functions.sh
index 470739d16..579600624 100644
--- a/cmd/zed/zed.d/zed-functions.sh
+++ b/cmd/zed/zed.d/zed-functions.sh
@@ -213,6 +213,10 @@ zed_notify()
[ "${rv}" -eq 0 ] && num_success=$((num_success + 1))
[ "${rv}" -eq 1 ] && num_failure=$((num_failure + 1))
+ zed_notify_libnotify "${subject}" "${pathname}"; rv=$?
+ [ "${rv}" -eq 0 ] && num_success=$((num_success + 1))
+ [ "${rv}" -eq 1 ] && num_failure=$((num_failure + 1))
+
[ "${num_success}" -gt 0 ] && return 0
[ "${num_failure}" -gt 0 ] && return 1
return 2
@@ -719,6 +723,65 @@ zed_notify_gotify()
}
+# zed_notify_libnotify (subject, pathname)
+#
+# Send a notification via libnotify <https://gitlab.gnome.org/GNOME/libnotify>.
+# The variable (ZED_USE_LIBNOTIFY) defines whether to use libnotify.
+#
+# Requires libnotify executables to be installed in the standard PATH.
+#
+# References
+# https://man.archlinux.org/man/notify-send.1.en
+#
+# Arguments
+# subject: notification subject
+# pathname: pathname containing the notification message (OPTIONAL)
+#
+# Globals
+# ZED_USE_LIBNOTIFY
+#
+# Return
+# 0: notification sent
+# 1: notification failed
+# 2: not configured
+#
+zed_notify_libnotify()
+{
+ local subject="$1"
+ local pathname="${2:-"/dev/null"}"
+ local msg_body
+ local msg_out
+ local msg_err
+
+ [ -n "${ZED_USE_LIBNOTIFY}" ] || return 2
+
+ if [ ! -r "${pathname}" ]; then
+ zed_log_err "libnotify cannot read \"${pathname}\""
+ return 1
+ fi
+
+ zed_check_cmd "notify-send" || return 1
+
+ # Read the message body in.
+ #
+ msg_body="$(cat "${pathname}")"
+
+ if [ -z "${msg_body}" ]
+ then
+ msg_body=$subject
+ subject=""
+ fi
+
+ # Send the notification and check for errors.
+ notify-send -a ZFS -u critical -i drive-harddisk-symbolic "$subject" "$msg_body"; rv=$?
+
+ if [ "${rv}" -ne 0 ]; then
+ zed_log_err "notify-send exit=${rv}"
+ return 1
+ fi
+ return 0
+}
+
# zed_rate_limit (tag, [interval])
#
diff --git a/cmd/zed/zed.d/zed.rc b/cmd/zed/zed.d/zed.rc
index af56147a9..ed71ede8c 100644
--- a/cmd/zed/zed.d/zed.rc
+++ b/cmd/zed/zed.d/zed.rc
@@ -197,3 +197,9 @@ ZED_SYSLOG_SUBCLASS_EXCLUDE="history_event"
# Gotify application associated with ZED_GOTIFY_APPTOKEN.
# Value is an integer 0 and up.
#ZED_GOTIFY_PRIORITY=""
+
+##
+# Whether to send notifications via libnotify
+# If defined, notify-send(1) will be used to send notifications
+# Disabled by default; uncomment to enable.
+#ZED_USE_LIBNOTIFY=1
--
2.47.0