Skip to content

Conversation

erick-sapp
Copy link
Contributor

This completes some of the requested work on the other current pull request.

fisherma91 and others added 25 commits August 23, 2017 14:59
The python api will now output a table with requestIDs for specific calls to security groups apis
Fix unit tests
Fix code style issues
Add functionality to get event logs to slcli
Refactor Event Log Code
Fix Unit Tests
Add Unit Tests
Fix Code Styling
Remove unneeded code left over from refactoring
Fix incorrect package name
Change public facing name to Audit Logs
Add functionality to get event log types
Fix ordering of test expecations to be Actual then Expected
Add functionality to filter by eventName
Add functionality to filter by dates
Add request id search functionality
change date_min to date-min in click args
change date_max to date-max in click args
change how the event log client is initialized
move filter building code into event log manager
set default utc offset to +0000
move date parsing code into utils
add ability to get event logs by type
add ability to get event logs by name
move requestID searching into Security Groups code
Overhaul unit tests
…event-log which matches the API and function names.
@allmightyspiff allmightyspiff changed the title Finishfish Security groups request ids Feb 5, 2019
@allmightyspiff
Copy link
Member

Finishes up #935

@coveralls
Copy link

coveralls commented Feb 5, 2019

Coverage Status

Coverage increased (+0.1%) to 90.781% when pulling 62e66b7 on erick-sapp:finishfish into 0b83362 on softlayer:master.

Copy link
Member

@allmightyspiff allmightyspiff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK as is, but I think i'll create a few more issues off this one to expand the event-log cli features

mgr = SoftLayer.EventLogManager(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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

get_event_logs should likely return an empty list at least.

$ ./slcli event-log get -t "Bare Metal Instance"
An unexpected error has occured:
Traceback (most recent call last):
  File "C:\Users\allmi\Source\softlayer-python\SoftLayer\CLI\core.py", line 182, in main
    cli.main(**kwargs)
  File "C:\Users\allmi\Source\py36\lib\site-packages\click\core.py", line 717, in main
    rv = self.invoke(ctx)
  File "C:\Users\allmi\Source\py36\lib\site-packages\click\core.py", line 1137, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "C:\Users\allmi\Source\py36\lib\site-packages\click\core.py", line 1137, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "C:\Users\allmi\Source\py36\lib\site-packages\click\core.py", line 956, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "C:\Users\allmi\Source\py36\lib\site-packages\click\core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "C:\Users\allmi\Source\py36\lib\site-packages\click\decorators.py", line 64, in new_func
    return ctx.invoke(f, obj, *args, **kwargs)
  File "C:\Users\allmi\Source\py36\lib\site-packages\click\core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "C:\Users\allmi\Source\softlayer-python\SoftLayer\CLI\event_log\get.py", line 39, in cli
    for log in logs:
TypeError: 'NoneType' object is not iterable

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be taken care of with the latest push.

@click.option('--obj-event', '-e',
help="The event we want to get event logs for")
@click.option('--obj-id', '-i',
help="The id of the object we want to get event logs for")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

help="The id of the object (server, storage, user, etc) to get logs for"

@click.option('--obj-id', '-i',
help="The id of the object we want to get event logs for")
@click.option('--obj-type', '-t',
help="The type of the object we want to get event logs for")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

help="The type of the object we want to get event logs for. See slcli event-log types for a list"

COLUMNS = ['event', 'label', 'date', 'metadata']


@click.command()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO:
Add a way to limit results. Something like in slcli vs list maybe.



@click.command()
@click.argument('request_id')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: I'm not really sure using the request_id here is useful, as that doesn't seem to be a very accessible piece of information for a user to get. Maybe it would be better to get the logs by the security group id?

def __init__(self, client):
self.event_log = client['Event_Log']

def get_event_logs(self, request_filter):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: event_log.getAllObjects should be called with self.event_log.getAllObjects(filter=request_filter, iter=True) and likely needs to support limits so more than the default number of objects can be pulled down.

Copy link
Contributor

@acamacho82 acamacho82 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to see some improvements in the table, maybe they can be added later

from SoftLayer.CLI import environment
from SoftLayer.CLI import formatting

COLUMNS = ['event', 'label', 'date', 'metadata']
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • It is a little annoying when looking the table and there are metadata information on it, maybe it would be better if metadata is an optional column or you could also create a new command which could be used to see the metadata information through the traceId value, similar to slcli vs detail

  • I suggest you to remove the braces { } if metadata information will be in the table.

  • I suggest to rename label by object and recommend to add object type and username columns to the table, this would help the customers to identify what user made the action/event and in what kind of object, for example I remember that a customer wanted to know what user powered on/off an specific virtual server

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With commit d21cbd1, these suggestions should be implemented.

@allmightyspiff allmightyspiff merged commit c822afc into softlayer:master Feb 13, 2019
@allmightyspiff allmightyspiff mentioned this pull request Feb 15, 2019
allmightyspiff added a commit to allmightyspiff/softlayer-python that referenced this pull request Mar 27, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants