init
This commit is contained in:
commit
8ff9ca1294
5 changed files with 68 additions and 0 deletions
7
Dockerfile
Normal file
7
Dockerfile
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
FROM badouralix/curl-jq:latest
|
||||||
|
|
||||||
|
COPY ./check /opt/resource/check
|
||||||
|
COPY ./in /opt/resource/in
|
||||||
|
COPY ./out /opt/resource/out
|
||||||
|
|
||||||
|
RUN chmod +x /opt/resource/out /opt/resource/in /opt/resource/check
|
1
check
Executable file
1
check
Executable file
|
@ -0,0 +1 @@
|
||||||
|
#!/bin/sh
|
12
example.json
Normal file
12
example.json
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
{
|
||||||
|
"params": {
|
||||||
|
"key": "concourse",
|
||||||
|
"body": "hoi",
|
||||||
|
"title": "Titeltje!",
|
||||||
|
"type": "warning",
|
||||||
|
"format": "text"
|
||||||
|
},
|
||||||
|
"source": {
|
||||||
|
"host": "https://apprise.pim.kunis.nl:444"
|
||||||
|
}
|
||||||
|
}
|
1
in
Executable file
1
in
Executable file
|
@ -0,0 +1 @@
|
||||||
|
#!/bin/sh
|
47
out
Executable file
47
out
Executable file
|
@ -0,0 +1,47 @@
|
||||||
|
#!/bin/sh
|
||||||
|
# https://github.com/cloudfoundry-community/slack-notification-resource/blob/master/out
|
||||||
|
# https://github.com/caronc/apprise-api#persistent-storage-solution
|
||||||
|
set -e
|
||||||
|
|
||||||
|
cd "${1}"
|
||||||
|
|
||||||
|
exec 3>&1
|
||||||
|
exec 1>&2
|
||||||
|
|
||||||
|
payload=$(mktemp /tmp/resource-in.XXXXXX)
|
||||||
|
cat > "${payload}" <&0
|
||||||
|
|
||||||
|
apprise_host="$(jq -r '.source.host' < "${payload}")"
|
||||||
|
|
||||||
|
apprise_key="$(jq -r '.params.key' < "${payload}")"
|
||||||
|
alert_body="$(jq -r '.params.body' < "${payload}")"
|
||||||
|
alert_title="$(jq -r '.params.title // null' < "${payload}")"
|
||||||
|
alert_type="$(jq -r '.params.type // null' < "${payload}")"
|
||||||
|
alert_tag="$(jq -r '.params.tag // null' < "${payload}")"
|
||||||
|
alert_format="$(jq -r '.params.format // null' < "${payload}")"
|
||||||
|
|
||||||
|
echo "${alert_body}"
|
||||||
|
|
||||||
|
alert_body="$(eval "printf \"${alert_body}\"" | jq -R -s .)"
|
||||||
|
[ "${alert_title}" != "null" ] && alert_title="$(eval "printf \"${alert_title}\"" | jq -R -s .)"
|
||||||
|
[ "${alert_type}" != "null" ] && alert_type="$(eval "printf \"${alert_type}\"" | jq -R -s .)"
|
||||||
|
[ "${alert_tag}" != "null" ] && alert_tag="$(eval "printf \"${alert_tag}\"" | jq -R -s .)"
|
||||||
|
[ "${alert_format}" != "null" ] && alert_format="$(eval "printf \"${alert_format}\"" | jq -R -s .)"
|
||||||
|
|
||||||
|
body="$(cat <<EOF
|
||||||
|
{
|
||||||
|
"body": ${alert_body},
|
||||||
|
"title": ${alert_title},
|
||||||
|
"type": ${alert_type},
|
||||||
|
"tag": ${alert_tag},
|
||||||
|
"format": ${alert_format}
|
||||||
|
}
|
||||||
|
EOF
|
||||||
|
)"
|
||||||
|
|
||||||
|
compact_body="$(echo "${body}" | jq -c '.')"
|
||||||
|
echo "$compact_body" | jq 'del(..|nulls)' > /tmp/compact_body.json
|
||||||
|
|
||||||
|
curl -v -X POST -T /tmp/compact_body.json -H "Content-Type: application/json" "${apprise_host}/notify/${apprise_key}"
|
||||||
|
|
||||||
|
echo "{}" >&3
|
Loading…
Reference in a new issue