-
Notifications
You must be signed in to change notification settings - Fork 194
Event Log improvements #1103
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
Event Log improvements #1103
Changes from all commits
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 |
---|---|---|
|
@@ -27,13 +27,16 @@ | |
help="UTC Offset for searching with dates. The default is -0000") | ||
@click.option('--metadata/--no-metadata', default=False, | ||
help="Display metadata if present") | ||
@click.option('--limit', '-l', default=30, | ||
help="How many results to get in one api call, default is 30.") | ||
@environment.pass_env | ||
def cli(env, date_min, date_max, obj_event, obj_id, obj_type, utc_offset, metadata): | ||
def cli(env, date_min, date_max, obj_event, obj_id, obj_type, utc_offset, metadata, limit): | ||
"""Get Event Logs""" | ||
|
||
mgr = SoftLayer.EventLogManager(env.client) | ||
usrmgr = SoftLayer.UserManager(env.client) | ||
request_filter = mgr.build_filter(date_min, date_max, obj_event, obj_id, obj_type, utc_offset) | ||
logs = mgr.get_event_logs(request_filter) | ||
logs = mgr.get_event_logs(request_filter, log_limit=limit) | ||
|
||
if logs is None: | ||
env.fout('None available.') | ||
|
@@ -43,11 +46,19 @@ def cli(env, date_min, date_max, obj_event, obj_id, obj_type, utc_offset, metada | |
COLUMNS.append('metadata') | ||
|
||
table = formatting.Table(COLUMNS) | ||
|
||
if metadata: | ||
table.align['metadata'] = "l" | ||
|
||
for log in logs: | ||
user = log['userType'] | ||
label = '' | ||
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.
|
||
|
||
try: | ||
label = log['label'] | ||
except KeyError: | ||
pass # label is already at default value. | ||
|
||
if user == "CUSTOMER": | ||
user = usrmgr.get_user(log['userId'], "mask[username]")['username'] | ||
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. Just noticed in testing that this line generates a large number of redundant API calls. Would be worth cacheing the results so we only have to look up each user once. I don't want to change this to just get all users once because some accounts have a lot of users which would generate its own problems. If you think thats out of the scope of this pull request thats ok, I can make an issue about it and deal with it later. |
||
if metadata: | ||
|
@@ -58,9 +69,9 @@ def cli(env, date_min, date_max, obj_event, obj_id, obj_type, utc_offset, metada | |
except ValueError: | ||
metadata_data = log['metaData'] | ||
|
||
table.add_row([log['eventName'], log['label'], log['objectName'], | ||
table.add_row([log['eventName'], label, log['objectName'], | ||
log['eventCreateDate'], user, metadata_data]) | ||
else: | ||
table.add_row([log['eventName'], log['label'], log['objectName'], | ||
table.add_row([log['eventName'], label, log['objectName'], | ||
log['eventCreateDate'], user]) | ||
env.fout(table) |
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.
https://click.palletsprojects.com/en/6.x/api/#click.Option
use
show_default=True
instead of adding it manually to the help message