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

View File

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