Skip to content

Commit 0b99069

Browse files
Merge pull request #23 from iriusrisk/DE-174
DE-174: Check if instance is IMSDv1 or IMSDv2 to get ec2 metadata
2 parents 4da9317 + 53ace8c commit 0b99069

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ plugins {
2222
}
2323

2424
group 'com.continuumsecurity.elasticagent'
25-
version '2.2.1'
25+
version '2.2.2'
2626

2727
// these values that go into plugin.xml
2828
project.ext.pluginDesc = [

src/main/java/com/continuumsecurity/elasticagent/ec2/Ec2Instance.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,18 @@ public static Ec2Instance create(CreateAgentRequest request, PluginSettings sett
7676
"echo \"wrapper.app.parameter.103=NONE\" >> /usr/share/go-agent/wrapper-config/wrapper-properties.conf\n" +
7777
"mkdir -p /var/lib/go-agent/config\n" +
7878
"echo \"agent.auto.register.key=" + request.autoRegisterKey() + "\" > /var/lib/go-agent/config/autoregister.properties\n" +
79-
"echo \"agent.auto.register.hostname=EA_$(curl http://169.254.169.254/latest/meta-data/instance-id)\" >> /var/lib/go-agent/config/autoregister.properties\n" +
80-
"echo \"agent.auto.register.elasticAgent.agentId=$(curl http://169.254.169.254/latest/meta-data/instance-id)\" >> /var/lib/go-agent/config/autoregister.properties\n" +
79+
80+
"HTTP_CODE=`curl -I http://169.254.169.254 | head -n 1 | cut -d$' ' -f2`\n" +
81+
"if [[ HTTP_CODE -eq 200 ]];\n" +
82+
"then\n" +
83+
"INSTANCE_ID=`curl http://169.254.169.254/latest/meta-data/instance-id`\n" +
84+
"else\n" +
85+
"TOKEN=`curl -X PUT 'http://169.254.169.254/latest/api/token' -H 'X-aws-ec2-metadata-token-ttl-seconds: 21600'`\n" +
86+
"INSTANCE_ID=`curl -H \"X-aws-ec2-metadata-token: $TOKEN\" http://169.254.169.254/latest/meta-data/instance-id`\n" +
87+
"fi\n" +
88+
89+
"echo \"agent.auto.register.hostname=EA_$INSTANCE_ID\" >> /var/lib/go-agent/config/autoregister.properties\n" +
90+
"echo \"agent.auto.register.elasticAgent.agentId=$INSTANCE_ID\" >> /var/lib/go-agent/config/autoregister.properties\n" +
8191
"echo \"agent.auto.register.elasticAgent.pluginId=" + Constants.PLUGIN_ID + "\" >> /var/lib/go-agent/config/autoregister.properties\n" +
8292
"chown -R go:go /var/log/go-agent/\n" +
8393
"chown -R go:go /var/lib/go-agent/\n" +

0 commit comments

Comments
 (0)