Skip to content

Commit

Permalink
added OpenSearch/Elasticsearch to prompts
Browse files Browse the repository at this point in the history
  • Loading branch information
mmguero committed Oct 10, 2023
1 parent 8ee1fbd commit d42c583
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 26 deletions.
18 changes: 11 additions & 7 deletions scripts/control.py
Original file line number Diff line number Diff line change
Expand Up @@ -1167,13 +1167,13 @@ def authSetup():
),
(
'remoteos',
"Configure remote primary or secondary OpenSearch instance",
"Configure remote primary or secondary OpenSearch/Elasticsearch instance",
False,
False,
),
(
'email',
"Store username/password for email alert sender account",
"Store username/password for OpenSearch Alerting email sender account",
False,
False,
),
Expand Down Expand Up @@ -1632,7 +1632,7 @@ def authSetup():
for instance in ['primary', 'secondary']:
openSearchCredFileName = os.path.join(MalcolmPath, f'.opensearch.{instance}.curlrc')
if YesOrNo(
f'Store username/password for {instance} remote OpenSearch instance?',
f'Store username/password for {instance} remote OpenSearch/Elasticsearch instance?',
default=False,
defaultBehavior=defaultBehavior,
):
Expand All @@ -1643,18 +1643,22 @@ def authSetup():
esPassword = None
esPasswordConfirm = None

loopBreaker = CountUntilException(MaxAskForValueCount, 'Invalid OpenSearch username')
loopBreaker = CountUntilException(
MaxAskForValueCount, 'Invalid OpenSearch/Elasticsearch username'
)
while loopBreaker.increment():
esUsername = AskForString(
"OpenSearch username",
"OpenSearch/Elasticsearch username",
default=prevCurlContents['user'],
defaultBehavior=defaultBehavior,
)
if (len(esUsername) > 0) and (':' not in esUsername):
break
eprint("Username is blank (or contains a colon, which is not allowed)")

