Skip to content

Instantly share code, notes, and snippets.

@DRN88
Last active January 11, 2023 13:46
Show Gist options
  • Save DRN88/680f6c04d7782561c08eeccc084c32e9 to your computer and use it in GitHub Desktop.
Save DRN88/680f6c04d7782561c08eeccc084c32e9 to your computer and use it in GitHub Desktop.
Send aws sns sms messages with bash. Zabbix
#!/bin/bash
#
# 1, Create AWS IAM user with a policy allowing only AWS SNS Publish command
# 2, Install awscli with 'yum -y install awscli' on zabbix server
# 3, Add /bin/bash shell for zabbix user: usermod -s /bin/bash zabbix
# 4, Deploy this script to: /etc/zabbix/send-aws-sns-sms.sh
# 5, Edit this script and define the required variables
# 6, Run the script manually to test
# 7, Use the script in Zabbix. Create a new Media Type -> Script
# Use zabbix documentation for the script parameter setup
# https://www.zabbix.com/documentation/3.0/manual/config/notifications/media/script
# 8, Create new Media for zabbix users, use phone number in E.164 format like: +447802861010
#
# IMPORTANT: Zabbix script parameter orer has to match here like:
# $1 is {ALERT.SENDTO}
# $2 is {ALERT.MESSAGE}
# Make sure the message is not longer than 140 ASCII chars for best results:
# https://docs.aws.amazon.com/sns/latest/dg/sms_publish-to-phone.html
#
if [ $# -eq 2 ]; then
AWS_ACCESS_KEY_ID="AKIAnnnnnnnnnnnnnn" \
AWS_SECRET_ACCESS_KEY="MySecretKeyHere" \
AWS_DEFAULT_REGION="eu-west-1" \
/bin/aws sns publish --phone-number "${1}" --message "${2}"
else
/bin/echo -e "\nThis script requires 2 parameters."
/bin/echo -e "\nUsage: ${0} PhoneNumberInE.194 Message\n"
/bin/echo -e "\nUsage: ${0} +44nnnnnnnn 'My message here'\n"
fi
@jaltgen
Copy link

jaltgen commented Jan 11, 2023

Good stuff, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment