Esempio n. 1
0
# clength = '26,592'

# if ',' in clength:
# 	clength = clength.replace(',','')
# print(clength)

# myl = ['a', 'a','c']

# print(len(myl))

# =========================================================
import json
import time
from jfunc import run_cmd
import ast
json_op = run_cmd('''/Users/jpatel/Documents/Techdocs/edgegrid-curl/egcurl -sSk  https://akab-7elybsdhwkk3wd56-yuvntpsfnkajbmvm.luna.akamaiapis.net/orion/v2/customers/424715/devices/28/connection-history ''')
#json_op = '''[{"logId":"2870584","akamaiDeviceId":"28","akamaiCustomerId":"424715","edgeIp":"2.16.165.31","gatewayIp":"1.1.1.1","firstConnectedTime":"2016-05-04T05:10:35+0000","lastConnectedTime":"2016-05-04T13:03:02+0000"},{"logId":"2870565","akamaiDeviceId":"28","akamaiCustomerId":"424715","edgeIp":"2.16.165.31","gatewayIp":"1.1.1.1","firstConnectedTime":"2016-05-03T23:24:02+0000","lastConnectedTime":"2016-05-04T04:12:57+0000"},{"logId":"2870548","akamaiDeviceId":"28","akamaiCustomerId":"424715","edgeIp":"2.16.165.31","gatewayIp":"1.1.1.1","firstConnectedTime":"2016-05-03T19:46:47+0000","lastConnectedTime":"2016-05-03T22:27:02+0000"},{"logId":"2870468","akamaiDeviceId":"28","akamaiCustomerId":"424715","edgeIp":"2.16.165.31","gatewayIp":"1.1.1.1","firstConnectedTime":"2016-05-03T11:37:21+0000","lastConnectedTime":"2016-05-03T11:37:21+0000"},{"logId":"2869907","akamaiDeviceId":"28","akamaiCustomerId":"424715","edgeIp":"2.16.165.31","gatewayIp":"1.1.1.1","firstConnectedTime":"2016-05-02T02:29:54+0000","lastConnectedTime":"2016-05-02T02:29:54+0000"},{"logId":"2869834","akamaiDeviceId":"28","akamaiCustomerId":"424715","edgeIp":"2.16.165.31","gatewayIp":"1.1.1.1","firstConnectedTime":"2016-05-01T23:21:36+0000","lastConnectedTime":"2016-05-01T23:23:43+0000"},{"logId":"2869191","akamaiDeviceId":"28","akamaiCustomerId":"424715","edgeIp":"2.16.165.31","gatewayIp":"1.1.1.1","firstConnectedTime":"2016-05-01T02:55:46+0000","lastConnectedTime":"2016-05-01T02:59:49+0000"},{"logId":"2868946","akamaiDeviceId":"28","akamaiCustomerId":"424715","edgeIp":"2.16.165.31","gatewayIp":"1.1.1.1","firstConnectedTime":"2016-04-30T19:48:39+0000","lastConnectedTime":"2016-04-30T19:48:39+0000"},{"logId":"2868435","akamaiDeviceId":"28","akamaiCustomerId":"424715","edgeIp":"2.16.165.31","gatewayIp":"1.1.1.1","firstConnectedTime":"2016-04-30T10:38:15+0000","lastConnectedTime":"2016-04-30T10:38:15+0000"},{"logId":"2868295","akamaiDeviceId":"28","akamaiCustomerId":"424715","edgeIp":"2.16.165.31","gatewayIp":"1.1.1.1","firstConnectedTime":"2016-04-30T08:34:10+0000","lastConnectedTime":"2016-04-30T08:34:10+0000"},{"logId":"2868229","akamaiDeviceId":"28","akamaiCustomerId":"424715","edgeIp":"2.16.165.31","gatewayIp":"1.1.1.1","firstConnectedTime":"2016-04-30T06:30:59+0000","lastConnectedTime":"2016-04-30T06:31:59+0000"},{"logId":"2868228","akamaiDeviceId":"28","akamaiCustomerId":"424715","edgeIp":"2.16.165.31","gatewayIp":"1.1.1.1","firstConnectedTime":"2016-04-30T05:29:55+0000","lastConnectedTime":"2016-04-30T05:31:55+0000"},{"logId":"2868225","akamaiDeviceId":"28","akamaiCustomerId":"424715","edgeIp":"2.16.165.31","gatewayIp":"1.1.1.1","firstConnectedTime":"2016-04-30T03:31:46+0000","lastConnectedTime":"2016-04-30T03:31:46+0000"},{"logId":"2868221","akamaiDeviceId":"28","akamaiCustomerId":"424715","edgeIp":"2.16.165.31","gatewayIp":"1.1.1.1","firstConnectedTime":"2016-04-30T01:27:28+0000","lastConnectedTime":"2016-04-30T01:27:28+0000"},{"logId":"2868212","akamaiDeviceId":"28","akamaiCustomerId":"424715","edgeIp":"2.16.165.31","gatewayIp":"1.1.1.1","firstConnectedTime":"2016-04-29T23:24:10+0000","lastConnectedTime":"2016-04-29T23:27:35+0000"},{"logId":"2868203","akamaiDeviceId":"28","akamaiCustomerId":"424715","edgeIp":"2.16.165.31","gatewayIp":"1.1.1.1","firstConnectedTime":"2016-04-29T17:40:52+0000","lastConnectedTime":"2016-04-29T22:20:00+0000"}]'''

