Created
December 13, 2018 12:19
-
-
Save dlopes7/d31ca3a740684d5882445f63a26d3de2 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env python | |
import requests | |
APPD_BASE_URL = 'http://controller.com:8090' | |
APPD_AUTH = ('admin@customer1', 'password') | |
APP = 23 | |
MINUTES = 5 | |
s = requests.Session() | |
def login(): | |
url = '{}/auth?action=login'.format(APPD_BASE_URL) | |
s.get(url, auth=APPD_AUTH) | |
def rest(uri, body=None, headers={}, method='GET', internal=False, params=None): | |
if internal: | |
if not s.cookies.get('X-CSRF-TOKEN'): | |
login() | |
headers['X-CSRF-TOKEN'] = s.cookies.get('X-CSRF-TOKEN') | |
url = '{}/{}'.format(APPD_BASE_URL, uri) | |
return s.request(method, url, auth=APPD_AUTH, headers=headers, json=body, params=params) | |
def get_snapshots(application, minutes_ago): | |
params = { | |
'output': 'json', | |
'need-props': 'true', | |
'time-range-type': 'BEFORE_NOW', | |
'duration-in-mins': minutes_ago | |
} | |
url = 'controller/rest/applications/{}/request-snapshots'.format(application) | |
return rest(url, params=params).json() | |
def get_segments(requestGUID, minutes_ago): | |
params = {"guids":[requestGUID], | |
"needExitCalls": 'false', | |
"needProps":'false', | |
"rangeSpecifier":{ | |
"type":"BEFORE_NOW", | |
"startTime":1, | |
"endTime":1, | |
"durationInMinutes":minutes_ago} | |
} | |
url = 'restui/snapshot/getFilteredRSDListData' | |
return rest(url, body=params, internal=True, method='POST').json() | |
def get_call_graph(segmentID, minutes_ago): | |
url = 'restui/snapshot/getCallGraphRoot' | |
params = { | |
'rsdId': segmentID, | |
'timeRange': 'Custom_Time_Range.BEFORE_NOW.1.1.{}'.format(minutes_ago) | |
} | |
return rest(url, params=params).json() | |
def get_dashboards(): | |
url = 'controller/restui/dashboards/getAllDashboardsByType/false' | |
print(rest(url, internal=True)) | |
def print_callstack(callstack, spaces=''): | |
print(spaces, '{}/{}'.format(callstack['className'], callstack['methodName'])) | |
if callstack['children']: | |
i = 1 | |
for children in callstack['children']: | |
print_callstack(children, spaces=' ' * i) | |
i += 1 | |
def main(): | |
try: | |
for snapshot in get_snapshots(APP, MINUTES): | |
for segment in get_segments(snapshot['requestGUID'], MINUTES): | |
for callstack in get_call_graph(segment['id'], MINUTES): | |
print_callstack(callstack) | |
except Exception as e: | |
print(e) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment