Add url subpath for Logsender to reach OpenSearch

It might happen, that the url for the OpenSearch is not directly
the hostname, eg.: localhost, but it also contains a subPath
for example: localhost/opensearch. In that case, the Logsender
was not able to connect to the OpenSearch.

Change-Id: I58a89c2fc33bdd06466bb60cc90fe2bd0317c92b
This commit is contained in:
Daniel Pawlik 2024-08-21 11:29:18 +02:00
parent d47815c04c
commit 6e3e1bf6f0
No known key found for this signature in database
3 changed files with 14 additions and 0 deletions

View File

@ -2,6 +2,7 @@
directory: /tmp/logscraper
host: localhost
port: 9200
subpath:
username: logstash
password:
index_prefix: logstash-

View File

@ -63,6 +63,11 @@ def get_arguments():
"be stored.")
parser.add_argument("--host", help="Opensearch host")
parser.add_argument("--port", help="Opensearch port", type=int)
parser.add_argument("--subpath", help="Add the subpath to the host. "
"That is useful, when the host url contains "
"a slash(/). For example: "
"'http://localhost/opensearch' then the subpath "
"is 'opensearch'.")
parser.add_argument("--username", help="Opensearch username")
parser.add_argument("--password", help="Opensearch user password")
parser.add_argument("--index-prefix", help="Prefix for the index.",
@ -660,6 +665,9 @@ def get_es_client(args):
if args.ca_file:
es_creds['ca_certs'] = args.ca_file
if args.subpath:
es_creds['url_prefix'] = args.subpath
es_client = OpenSearch([es_creds], timeout=60)
logging.info("Connected to Opensearch: %s" % es_client.info())
return es_client

View File

@ -87,6 +87,11 @@ def get_arguments():
args_parser.add_argument('--port',
help='Opensearch port. Need to ensure that '
'index pattern exists before restore')
args_parser.add_argument("--subpath", help="Add the subpath to the host. "
"That is useful, when the host url contains "
"a slash(/). For example: "
"'http://localhost/opensearch' then the subpath "
"is 'opensearch'.")
args_parser.add_argument('--ca-file',
help='Custom CA certificate file')
args_parser.add_argument("--debug", help="Print more information",