various
This commit is contained in:
parent
73e43624b7
commit
bfbf3c128f
2 changed files with 78 additions and 32 deletions
|
@ -6,9 +6,19 @@ _PLUG_ARGS=(
|
|||
"message;m;;string;(No Message)"
|
||||
"title;t;;string;(No Title)"
|
||||
"level;l;;string;info"
|
||||
"invoker;i;;string"
|
||||
"invoked-by;i;;string"
|
||||
)
|
||||
|
||||
function get_cache_header() {
|
||||
topic="$1"
|
||||
|
||||
if [[ "$topic" == "zio_test" ]]; then
|
||||
echo ""
|
||||
else
|
||||
echo "Cache: no"
|
||||
fi
|
||||
}
|
||||
|
||||
function get_level_emoji() {
|
||||
case "$1" in
|
||||
"critical"|"error") echo "⛔" ;;
|
||||
|
@ -30,6 +40,18 @@ function get_level_priority() {
|
|||
esac
|
||||
}
|
||||
|
||||
function get_topic() {
|
||||
invoked_by="$1"
|
||||
topic_prefix="zio"
|
||||
topic="test"
|
||||
|
||||
if [[ -n "$invoked_by" ]]; then
|
||||
topic="$(echo "$invoked_by" | sed -r 's/sh.zio.//g' | sed -r 's/[.]+/-/g')"
|
||||
fi
|
||||
|
||||
echo "${topic_prefix}_$topic"
|
||||
}
|
||||
|
||||
function main() {
|
||||
token_path="$(get_config_dir "sh.zio.notify")/token"
|
||||
[[ ! -f "$token_path" ]] && die "'$token_path' does not exist"
|
||||
|
@ -37,24 +59,27 @@ function main() {
|
|||
token="$(cat "$token_path")"
|
||||
|
||||
hostname="$(hostname -s)"
|
||||
invoker="$_invoker"
|
||||
invoked_by="$_invoked_by"
|
||||
level_emoji="$(get_level_emoji "$_level")"
|
||||
triggered_by="sh.zio.backup"
|
||||
|
||||
n_message="$_message"
|
||||
n_priority="$(get_level_priority "$_level")"
|
||||
n_title="$level_emoji [$hostname] $_title"
|
||||
n_topic="zio_backup_a123"
|
||||
n_topic="$(get_topic "$_invoked_by")"
|
||||
|
||||
body='{
|
||||
"message": "'$n_message'",
|
||||
"priority": '$n_priority',
|
||||
"tags": ["'$hostname'", "'$invoker'"],
|
||||
"tags": ["'$hostname'", "'$invoked_by'"],
|
||||
"title": "'$n_title'",
|
||||
"topic": "'$n_topic'"
|
||||
}'
|
||||
|
||||
curl -d "$body" -H "Authorization: Bearer $token" -H "Cache: no" -H "Markdown: yes" "https://ntfy.zio.sh/"
|
||||
curl -d "$body" \
|
||||
-H "Authorization: Bearer $token" \
|
||||
-H "$(get_cache_header "$n_topic")" \
|
||||
-H "Markdown: yes" \
|
||||
"https://ntfy.zio.sh/"
|
||||
}
|
||||
|
||||
if [[ $_PLUG_INVOKED != "true" ]]; then
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue