Skip to content

Instantly share code, notes, and snippets.

@netmanchris
netmanchris / XML
Last active August 29, 2015 14:26
>>> x = '''<device>
<id>116</id>
<label>Cisco2811.haw.int</label>
<ip>10.101.0.1</ip>
<mask>255.255.255.0</mask>
<status>1</status>
<statusDesc>Normal</statusDesc>
<sysName>Cisco2811.haw.int</sysName>
<contact>changed this too</contact>
<location>changed this too</location>
@netmanchris
netmanchris / Add_device_to_custom_view.py
Created July 25, 2015 20:03
Add Device to Custom View
def add_device_to_view(dev_list, view_id):
modify_custom_view_url = '''/imcrs/plat/res/view/custom/'''+ str(view_id)
device_list = []
for i in dev_list:
dev_id = {'id': i['id'] }
device_list.append(dev_id)
payload = '''{"device":'''+ json.dumps(device_list) + '''}'''
f_url = url+modify_custom_view_url
r = requests.put(f_url, data = payload, auth=auth, headers=headers) #creates the URL using the payload variable as the contents
r.status_code
def get_view_id(view_name):
view_list = get_custom_views()
for i in view_list:
if i['name'].lower() == view_name.lower():
view_id = i['symbolId']
return i['symbolId']
@netmanchris
netmanchris / Add_custom_views.py
Created July 25, 2015 18:49
Add Custom View Main function
def main():
# checks to see if the imc credentials are already available
if auth == None or url == None:
imc_creds()
view_name = create_new_view()
view_list = get_custom_views()
view_id = get_view_id(view_name)
dev_list = filter_dev_category()
add_device_to_view(dev_list, view_id)
@netmanchris
netmanchris / get_custom_views.py
Created July 25, 2015 18:46
Get Custom Views
def get_custom_views():
# checks to see if the imc credentials are already available
if auth == None or url == None:
imc_creds()
get_custom_view_url = '/imcrs/plat/res/view/custom?resPrivilegeFilter=false&desc=false&total=false'
f_url = url + get_custom_view_url
# creates the URL using the payload variable as the contents
r = requests.get(f_url, auth=auth, headers=headers)
if r.status_code == 200:
view_list = (json.loads(r.text))["customView"]
@netmanchris
netmanchris / Add_New_Custom_View.py
Created July 25, 2015 18:29
Add New Custom View
def create_new_view():
view_name = input("Please input the name of the new view: ")
add_view_url = "/imcrs/plat/res/view/custom?resPrivilegeFilter=false&desc=false&total=false"
f_url = url + add_view_url
payload = '''{ "name": "''' + view_name + '''", "autoAddDevType" : "0"}'''
r = requests.post(f_url, data=payload, auth=auth,
headers=headers) # creates the URL using the payload variable as the contents
r.status_code
if r.status_code == 201:
return view_name