loopBreaker = CountUntilException(MaxAskForValueCount, 'Invalid OpenSearch password')
loopBreaker = CountUntilException(
MaxAskForValueCount, 'Invalid OpenSearch/Elasticsearch password'
)
while loopBreaker.increment():
esPassword = AskForPassword(
f"{esUsername} password: ",
Expand Down Expand Up @@ -1683,7 +1687,7 @@ def authSetup():
eprint("Passwords do not match")

esSslVerify = YesOrNo(
'Require SSL certificate validation for OpenSearch communication?',
'Require SSL certificate validation for OpenSearch/Elasticsearch communication?',
default=False,
defaultBehavior=defaultBehavior,
)
Expand Down
24 changes: 14 additions & 10 deletions shared/bin/configure-capture.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,9 +225,9 @@ def input_opensearch_connection_info(
# opensearch protocol and SSL verification mode
opensearch_protocol = "http"
opensearch_ssl_verify = "none"
if d.yesno("OpenSearch connection protocol", yes_label="HTTPS", no_label="HTTP") == Dialog.OK:
if d.yesno("OpenSearch/Elasticsearch connection protocol", yes_label="HTTPS", no_label="HTTP") == Dialog.OK:
opensearch_protocol = "https"
if d.yesno("OpenSearch SSL verification", yes_label="None", no_label="Full") != Dialog.OK:
if d.yesno("OpenSearch/Elasticsearch SSL verification", yes_label="None", no_label="Full") != Dialog.OK:
opensearch_ssl_verify = "full"
return_dict[Constants.BEAT_OS_PROTOCOL] = opensearch_protocol
return_dict[Constants.BEAT_OS_SSL_VERIFY] = opensearch_ssl_verify
Expand All @@ -237,8 +237,8 @@ def input_opensearch_connection_info(
code, values = d.form(
Constants.MSG_CONFIG_GENERIC.format(forwarder),
[
('OpenSearch Host', 1, 1, default_os_host or "", 1, 25, 30, 255),
('OpenSearch Port', 2, 1, default_os_port or "9200", 2, 25, 6, 5),
('OpenSearch/Elasticsearch Host', 1, 1, default_os_host or "", 1, 25, 30, 255),
('OpenSearch/Elasticsearch Port', 2, 1, default_os_port or "9200", 2, 25, 6, 5),
],
)
values = [x.strip() for x in values]
Expand All @@ -255,21 +255,21 @@ def input_opensearch_connection_info(
break

# HTTP/HTTPS authentication
code, http_username = d.inputbox("OpenSearch HTTP/HTTPS server username", init=default_username)
code, http_username = d.inputbox("OpenSearch/Elasticsearch HTTP/HTTPS server username", init=default_username)
if (code == Dialog.CANCEL) or (code == Dialog.ESC):
raise CancelledError
return_dict[Constants.BEAT_HTTP_USERNAME] = http_username.strip()

# make them enter the password twice
while True:
code, http_password = d.passwordbox(
"OpenSearch HTTP/HTTPS server password", insecure=True, init=default_password
"OpenSearch/Elasticsearch HTTP/HTTPS server password", insecure=True, init=default_password
)
if (code == Dialog.CANCEL) or (code == Dialog.ESC):
raise CancelledError

code, http_password2 = d.passwordbox(
"OpenSearch HTTP/HTTPS server password (again)",
"OpenSearch/Elasticsearch HTTP/HTTPS server password (again)",
insecure=True,
init=default_password if (http_password == default_password) else "",
)
Expand All @@ -283,7 +283,7 @@ def input_opensearch_connection_info(
code = d.msgbox(text=Constants.MSG_MESSAGE_ERROR.format("Passwords did not match"))

# test OpenSearch connection
code = d.infobox(Constants.MSG_TESTING_CONNECTION.format("OpenSearch"))
code = d.infobox(Constants.MSG_TESTING_CONNECTION.format("OpenSearch/Elasticsearch"))
retcode, message, output = test_connection(
protocol=return_dict[Constants.BEAT_OS_PROTOCOL],
host=return_dict[Constants.BEAT_OS_HOST],
Expand All @@ -297,10 +297,14 @@ def input_opensearch_connection_info(
ssl_verify=return_dict[Constants.BEAT_OS_SSL_VERIFY],
)
if retcode == 200:
code = d.msgbox(text=Constants.MSG_TESTING_CONNECTION_SUCCESS.format("OpenSearch", retcode, message))
code = d.msgbox(
text=Constants.MSG_TESTING_CONNECTION_SUCCESS.format("OpenSearch/Elasticsearch", retcode, message)
)
else:
code = d.yesno(
text=Constants.MSG_TESTING_CONNECTION_FAILURE.format("OpenSearch", retcode, message, "\n".join(output)),
text=Constants.MSG_TESTING_CONNECTION_FAILURE.format(
"OpenSearch/Elasticsearch", retcode, message, "\n".join(output)
),
yes_label="Ignore Error",
no_label="Start Over",
)
Expand Down
18 changes: 9 additions & 9 deletions shared/bin/pcap_watcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def __init__(self, logger=None):
while (not connected) and (not shuttingDown[0]):
try:
try:
self.logger.info(f"{scriptName}:\tconnecting to OpenSearch {args.opensearchUrl}...")
self.logger.info(f"{scriptName}:\tconnecting to {args.opensearchMode} {args.opensearchUrl}...")

self.openSearchClient = DatabaseClass(
hosts=[args.opensearchUrl],
Expand Down Expand Up @@ -127,11 +127,11 @@ def __init__(self, logger=None):
NewConnectionError,
AuthenticationException,
) as connError:
self.logger.error(f"{scriptName}:\tOpenSearch connection error: {connError}")
self.logger.error(f"{scriptName}:\t{args.opensearchMode} connection error: {connError}")

except Exception as genericError:
self.logger.error(
f"{scriptName}:\tUnexpected exception while connecting to OpenSearch: {genericError}"
f"{scriptName}:\tUnexpected exception while connecting to {args.opensearchMode}: {genericError}"
)

if (not connected) and args.opensearchWaitForHealth:
Expand All @@ -144,7 +144,7 @@ def __init__(self, logger=None):
# if requested, wait for at least "yellow" health in the cluster for the "files" index
while connected and args.opensearchWaitForHealth and (not healthy) and (not shuttingDown[0]):
try:
self.logger.info(f"{scriptName}:\twaiting for OpenSearch to be healthy")
self.logger.info(f"{scriptName}:\twaiting for {args.opensearchMode} to be healthy")
self.openSearchClient.cluster.health(
index=ARKIME_FILES_INDEX,
wait_for_status='yellow',
Expand All @@ -159,7 +159,7 @@ def __init__(self, logger=None):
NewConnectionError,
AuthenticationException,
) as connError:
self.logger.debug(f"{scriptName}:\tOpenSearch health check: {connError}")
self.logger.debug(f"{scriptName}:\t{args.opensearchMode} health check: {connError}")

if not healthy:
time.sleep(1)
Expand Down Expand Up @@ -302,15 +302,15 @@ def main():
metavar='<STR>',
type=str,
default=os.getenv('OPENSEARCH_URL', None),
help='OpenSearch connection string for querying Arkime files index to ignore duplicates',
help='OpenSearch/Elasticsearch connection string for querying Arkime files index to ignore duplicates',
)
parser.add_argument(
'--opensearch-curlrc',
dest='opensearchCurlRcFile',
metavar='<filename>',
type=str,
default=os.getenv('OPENSEARCH_CREDS_CONFIG_FILE', '/var/local/curlrc/.opensearch.primary.curlrc'),
help='cURL.rc formatted file containing OpenSearch connection parameters',
help='cURL.rc formatted file containing OpenSearch/Elasticsearch connection parameters',
)
parser.add_argument(
'--opensearch-ssl-verify',
Expand All @@ -319,7 +319,7 @@ def main():
nargs='?',
const=True,
default=str2bool(os.getenv('OPENSEARCH_SSL_CERTIFICATE_VERIFICATION', default='False')),
help="Verify SSL certificates for OpenSearch",
help="Verify SSL certificates for OpenSearch/Elasticsearch",
)
parser.add_argument(
'--opensearch-mode',
Expand All @@ -338,7 +338,7 @@ def main():
parser.add_argument(
'--opensearch-wait',
dest='opensearchWaitForHealth',
help="Wait for OpenSearch to be healthy before starting",
help="Wait for OpenSearch/Elasticsearch to be healthy before starting",
metavar='true|false',
type=str2bool,
nargs='?',
Expand Down

0 comments on commit d42c583

Please sign in to comment.