Skip to content

Commit 12b2e18

Browse files
Merge pull request #2 from DataDog/651-ec2-instance-id
@fabrice Missing urllib import. Turned 2.6ism into 2.4 code.
2 parents 2e5f947 + 83332c3 commit 12b2e18

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

agent.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import sched
1919
import sys
2020
import time
21+
import urllib
2122

2223
# Check we're not using an old version of Python. We need 2.4 above because some modules (like subprocess)
2324
# were only introduced in 2.4.
@@ -42,12 +43,12 @@ def get_ec2_instance_id():
4243
"""Fetch EC2 instance ID if possible. If not on EC2 returns None"""
4344
try:
4445
url = urllib.urlopen(agent.EC2_URL)
45-
if url.getcode() == 200:
46-
instanceId = url.read()
47-
return instanceId
46+
instanceId = url.read()
47+
assert instanceId.startswith("i-"), "Malformed instance-id: %s" % instanceId
48+
return instanceId
4849

4950
except Exception, e:
50-
pass
51+
logging.getLogger('agent').exception('Cannot determine instance-id. Is this machine on EC2?')
5152

5253
return None
5354

0 commit comments

Comments
 (0)