Skip to content

Commit

Permalink
Improve output of log opensearch (#662)
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Berendt <[email protected]>
  • Loading branch information
berendt authored Oct 31, 2023
1 parent 1ff804a commit dba7597
Showing 1 changed file with 23 additions and 10 deletions.
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)

0 comments on commit dba7597

Please sign in to comment.