# if '[' or ']' in json_op:
# 	json_op = json_op.replace('[','')
# 	json_op = json_op.replace(']','')
# 	json_op = json_op.replace('},','};')
# 	json_list = json_op.split(';')
# 	# print(json_list[0])
# 	for i in range(0,len(json_list)):
# 		dict_conn_history = json.loads(json_list[i])
# 		print ('lastConnected from connection-history -- ',dict_conn_history['lastConnectedTime'])

print(ast.literal_eval(json_op))   #    MUCH BETTER WAY TO LITERALLY CONVERT A FORMATTED STRING -- http://stackoverflow.com/questions/3622643/python-convert-formatted-string-to-list

# =========================================================
Esempio n. 2
0
	df1.set_index(['vip'], inplace = True)
	df1['physregion'] = df1['physregion'].str.replace(',','')
	# # print(df1[df1['vip'] == '120.29.145.227'])  # Works if index is not set
	# print (df1.ix['120.29.145.227'])  # works if index is set
	# print(df1.loc['120.29.145.227'])  # works if index is set	
	tempdf1 = df1.ix[edge_vip]
	print('Machines behind the VIP: \n', tempdf1)
	edge_reg_str = str(tempdf1.iloc[0][1])
	reg_df1 = region_info(edge_reg_str)
	print('\nEdge Region:  ',edge_reg_str, reg_df1['city'], reg_df1['country'])

	print('\n========================================================')
	# print(tempdf1.iloc[0][0])
	cmd1 = 'gwsh -i /Users/jpatel/.ssh/deployed/2016-04-18 -l testgrp ' + tempdf1.iloc[0][0] + '  /a/bin/qed /ipsecd_endpoint w9=' + endpoint_id 
	print('Running on first machine in above list: ', cmd1)
	op1 = run_cmd(cmd1)
	print(op1)

	df2 = qed_string_to_pd(op1)
	df2.set_index('machineIP', inplace = True)
	edg = df2['natPort'].idxmax()
	dev_id = df2.ix[edg]['id']
	print('\nFound the machineIP with a valid NAT port: ', edg)
	print('Associated device ID is: ', dev_id)
	print('\n========================================================')
	cmd2 = 'gwsh -i /Users/jpatel/.ssh/deployed/2016-04-18 -l testgrp ' + df2['natPort'].idxmax() + ' /a/bin/tfetch -qc sripd_assignments_tunnel_gtwy'
	print('Running on  above machine: ', cmd2, '\n')
	op2 = run_cmd(cmd2)

	df3 = tfetch_string_to_pd(op2)
	df3.set_index('deviceID', inplace= True)
Esempio n. 3
0
#! /usr/bin/env python3

from jfunc import run_cmd
import json
import time
import ast 

if __name__ == "__main__":
	
	date_UTC = run_cmd('date -u')
	list_of_tuple = []
	
	# JAY:
	# jay_conn_status = run_cmd('''/Users/jpatel/Documents/Techdocs/edgegrid-curl/egcurl -sSk  https://akab-p5cgfagtzkkfjy74-qgv27om5urjpzcs4.luna.akamaiapis.net/orion/v2/customers/432452/devices/2859560/connection-status | python -mjson.tool''')
	# jay_conn_history = run_cmd('''/Users/jpatel/Documents/Techdocs/edgegrid-curl/egcurl -sSk  https://akab-p5cgfagtzkkfjy74-qgv27om5urjpzcs4.luna.akamaiapis.net/orion/v2/customers/432452/devices/2859560/connection-history''')
	# list_of_tuple.append((jay_conn_status,jay_conn_history))
	
	# OBS:
	for devid in ['31','26','23','27']:
		obs_conn_status = run_cmd('''/Users/jpatel/Documents/Techdocs/edgegrid-curl/egcurl -sSk https://akab-7elybsdhwkk3wd56-yuvntpsfnkajbmvm.luna.akamaiapis.net/orion/v2/customers/424715/devices/'''+devid+'''/connection-status   | python -mjson.tool''')
		obs_conn_history = run_cmd('''/Users/jpatel/Documents/Techdocs/edgegrid-curl/egcurl -sSk https://akab-7elybsdhwkk3wd56-yuvntpsfnkajbmvm.luna.akamaiapis.net/orion/v2/customers/424715/devices/'''+devid+'''/connection-history''')
		list_of_tuple.append((obs_conn_status,obs_conn_history))
	
	print('\n=======================================================\n')
	for conn_status,conn_history in list_of_tuple:
		dict_conn_status = json.loads(conn_status)
		# print(dict_conn_status)
		conn_history_list = ast.literal_eval(conn_history)
		# print(conn_history_list[0])
		try:
			dict_conn_history = conn_history_list[0]
