Skip to content

Commit

Permalink
use slack token instead of webhook
Browse files Browse the repository at this point in the history
replace slack webhook with bot token
  • Loading branch information
nicolasochem committed Jul 30, 2024
1 parent d3a65d3 commit ee13f4a
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 9 deletions.
16 changes: 12 additions & 4 deletions charts/tezos-reward-distributor/scripts/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ if [ "${DRY_RUN}" == "false" ]; then
else
dry_run_arg="--dry_run"
fi

python src/main.py \
-M 2 \
--reward_data_provider ${REWARD_DATA_PROVIDER} \
Expand All @@ -23,10 +24,17 @@ python src/main.py \

# if TRD fails, send a slack alert
if [ $? -ne 0 ]; then
# check if webhook is set
if [ -z "${SLACK_WEBHOOK}" ]; then
echo "TRD failed, but SLACK_WEBHOOK is not set, failing job"
# check if bot token and channel are set
if [ -z "${SLACK_BOT_TOKEN}" ] || [ -z "${SLACK_CHANNEL}" ]; then
echo "TRD failed, but SLACK_BOT_TOKEN or SLACK_CHANNEL is not set, failing job"
exit 1
fi
curl -X POST -H 'Authorization: Bearer '${SLACK_BOT_TOKEN} -H 'Content-type: application/json' \
--data "{\"channel\":\"${SLACK_CHANNEL}\", \"text\":\"Payout failed for $BAKER_ALIAS\"}" \
https://slack.com/api/chat.postMessage | jq '.ok' | grep true
if [ $? -ne 0 ]; then
echo "Failed to send Slack alert"
exit 1
fi
curl -X POST -H 'Content-type: application/json' --data "{\"text\":\"Payout failed for $BAKER_ALIAS\"}" ${SLACK_WEBHOOK}
fi

4 changes: 2 additions & 2 deletions charts/tezos-reward-distributor/templates/cronjob.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ spec:
value: "{{ .Values.dry_run }}"
- name: BAKER_ALIAS
value: "{{ .Values.baker_alias | default "unknown" }}"
- name: SLACK_WEBHOOK
- name: SLACK_BOT_TOKEN
valueFrom:
secretKeyRef:
name: {{ include "tezos-reward-distributor.fullname" . }}-secret
key: slack_webhook
key: slack_bot_token
restartPolicy: OnFailure
2 changes: 1 addition & 1 deletion charts/tezos-reward-distributor/templates/secrets.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ kind: Secret
metadata:
name: {{ include "tezos-reward-distributor.fullname" . }}-secret
data:
slack_webhook: {{ .Values.slack_webhook | b64enc }}
slack_bot_token: {{ .Values.slack_bot_token | b64enc }}
4 changes: 2 additions & 2 deletions charts/tezos-reward-distributor/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ trd_config:
# Rewards for cycle %CYCLE% are completed.
# We paid out %TREWARDS% tez in rewards to %NDELEGATORS% delegators.

# slack webhook to be alerted when TRD fails
slack_webhook: "https://hooks.slack.com/services/XXXXXXXXX/XXXXXXXXX/XXXXXXXXXXXXXXXXXXXXXXXX"
# slack token to be alerted when TRD fails
slack_bot_token: "xoxb-xxxxxxxx"

# baker alias to push to slack webhook
# baker_alias: "mybaker"

0 comments on commit ee13f4a

Please sign in to comment.