Skip to content

Instantly share code, notes, and snippets.

@elocnatsirt
Last active February 9, 2017 17:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elocnatsirt/061e6ea63e37523de838f294fb4881eb to your computer and use it in GitHub Desktop.
Save elocnatsirt/061e6ea63e37523de838f294fb4881eb to your computer and use it in GitHub Desktop.
Retrieves information about an AWS instance and outputs it via stdout. Written to use as a Sensu check to get basic information about a client.
#!/bin/bash
# Written By: https://github.com/elocnatsirt
# This script will curl the instance metadata and output useful values
# If the system isn't in AWS it will succeed with a relevant message
instance_id=`curl --silent http://169.254.169.254/latest/meta-data/instance-id`
instance_type=`curl --silent http://169.254.169.254/latest/meta-data/instance-type`
location=`curl --silent http://169.254.169.254/latest/meta-data/placement/availability-zone`
region=`curl --silent http://169.254.169.254/latest/meta-data/placement/availability-zone | sed 's/.$//'`
if [ "$instance_id" == "" ]; then
echo "This is not an AWS instance"
exit 0
fi
echo "Location: ${location}"
echo "Instance ID: ${instance_id}"
echo "Instance Type: ${instance_type}"
echo "Cloudwatch Link: https://console.aws.amazon.com/cloudwatch/home?region=${region}#metrics:metricFilter=Search%253D${instance_id}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment