I thought I would share this with you all. Just in case anyone ever wanted to do something like this. Anyways, I setup a very primitive alert using a bash script that calls the AWS SNS. I borrowed quite a bit of my script from the link below to do this.
I modified my script to monitor the dewpoint on our farm. This alerts us to start our wind machine when it hits 36 degrees F.
You must have an Amazon Web Service account to use the SNS service. You can use the free tier and send 1000 emails and 100 SMS per month for free.
I created an new user in my existing AWS account within IAM and assigned it the SNS full control role.
I then installed the awscli.
I then configured aws for this system with the new user with the SNS full contorl role.
You have to enter the AWS key and AWS Secret key that were generated when you made the new user. You should also use an east coast default region if you want to use SMS. The us-west-2 region does not support SMS.
I used the following command to create the topic.
# aws sns create-topic --name dewpoint-alert
I used the command below to subscribe to the topic.
# aws sns subscribe --topic arn:aws:sns:us-west-2:110057505160:dewpoint-alert --protocol email --notification-endpoint <email address>
If you look at the script you can see how I call the topic and alert with a message.
You can look up the topics and subscriptions on your AWS account with the following commands.
# aws sns list-subscriptions
Note: Substitute the email address with the email address you would like to use to get alerts.
I assume that you substitute --protocol email with --protocol sms if you have the default region to an east cost default region.
The script is called by a cron job that runs every 15 minutes.
# crontab -e
1,16,31,46 * * * * /root/scripts/weewxAlert.sh
Contents of weewxAlert.sh
#!/bin/bash
# This script will alert the subscribers every three minutes for a total of 5 iterations. If dewpoint is below 36 degrees F. The alert will come from the AWS SNS topic.
logDir="/var/log/weatherAlert/weatherAlert.log"
notify() {
stateFile="/tmp/weatherAlertAlarm"
if test `find $stateFile 2>/dev/null`
then
echo "Five alerts already sent!" >> $logDir
date >>$logDir
else
for i in `seq 0 4`;
do
aws sns publish\
\--topic-arn arn:aws:sns:us-west-2:110057505160:dewpoint-alert\
--message "$alert" 2>/dev/null
touch /tmp/weatherAlertAlarm
echo "Message sent" date >> $logDir
date >> $logDir
sleep 180
done
fi
}
# Gets dewpoint from /var/www/weewx/RSS/weewx_rss.xml
dewpoint=`/bin/cat /var/www/weewx/RSS/weewx_rss.xml\
| grep Dewpoint: | awk '{print $2}' | cut -f1 -d"&"`
if (($(echo "$dewpoint < 36" | bc -l) ));
then
echo $dewpoint
alert="Weather Alert! DewPoint is $dewpoint. Start up the wind machine."
notify $alert
else
# Script ends if the dewpoint is not below 36 degrees.
echo "Dewpoint is not below 36 degrees F" >> $logDir
date >> $logDir
fi
In order to acknowledge the alert. You have to kill the cronjob. If you want to start it up again and alert you have to remove the /tmp/weatherAlertAlarm
If any of you need any help alerting. Please let me know. I hope this was helpful.