-
Notifications
You must be signed in to change notification settings - Fork 194
Security groups request ids #935
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
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 @@ | ||
| """Audit Logs.""" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| """Get Audit 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', 'label', 'date', 'metadata'] | ||
|
|
||
|
|
||
| @click.command() | ||
| @click.option('--date-min', '-d', | ||
| help='The earliest date we want to search for audit logs in mm/dd/yyyy format.') | ||
| @click.option('--date-max', '-D', | ||
| help='The latest date we want to search for audit logs in mm/dd/yyyy format.') | ||
| @click.option('--obj_event', '-e', | ||
| help="The event we want to get audit logs for") | ||
| @click.option('--obj_id', '-i', | ||
| help="The id of the object we want to get audit logs for") | ||
| @click.option('--obj_type', '-t', | ||
| help="The type of the object we want to get audit logs for") | ||
| @click.option('--utc_offset', '-z', | ||
| help="UTC Offset for seatching with dates. The default is -0000") | ||
|
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.
|
||
| @environment.pass_env | ||
| def cli(env, date_min, date_max, obj_event, obj_id, obj_type, utc_offset): | ||
| """Get Audit Logs""" | ||
| 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) | ||
|
|
||
| table = formatting.Table(COLUMNS) | ||
| table.align['metadata'] = "l" | ||
|
|
||
| for log in logs: | ||
| try: | ||
| metadata = json.dumps(json.loads(log['metaData']), indent=4, sort_keys=True) | ||
| except ValueError: | ||
| metadata = log['metaData'] | ||
|
|
||
| table.add_row([log['eventName'], log['label'], log['eventCreateDate'], metadata]) | ||
|
|
||
| env.fout(table) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| """Get Audit 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 Audit 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') | ||
| @environment.pass_env | ||
| def get_by_request_id(env, request_id): | ||
| """Search for event logs by 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. Having it be called |
||
| 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) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,6 +14,8 @@ | |
| 'interface', | ||
| 'ipAddress', ] | ||
|
|
||
| REQUEST_COLUMNS = ['requestId'] | ||
|
|
||
|
|
||
| @click.command() | ||
| @click.argument('securitygroup_id') | ||
|
|
@@ -95,6 +97,11 @@ def add(env, securitygroup_id, network_component, server, interface): | |
| if not success: | ||
| raise exceptions.CLIAbort("Could not attach network component") | ||
|
|
||
| table = formatting.Table(REQUEST_COLUMNS) | ||
| table.add_row([success['requestId']]) | ||
|
|
||
| env.fout(table) | ||
|
|
||
|
|
||
| @click.command() | ||
| @click.argument('securitygroup_id') | ||
|
|
@@ -118,6 +125,11 @@ def remove(env, securitygroup_id, network_component, server, interface): | |
| if not success: | ||
| raise exceptions.CLIAbort("Could not detach network component") | ||
|
|
||
| table = formatting.Table(REQUEST_COLUMNS) | ||
| table.add_row([success['requestId']]) | ||
|
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. I'd rename the |
||
|
|
||
| env.fout(table) | ||
|
|
||
|
|
||
| def _validate_args(network_component, server, interface): | ||
| use_server = bool(server and interface and not network_component) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,127 @@ | ||
| getAllObjects = [ | ||
| { | ||
| 'accountId': 100, | ||
| 'eventCreateDate': '2017-10-23T14:22:36.221541-05:00', | ||
| 'eventName': 'Disable Port', | ||
| 'ipAddress': '192.168.0.1', | ||
| 'label': 'test.softlayer.com', | ||
| 'metaData': '', | ||
| 'objectId': 300, | ||
| 'objectName': 'CCI', | ||
| 'traceId': '100', | ||
| 'userId': '', | ||
| 'userType': 'SYSTEM' | ||
| }, | ||
| { | ||
| 'accountId': 100, | ||
| 'eventCreateDate': '2017-10-18T09:40:41.830338-05:00', | ||
| 'eventName': 'Security Group Rule Added', | ||
| 'ipAddress': '192.168.0.1', | ||
| 'label': 'test.softlayer.com', | ||
| 'metaData': '{"securityGroupId":"200",' | ||
| '"securityGroupName":"test_SG",' | ||
| '"networkComponentId":"100",' | ||
| '"networkInterfaceType":"public",' | ||
| '"requestId":"53d0b91d392864e062f4958",' | ||
| '"rules":[{"ruleId":"100",' | ||
| '"remoteIp":null,"remoteGroupId":null,"direction":"ingress",' | ||
| '"ethertype":"IPv4",' | ||
| '"portRangeMin":2000,"portRangeMax":2001,"protocol":"tcp"}]}', | ||
| 'objectId': 300, | ||
| 'objectName': 'CCI', | ||
| 'traceId': '59e767e9c2184', | ||
| 'userId': 400, | ||
| 'userType': 'CUSTOMER', | ||
| 'username': 'user' | ||
| }, | ||
| { | ||
| 'accountId': 100, | ||
| 'eventCreateDate': '2017-10-18T09:40:32.238869-05:00', | ||
| 'eventName': 'Security Group Added', | ||
| 'ipAddress': '192.168.0.1', | ||
| 'label': 'test.softlayer.com', | ||
| 'metaData': '{"securityGroupId":"200",' | ||
| '"securityGroupName":"test_SG",' | ||
| '"networkComponentId":"100",' | ||
| '"networkInterfaceType":"public",' | ||
| '"requestId":"96c9b47b9e102d2e1d81fba"}', | ||
| 'objectId': 300, | ||
| 'objectName': 'CCI', | ||
| 'traceId': '59e767e03a57e', | ||
| 'userId': 400, | ||
| 'userType': 'CUSTOMER', | ||
| 'username': 'user' | ||
| }, | ||
| { | ||
| 'accountId': 100, | ||
| 'eventCreateDate': '2017-10-18T10:42:13.089536-05:00', | ||
| 'eventName': 'Security Group Rule(s) Removed', | ||
| 'ipAddress': '192.168.0.1', | ||
| 'label': 'test_SG', | ||
| 'metaData': '{"requestId":"2abda7ca97e5a1444cae0b9",' | ||
| '"rules":[{"ruleId":"800",' | ||
| '"remoteIp":null,"remoteGroupId":null,"direction":"ingress",' | ||
| '"ethertype":"IPv4",' | ||
| '"portRangeMin":2000,"portRangeMax":2001,"protocol":"tcp"}]}', | ||
| 'objectId': 700, | ||
| 'objectName': 'Security Group', | ||
| 'traceId': '59e7765515e28', | ||
| 'userId': 400, | ||
| 'userType': 'CUSTOMER', | ||
| 'username': 'user' | ||
| }, | ||
| { | ||
| 'accountId': 100, | ||
| 'eventCreateDate': '2017-10-18T10:42:11.679736-05:00', | ||
| 'eventName': 'Network Component Removed from Security Group', | ||
| 'ipAddress': '192.168.0.1', | ||
| 'label': 'test_SG', | ||
| 'metaData': '{"requestId":"6b9a87a9ab8ac9a22e87a00",' | ||
| '"fullyQualifiedDomainName":"test.softlayer.com",' | ||
| '"networkComponentId":"100",' | ||
| '"networkInterfaceType":"public"}', | ||
| 'objectId': 700, | ||
| 'objectName': 'Security Group', | ||
| 'traceId': '59e77653a1e5f', | ||
| 'userId': 400, | ||
| 'userType': 'CUSTOMER', | ||
| 'username': 'user' | ||
| }, | ||
| { | ||
| 'accountId': 100, | ||
| 'eventCreateDate': '2017-10-18T10:41:49.802498-05:00', | ||
| 'eventName': 'Security Group Rule(s) Added', | ||
| 'ipAddress': '192.168.0.1', | ||
| 'label': 'test_SG', | ||
| 'metaData': '{"requestId":"0a293c1c3e59e4471da6495",' | ||
| '"rules":[{"ruleId":"800",' | ||
| '"remoteIp":null,"remoteGroupId":null,"direction":"ingress",' | ||
| '"ethertype":"IPv4",' | ||
| '"portRangeMin":2000,"portRangeMax":2001,"protocol":"tcp"}]}', | ||
| 'objectId': 700, | ||
| 'objectName': 'Security Group', | ||
| 'traceId': '59e7763dc3f1c', | ||
| 'userId': 400, | ||
| 'userType': 'CUSTOMER', | ||
| 'username': 'user' | ||
| }, | ||
| { | ||
| 'accountId': 100, | ||
| 'eventCreateDate': '2017-10-18T10:41:42.176328-05:00', | ||
| 'eventName': 'Network Component Added to Security Group', | ||
| 'ipAddress': '192.168.0.1', | ||
| 'label': 'test_SG', | ||
| 'metaData': '{"requestId":"4709e02ad42c83f80345904",' | ||
| '"fullyQualifiedDomainName":"test.softlayer.com",' | ||
| '"networkComponentId":"100",' | ||
| '"networkInterfaceType":"public"}', | ||
| 'objectId': 700, | ||
| 'objectName': 'Security Group', | ||
| 'traceId': '59e77636261e7', | ||
| 'userId': 400, | ||
| 'userType': 'CUSTOMER', | ||
| 'username': 'user' | ||
| } | ||
| ] | ||
|
|
||
| getAllEventObjectNames = ['CCI', 'Security Group'] |
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.
All of these other options still need to be switched over to use
-instead of_as well