create_cloudwatch_EC2_alarm.sh

Create CloudWatch (AWS) EC2 alarm in Bash

1

Votes

#!/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

Vote Here

You must earn at least 1 vote on your snippets to be allowed to vote

Terms Of Use

Privacy Policy

Featured snippets are MIT license

Gears & Masters

Advertise

DevOpsnipp.com © 2020

medium.png