Skip to content

Instantly share code, notes, and snippets.

@goduncan
Created June 24, 2017 22:57
Show Gist options
  • Save goduncan/58872a6a11e2244fea511cea561dcbef to your computer and use it in GitHub Desktop.
Save goduncan/58872a6a11e2244fea511cea561dcbef to your computer and use it in GitHub Desktop.
Create a Sumo Logic collector's name from EC2 metadata
#!/bin/bash
az=$(curl -sfm1 http://169.254.169.254/latest/meta-data/placement/availability-zone)
instanceId=$(curl -sfm1 http://169.254.169.254/latest/meta-data/instance-id)
accountNo=$(curl -sfm1 http://169.254.169.254/latest/dynamic/instance-identity/document | jq -r '.accountId')
region=$(echo $az | sed 's/\w$//')
name="${instanceId}:${region}:${accountNo}"
# Check if we have set the name already
if ! grep -q "name=" /opt/SumoCollector/config/user.properties; then
echo name=${name} >> /opt/SumoCollector/config/user.properties
fi
/opt/SumoCollector/collector start
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment