Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve output of log opensearch #662

Merged
merged 1 commit into from
Oct 31, 2023
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
33 changes: 23 additions & 10 deletions osism/commands/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,18 @@ def take_action(self, parsed_args):
class Opensearch(Command):
def get_parser(self, prog_name):
parser = super(Opensearch, self).get_parser(prog_name)
parser.add_argument(
"--verbose",
default=False,
help="Verbose output",
action="store_true",
)
return parser

def take_action(self, parsed_args):
session = PromptSession(history=FileHistory("/tmp/.opensearch.history"))
verbose = parsed_args.verbose

while True:
query = session.prompt(">>> ")
if query in ["Exit", "exit", "EXIT"]:
Expand All @@ -93,14 +101,19 @@ def take_action(self, parsed_args):
if "hits" in data:
for hit in data["hits"]["hits"]:
source = hit["_source"]
if "timestamp" not in source:
source["timestamp"] = source["@timestamp"]

if "programname" in source:
print(
f"{source['timestamp']} | {source['Hostname']} | {source['programname']} | {source['Payload']}"
)
if verbose:
if "timestamp" not in source:
source["timestamp"] = source["@timestamp"]

if "programname" in source:
print(
f"{source['timestamp']} | {source['Hostname']} | {source['programname']} | {source['Payload']}"
)
else:
print(
f"{source['timestamp']} | {source['Hostname']} | {source['Payload']}"
)
else:
print(
f"{source['timestamp']} | {source['Hostname']} | {source['Payload']}"
)
print(source["Payload"])
else:
print(data)