-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgncs_field_services.py
executable file
·84 lines (79 loc) · 2.29 KB
/
gncs_field_services.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/usr/bin/python
#-*- coding: utf-8 -*-
import os
import urllib2
import urllib
import json
import csv
import sys
reload(sys)
sys.setdefaultencoding('utf-8')
filter = """
{
"data": {
"page": 1,
"Type": "Device",
"Filters": {
"support_group__name": "GNS Field Services",
"status_id": "3"
}
}
}
"""
devicefilter = """
{
"data": {
"page": 1,
"Type": "DeviceInterface",
"Filters": {
"device_id": "3"
}
}
}
"""
rows = []
output_dir = "."
filename = "gnsfieldservicesdeviceinterface.csv"
csv_file = os.path.join(output_dir, filename).encode('utf-8')
filterObj = json.loads(filter)
devicefilters = json.loads(devicefilter)
vartmp = 0
varItr=1;
while True:
url = 'https://capri.corp.apple.com/v0/query'
req = urllib2.Request(url, json.dumps(filterObj),)
response = urllib2.urlopen(req)
json_obj = response.read()
data = json.loads(json_obj)
for item in data['data'] :
varsa= item['id']
print varsa
devicefilters['data']['Filters']['device_id'] = varsa
request = urllib2.Request(url, json.dumps(devicefilters),)
responses = urllib2.urlopen(request)
json_obj = responses.read()
deviceinterfacedata = json.loads(json_obj)
#yourstring = deviceinterfacedata.encode('ascii', 'ignore').decode('ascii')
#deviceinterfacedata.encode('utf-8')
#print deviceinterfacedata
for deviceinfo in deviceinterfacedata['data']:
rows.append([deviceinfo['device_name'],deviceinfo['name'],deviceinfo['ip'],deviceinfo['ip_subnet'],deviceinfo['id'],item['snmp_location'],item['fqdn'],item['mgmt_ip'],deviceinfo['description'] ])
print deviceinfo['name']
print deviceinfo['ip']
print deviceinfo['ip_subnet']
print deviceinfo['id']
print deviceinfo['device_name']
print item['snmp_location']
print item['fqdn']
print item['mgmt_ip']
print deviceinfo['description']
with open(filename, "wb") as csv_file:
csv_writer = csv.writer(
csv_file, delimiter=',', quotechar='"', quoting=csv.QUOTE_ALL)
csv_writer.writerows(rows)
vartotal = data['total_num_pages'];
varItr+=1
print varItr
filterObj['data']['page'] = varItr
if(varItr> vartotal):
break;