-
Notifications
You must be signed in to change notification settings - Fork 194
Security groups request ids #1099
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
Changes from all commits
54f72c1
4c0badf
7768a83
d3650de
f4bc42f
d7a736f
d851de6
4228058
9d04a8e
a3406a1
884d117
7c25d97
265460a
a453d6d
01ee771
3a72d7f
6333687
6ae6814
495dcc2
e2648c6
5a406b4
8bbbe78
82574e0
5320df0
5aee15e
bb1717c
8bb2b1e
004e5af
d21cbd1
6a16076
62e66b7
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
"""Event Logs.""" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
"""Get Event Logs.""" | ||
# :license: MIT, see LICENSE for more details. | ||
|
||
import json | ||
|
||
import click | ||
|
||
import SoftLayer | ||
from SoftLayer.CLI import environment | ||
from SoftLayer.CLI import formatting | ||
|
||
COLUMNS = ['event', 'object', 'type', 'date', 'username'] | ||
|
||
|
||
@click.command() | ||
@click.option('--date-min', '-d', | ||
help='The earliest date we want to search for event logs in mm/dd/yyyy format.') | ||
@click.option('--date-max', '-D', | ||
help='The latest date we want to search for event logs in mm/dd/yyyy format.') | ||
@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") | ||
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.
|
||
@click.option('--obj-type', '-t', | ||
help="The type of the object we want to get event logs for") | ||
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.
|
||
@click.option('--utc-offset', '-z', | ||
help="UTC Offset for searching with dates. The default is -0000") | ||
@click.option('--metadata/--no-metadata', default=False, | ||
help="Display metadata if present") | ||
@environment.pass_env | ||
def cli(env, date_min, date_max, obj_event, obj_id, obj_type, utc_offset, metadata): | ||
"""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) | ||
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. get_event_logs should likely return an empty list at least.
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. This should be taken care of with the latest push. |
||
|
||
if logs is None: | ||
env.fout('None available.') | ||
return | ||
|
||
if metadata and 'metadata' not in COLUMNS: | ||
COLUMNS.append('metadata') | ||
|
||
table = formatting.Table(COLUMNS) | ||
if metadata: | ||
table.align['metadata'] = "l" | ||
|
||
for log in logs: | ||
user = log['userType'] | ||
if user == "CUSTOMER": | ||
user = usrmgr.get_user(log['userId'], "mask[username]")['username'] | ||
if metadata: | ||
try: | ||
metadata_data = json.dumps(json.loads(log['metaData']), indent=4, sort_keys=True) | ||
if env.format == "table": | ||
metadata_data = metadata_data.strip("{}\n\t") | ||
except ValueError: | ||
metadata_data = log['metaData'] | ||
|
||
table.add_row([log['eventName'], log['label'], log['objectName'], | ||
log['eventCreateDate'], user, metadata_data]) | ||
else: | ||
table.add_row([log['eventName'], log['label'], log['objectName'], | ||
log['eventCreateDate'], user]) | ||
env.fout(table) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
"""Get Event Log Types.""" | ||
# :license: MIT, see LICENSE for more details. | ||
|
||
import click | ||
|
||
import SoftLayer | ||
from SoftLayer.CLI import environment | ||
from SoftLayer.CLI import formatting | ||
|
||
COLUMNS = ['types'] | ||
|
||
|
||
@click.command() | ||
@environment.pass_env | ||
def cli(env): | ||
"""Get Event Log Types""" | ||
mgr = SoftLayer.EventLogManager(env.client) | ||
|
||
event_log_types = mgr.get_event_log_types() | ||
|
||
table = formatting.Table(COLUMNS) | ||
|
||
for event_log_type in event_log_types: | ||
table.add_row([event_log_type]) | ||
|
||
env.fout(table) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
"""Get event logs relating to security groups""" | ||
# :license: MIT, see LICENSE for more details. | ||
|
||
import json | ||
|
||
import click | ||
|
||
import SoftLayer | ||
from SoftLayer.CLI import environment | ||
from SoftLayer.CLI import formatting | ||
|
||
COLUMNS = ['event', 'label', 'date', 'metadata'] | ||
|
||
|
||
@click.command() | ||
@click.argument('request_id') | ||
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. 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? |
||
@environment.pass_env | ||
def get_by_request_id(env, request_id): | ||
"""Search for event logs by request id""" | ||
mgr = SoftLayer.NetworkManager(env.client) | ||
|
||
logs = mgr.get_event_logs_by_request_id(request_id) | ||
|
||
table = formatting.Table(COLUMNS) | ||
table.align['metadata'] = "l" | ||
|
||
for log in logs: | ||
metadata = json.dumps(json.loads(log['metaData']), indent=4, sort_keys=True) | ||
|
||
table.add_row([log['eventName'], log['label'], log['eventCreateDate'], metadata]) | ||
|
||
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.
TODO:
Add a way to limit results. Something like in
slcli vs list
maybe.