Amazon SNS for Nagios monitoring
I wanted to get SNS to notify me if something big went down at the office and email wasn’t enough so I started googling. Everything I found didn’t really do what I wanted so I took my own approach. Using aws-cli and some bash scripting I came up with the following code:
#!/bin/bash
export AWS_ACCESS_KEY_ID='AWS ACCESS KEY'
export AWS_SECRET_ACCESS_KEY='AWS SECRET KEY'
export AWS_DEFAULT_REGION='REGION'
/usr/local/bin/aws sns publish --topic-arn arn:aws:sns:'TOPIC ID' --message "$*"
#EOF
You will need to create a topic in AWS SNS and point it to a cell phone number. Modify the script with the correct AWS KEY info, Region location, and Topic ID for SNS. Execute the script with:
./sns.sh testing
or
printf "is this working?" | xargs ./sns.sh $1
and you will get something like the following:
{
"MessageId": "c0s399d5-7y80-326a-b398-40808ds0f8a0"
}
Insert a line into your Naigos command config as follows and assign a contact for it:
/usr/bin/printf "%b" "*ALERT*****\nType: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nInfo:
$HOSTOUTPUT$\nDate/T^Ce: $LONGDATETIME$\n" | xargs /usr/lib64/nagios/plugins/sns $1
At this point go back to SNS and enter the phone numbers of everyone on your team and enjoy your 3am Txt messages.