forked from softlayer/softlayer-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Security groups request ids #1
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
Open
fisherma91
wants to merge
17
commits into
master
Choose a base branch
from
security-groups-request-ids
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
54f72c1
security-groups-request-ids : Add output for RequestIDs
fisherma91 4c0badf
security-groups-request-ids : Add output for RequestIDs
fisherma91 7768a83
security-groups-request-ids : Add output for RequestIDs
fisherma91 d3650de
security-groups-request-ids : Add output for RequestIDs
fisherma91 f4bc42f
security-groups-request-ids : Add output for RequestIDs
fisherma91 d7a736f
security-groups-request-ids : Add output for RequestIDs
fisherma91 d851de6
security-groups-request-ids : Add output for RequestIDs
fisherma91 4228058
security-groups-request-ids : Add output for RequestIDs
fisherma91 9d04a8e
security-groups-request-ids : Add output for RequestIDs
fisherma91 a3406a1
security-groups-request-ids : Add output for RequestIDs
fisherma91 884d117
security-groups-request-ids : Add output for RequestIDs
fisherma91 7c25d97
security-groups-request-ids : Add output for RequestIDs
fisherma91 265460a
security-groups-request-ids : Add output for RequestIDs
fisherma91 a453d6d
Merge branch 'master' into security-groups-request-ids
fisherma91 01ee771
security-groups-request-ids : Add output for RequestIDs
fisherma91 3a72d7f
security-groups-request-ids : Add output for RequestIDs
fisherma91 6333687
Major refactoring of audit log code
fisherma91 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| """Audit Logs.""" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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") | ||
| @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) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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""" | ||
| 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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'] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
👍 I like the key sorting, good idea.