bash mattermost sender

This commit is contained in:
Oleg Sheynin 2023-12-29 16:43:09 -05:00
parent 333fc41abf
commit 83cc1cd509
3 changed files with 18 additions and 23 deletions

View File

@ -1 +1 @@
0.3.9
0.4.1

View File

@ -7,18 +7,9 @@ RootDir="${HOME}/prod"
export PYTHONPATH=${RootDir}
# Temporary
MmStatusSender=
MmStatusSender="${MmStatusSender} ${HOME}/.pyenv/python3.10-venv/bin/python3"
MmStatusSender="${MmStatusSender} ${RootDir}/cvttpy/apps/utils/mmost_sender.py"
MmStatusSender="${MmStatusSender} --channel=Status-CVTT"
MmStatusSender="${MmStatusSender} --log_level=ERROR"
MmAlertSender=
MmAlertSender="${MmAlertSender} ${HOME}/.pyenv/python3.10-venv/bin/python3"
MmAlertSender="${MmAlertSender} ${RootDir}/cvttpy/apps/utils/mmost_sender.py"
MmAlertSender="${MmAlertSender} --channel=Alerts-CVTT"
MmAlertSender="${MmAlertSender} --log_level=ERROR"
StatusChannel=Status-CVTT
AlertChannel=Alerts-CVTT
Sender=${RootDir}/ops/utils/send_mmost.sh
Hosts=
Hosts="${Hosts} cloud11.cvtt.vpn"
@ -84,14 +75,14 @@ function storage_check() {
Measurements=()
tmpfile=$(mktemp)
storage_check > ${tmpfile}
cat ${tmpfile} | ${MmStatusSender}
cat ${tmpfile} | ${Sender} ${StatusChannel}
tmpfile=$(mktemp)
space_alert > ${tmpfile}
cat ${tmpfile}
if [ -s ${tmpfile} ]
then
(echo "### :card_file_box: STORAGE ALERTS" && cat ${tmpfile}) | ${MmAlertSender}
(echo "### :card_file_box: STORAGE ALERTS" && cat ${tmpfile}) | ${Sender} ${AlertChannel}
else
echo File ${tmpfile} is empty
fi

View File

@ -23,20 +23,24 @@ Cmd="${Cmd} | jq -r '.id'"
channel_id=$(eval ${Cmd})
input=$(cat)
input="$(cat)"
body="{"
body="${body}\\\"channel_id\\\":\\\"${channel_id}\\\""
body="${body}, \\\"message\\\":\\\"${input}\\\""
body="${body}\"channel_id\":\"${channel_id}\""
body="${body}, \"message\":\"${input}\""
body="${body}}"
# replace new line with literal \n
body=$(echo "${body}" |awk '{printf "%s\\n", $0}')
post_url="${url}/api/v4/posts"
Cmd="curl -s"
Cmd="${Cmd} -X POST"
Cmd="${Cmd} -H \"Content-Type: Application/JSON\""
Cmd="${Cmd} -H \"Authorization: Bearer ${bearer}\""
Cmd="${Cmd} --data \"${body}\""
Cmd="${Cmd} --request POST"
Cmd="${Cmd} --header \"Content-Type: Application/JSON\""
Cmd="${Cmd} --header \"Authorization: Bearer ${bearer}\""
Cmd="${Cmd} --data @-"
Cmd="${Cmd} ${post_url}"
eval ${Cmd} > /dev/null
(echo "${body}" | eval ${Cmd}) > /dev/null