Esempio n. 4
0
#! /usr/bin/env python3

from jfunc import run_cmd
import json
import time
import ast 

if __name__ == "__main__":
	
	# JAY:

	print('\n=======================================================\n')
	
	while True:
		date_UTC = run_cmd('date -u')
		conn_status = run_cmd('''/Users/jpatel/Documents/Techdocs/edgegrid-curl/egcurl -sSk  https://akab-p5cgfagtzkkfjy74-qgv27om5urjpzcs4.luna.akamaiapis.net/orion/v2/customers/432452/devices/2859560/connection-status | python -mjson.tool''')
		conn_history = run_cmd('''/Users/jpatel/Documents/Techdocs/edgegrid-curl/egcurl -sSk  https://akab-p5cgfagtzkkfjy74-qgv27om5urjpzcs4.luna.akamaiapis.net/orion/v2/customers/432452/devices/2859560/connection-history''')
		dict_conn_status = json.loads(conn_status)
		conn_history_list = ast.literal_eval(conn_history)

		try:
			dict_conn_history = conn_history_list[0]
			print('Customer ID: ',dict_conn_history['akamaiCustomerId'], '	Device ID: ',dict_conn_history['akamaiDeviceId'] )
			print ('UTC time on mac -- ', date_UTC)	
			print ('lastConnected from connection-status --  ',dict_conn_status['lastConnected'])
			print ('lastConnected from connection-history -- ',dict_conn_history['lastConnectedTime'])


			fmt_api_time = '%Y-%m-%dT%H:%M:%S+0000'
			fmt_utc_time = '%a %b %d %H:%M:%S UTC %Y'
Esempio n. 5
0
def searchlogs(request):
  mip_reg_vip_pickle = '/Users/jpatel/Desktop/mip_reg_vip_loc.pickle'
  fmt = '%(asctime)s %(levelname)s %(name)s %(lineno)s %(message)s'
  logging.basicConfig(level='INFO', format= fmt, filename='/Library/Frameworks/Python.framework/Versions/3.4/bin/django_jay/searchlogs.log')
  global logger
  logger = logging.getLogger('searchlogs')

  if request.method == 'POST':
    d = SearchlogsForm(request.POST)
    if d.is_valid():
      cd = d.cleaned_data
      # LOGIC FOR DATA COLLECTED
      start = format_datetime(str(cd['start_time']))
      end = format_datetime(str(cd['end_time']))
      
      if cd['search_base'] == 'Machine IP':
        cmd = 'nsh '+ cd['ip_or_reg'] + ' grep -i --range=' + start + '-' + end + " '" + cd['search_string'] + "' /ghostcache/logs/" + cd['log_select1'] + '.log'
        op = run_cmd(cmd)        
        context = {
                    "cmd": cmd,
			               "op": op
			             }

      if (cd['search_base'] == 'Edge VIP') or (cd['search_base'] == 'Region Number'):
        df = pd.read_pickle(mip_reg_vip_pickle)
        logger.info('Done with reading pickle file ')
        file_age = (time.time() - os.path.getmtime(mip_reg_vip_pickle))//60
        try:
          if cd['search_base'] == 'Edge VIP':
            df.set_index(['vip'], inplace = True)
            tempdf = df.ix[cd['ip_or_reg']]
          if cd['search_base'] == 'Region Number':
            df.set_index(['physregion'], inplace = True)
            tempdf = df.ix[int(cd['ip_or_reg'])]
            tempdf.drop_duplicates(subset='machineIP',inplace = True)
          logger.info('List found:')
          logger.info(tempdf['machineIP'])

          queue1 = Queue()
          for i in tempdf['machineIP']:
            cmd = 'nsh ' + i + ' grep -i --range ' + start + '-' + end + " '" + cd['search_string'] + "' /ghostcache/logs/" + cd['log_select1'] + '.log'
            p = multiprocessing.Process(target=run_cmd_local, args=(cmd,queue1))
            p.start()
            # p.join()
          count = len(tempdf)
          op_list = []
          while count > 0 :
            op_list.append(queue1.get())
            count = count -1
          tempdf['count'] = np.arange(1, len(tempdf) + 1)
          logger.info('Results ready for django.')
          context = {
                       "machine_list": tempdf[['count','machineIP']].to_html(classes="table table-striped", index=False),              
                       "op_list": op_list,
                       "file_age": file_age
                     }
        except KeyError as err:
           context = {
                       "KeyError_Exception": True
                     }
      return render(request, 'searchlogs_result.html', context)
    else:
      context = {
                   "form" : d
                   }
      return render(request, 'searchlogs_form.html',context)
  else:
    d = SearchlogsForm()
    context = {
             "form" : d
             }
    return render(request, 'searchlogs_form.html', context)