Skip to content

Instantly share code, notes, and snippets.

@dlopes7
Created December 8, 2018 23:09
Show Gist options
  • Save dlopes7/bfea4002ca531bf87ccbe3a937cb95b3 to your computer and use it in GitHub Desktop.
Save dlopes7/bfea4002ca531bf87ccbe3a937cb95b3 to your computer and use it in GitHub Desktop.
#!/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