Skip to content

Instantly share code, notes, and snippets.

@meggi
Last active May 12, 2016 14:06
Show Gist options
  • Save meggi/bdd94e480d469a01a5fe to your computer and use it in GitHub Desktop.
Save meggi/bdd94e480d469a01a5fe to your computer and use it in GitHub Desktop.
AWS
#!/bin/bash
SERVICENAME="NAME-OF-NODE"
INSTANCEID=$(wget -q -O - http://169.254.169.254/latest/meta-data/instance-id)
AWS=/usr/bin/aws
REGION=$(wget -q -O - http://169.254.169.254/latest/dynamic/instance-identity/document | grep region | awk -F '"' '{print $4}')
DOMAIN=$(/usr/bin/aws ec2 describe-instances --region $REGION --instance-id $INSTANCEID --query 'Reservations[*].Instances[*].Tags[*]' --output=t
ext | grep Name | awk -F ":" '{print $1}' | awk '{print $2}')
SNSARN=arn:aws:sns:${REGION}:948962939411:BPPM_Connector
METRICNAME=$1
PERIOD=$2
UNIT=$3
METRICTHRESHOLD=$4
COMPARISONOPERATOR=$5
$AWS cloudwatch put-metric-alarm --region=$REGION --alarm-name "$SERVICENAME|$INSTANCEID|$METRICNAME" --alarm-description "$DOMAIN CLI $METRICNAM
E" --actions-enabled --ok-actions $SNSARN --alarm-actions $SNSARN --insufficient-data-actions $SNSARN --metric-name $METRICNAME --namespace "AWS/
EC2" --statistic Average --dimensions "Name=InstanceId,Value=$INSTANCEID" --period $PERIOD --unit $UNIT --evaluation-periods 1 --threshold $METRI
CTHRESHOLD --comparison-operator $COMPARISONOPERATOR
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment