~kolletzki/scripts

eaf7bb3575b5b1e7c7b9c6e928a16a50414c65cf — Lukas Kolletzki 1 year, 2 months ago c7e63d1 master
Trim content in discord notifications
2 files changed, 20 insertions(+), 8 deletions(-)

M discord-notify.sh
M systemd-unit-notify.sh
M discord-notify.sh => discord-notify.sh +9 -2
@@ 4,10 4,16 @@ set -euo pipefail
WEBHOOK_URL=""

if [[ ${#} -lt 1 ]] || [[ -z ${1} ]]; then
		printf "Usage: ${0} <content>\n" >&2
			exit 1
	printf "Usage: ${0} <content>\n" >&2
	exit 1
fi

content=${1}
if [[ ${#content} -gt 1990 ]]; then
	content="$(head -c 1990 <<< "${content}")\n[...]"
fi


data=$(cat <<EOF
{
	"content": $(printf "${1}" | jq -aRs .),


@@ 16,5 22,6 @@ data=$(cat <<EOF
EOF
)


curl -fsSL -X POST -H "Content-Type: application/json" -d "${data}" "${WEBHOOK_URL}"


M systemd-unit-notify.sh => systemd-unit-notify.sh +11 -6
@@ 2,11 2,11 @@
set -euo pipefail

WEBHOOK_URL=""
JOURNAL_LINES=5
JOURNAL_LINES=8

if [[ ${#} -lt 1 ]] || [[ -z ${1} ]]; then
		printf "Usage: ${0} <unit>\n" >&2
			exit 1
	printf "Usage: ${0} <unit>\n" >&2
	exit 1
fi

unit=${1}


@@ 18,10 18,15 @@ EOF
)

if [[ ${JOURNAL_LINES} -gt 0 ]]; then
		journal="$(journalctl -u ${unit} -n ${JOURNAL_LINES} --no-hostname -o short-full -q)"
			journal="$(sed 's/^/> /' <<< "${journal}")"
	journal="$(journalctl -u ${unit} -n ${JOURNAL_LINES} --no-hostname -o short-full -q)"

				content="$(cat <<EOF
	if [[ ${#journal} -gt 1850 ]]; then
		journal="[...] $(tail -c 1850 <<< "${journal}")"
	fi

	journal="$(sed 's/^/> /' <<< "${journal}")"

	content="$(cat <<EOF
${content}

**Journal:**