Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 17 additions & 7 deletions instana/fsm.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,22 +67,32 @@ def start_metric_reporting(self, e):
self.agent.sensor.meter.run()

def lookup_agent_host(self, e):
if self.agent.sensor.options.agent_host != "":
host = a.AGENT_DEFAULT_HOST
port = a.AGENT_DEFAULT_PORT

if "INSTANA_AGENT_IP" in os.environ:
host = os.environ["INSTANA_AGENT_IP"]
if "INSTANA_AGENT_PORT" in os.environ:
port = int(os.environ["INSTANA_AGENT_PORT"])

elif self.agent.sensor.options.agent_host != "":
host = self.agent.sensor.options.agent_host
else:
host = a.AGENT_DEFAULT_HOST
if self.agent.sensor.options.agent_port != 0:
port = self.agent.sensor.options.agent_port

h = self.check_host(host)
h = self.check_host(host, port)
if h == a.AGENT_HEADER:
self.agent.set_host(host)
self.agent.set_port(port)
self.fsm.announce()
return True
elif os.path.exists("/proc/"):
host = self.get_default_gateway()
if host:
h = self.check_host(host)
h = self.check_host(host, port)
if h == a.AGENT_HEADER:
self.agent.set_host(host)
self.agent.set_port(port)
self.fsm.announce()
return True

Expand All @@ -105,8 +115,8 @@ def get_default_gateway(self):

return None

def check_host(self, host):
log.debug("checking host", host)
def check_host(self, host, port):
log.debug("checking %s:%d" % (host, port))

(_, h) = self.agent.request_header(
self.agent.make_host_url(host, "/"), "GET", "Server")
Expand Down