-
Notifications
You must be signed in to change notification settings - Fork 68
Add Elastic Agent #1005
Add Elastic Agent #1005
Changes from 11 commits
1e6d775
b9bba2f
c6f0967
355a3ed
b3e5723
1ee384c
b9a659e
48a1607
3ef764a
0c77461
d067c77
356ce54
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
import json | ||
import os | ||
|
||
from .helpers import curl_healthcheck, try_to_set_slowlog | ||
from .helpers import curl_healthcheck, try_to_set_slowlog, urlparse | ||
from .service import StackService, Service, DEFAULT_APM_SERVER_URL | ||
|
||
|
||
|
@@ -587,6 +587,68 @@ def render_tee(self): | |
return {self.name(): content} | ||
|
||
|
||
class ElasticAgent(StackService, Service): | ||
docker_path = "beats" | ||
|
||
def __init__(self, **options): | ||
super(ElasticAgent, self).__init__(**options) | ||
if not self.at_least_version("7.8"): | ||
raise Exception("Elastic Agent is only available in 7.8+") | ||
|
||
# build deps | ||
self.depends_on = {"kibana": {"condition": "service_healthy"}} if options.get("enable_kibana", True) else {} | ||
|
||
# build environment | ||
# Environment variables used | ||
# FLEET_ENROLLMENT_TOKEN - existing enrollment token to be used for enroll | ||
# FLEET_ENROLL - if set to 1 enroll will be performed | ||
# FLEET_ENROLL_INSECURE - if set to 1, agent will enroll with fleet using --insecure flag | ||
# FLEET_SETUP - if set to 1 fleet setup will be performed | ||
# FLEET_TOKEN_NAME - token name for a token to be created | ||
# KIBANA_HOST - actual kibana host [http://localhost:5601] | ||
# KIBANA_PASSWORD - password for accessing kibana API [changeme] | ||
# KIBANA_USERNAME - username for accessing kibana API [elastic] | ||
kibana_url = options.get("elastic_agent_kibana_url") | ||
if not kibana_url: | ||
kibana_scheme = "https" if self.options.get("kibana_enable_tls", False) else "http" | ||
# TODO(gr): add default elastic-agent user | ||
kibana_url = kibana_scheme + "://admin:changeme@" + self.DEFAULT_KIBANA_HOST | ||
|
||
kibana_parsed_url = urlparse(kibana_url) | ||
self.environment = { | ||
"FLEET_ENROLL": "1", | ||
"FLEET_SETUP": "1", | ||
"KIBANA_HOST": kibana_url, | ||
} | ||
if kibana_parsed_url.password: | ||
self.environment["KIBANA_PASSWORD"] = kibana_parsed_url.password | ||
if kibana_parsed_url.username: | ||
self.environment["KIBANA_USERNAME"] = kibana_parsed_url.username | ||
if not kibana_url.startswith("https://"): | ||
self.environment["FLEET_ENROLL_INSECURE"] = 1 | ||
|
||
def _content(self): | ||
return dict( | ||
depends_on=self.depends_on, | ||
environment=self.environment, | ||
healthcheck={ | ||
"test": ["CMD", "/bin/true"], | ||
}, | ||
volumes=[ | ||
"/var/run/docker.sock:/var/run/docker.sock", | ||
] | ||
) | ||
|
||
@classmethod | ||
def add_arguments(cls, parser): | ||
super(ElasticAgent, cls).add_arguments(parser) | ||
parser.add_argument( | ||
"--elastic-agent-kibana-url", | ||
default="http://admin:changeme@" + cls.DEFAULT_KIBANA_HOST, | ||
help="Elastic Agent's Kibana URL" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe add |
||
) | ||
|
||
|
||
class Elasticsearch(StackService, Service): | ||
default_environment = [ | ||
"bootstrap.memory_lock=true", | ||
|
@@ -859,6 +921,10 @@ def __init__(self, **options): | |
if self.at_least_version("7.7"): | ||
self.environment["XPACK_SECURITY_ENCRYPTIONKEY"] = "fhjskloppd678ehkdfdlliverpoolfcr" | ||
self.environment["XPACK_ENCRYPTEDSAVEDOBJECTS_ENCRYPTIONKEY"] = "fhjskloppd678ehkdfdlliverpoolfcr" | ||
if self.at_least_version("7.8"): | ||
self.environment["XPACK_FLEET_AGENTS_ELASTICSEARCH_HOST"] = urls[0] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The Elastic Agent container crashes in 7.8, and I suspect it might be because these settings were named differently. I just can't find it, https://www.elastic.co/guide/en/kibana/7.10/fleet-settings-kb.html doesn't exist for previous versions... We might just as well support >=7.10 only and revisit if needed for earlier version? The error is pretty clear, thou:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
self.environment["XPACK_FLEET_AGENTS_KIBANA_HOST"] = "{}://kibana:{}".format( | ||
"https" if self.kibana_tls else "http", self.SERVICE_PORT) | ||
if options.get("xpack_secure"): | ||
self.environment["ELASTICSEARCH_PASSWORD"] = "changeme" | ||
self.environment["ELASTICSEARCH_USERNAME"] = "kibana_system_user" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isn't that
admin
instead ofelastic
?