This file contains 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
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 |
This file contains 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
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"] |
This file contains 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
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) |
This file contains 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
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'] |
This file contains 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
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 |
This file contains 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
>>> 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> |
This file contains 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
>>> print (json.dumps(y, indent = 4)) | |
{ | |
"device": { | |
"id": "116", | |
"label": "Cisco2811.haw.int", | |
"ip": "10.101.0.1", | |
"mask": "255.255.255.0", | |
"status": "1", | |
"statusDesc": "Normal", | |
"sysName": "Cisco2811.haw.int", |
This file contains 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
>>> print (yaml.dump(y, default_flow_style = False)) | |
!!python/object/apply:collections.OrderedDict | |
dictitems: | |
device: !!python/object/apply:collections.OrderedDict | |
dictitems: | |
categoryId: '0' | |
contact: changed this too | |
devCategoryImgSrc: router | |
id: '116' | |
ip: 10.101.0.1 |
This file contains 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
>>> y = xmltodict.parse(x) | |
>>> y | |
OrderedDict([('device', OrderedDict([('id', '116'), ('label', 'Cisco2811.haw.int'), ('ip', '10.101.0.1'), ('mask', '255.255.255.0'), ('status', '1'), ('statusDesc', 'Normal'), ('sysName', 'Cisco2811.haw.int'), ('contact', 'changed this too'), ('location', 'changed this too'), ('sysOid', '1.3.6.1.4.1.9.1.576'), ('sysDescription', None), ('devCategoryImgSrc', 'router'), ('topoIconName', 'iconroute'), ('categoryId', '0'), ('symbolId', '1147'), ('symbolName', 'Cisco2811.haw.int'), ('symbolType', '3'), ('symbolDesc', None), ('symbolLevel', '2'), ('parentId', '1'), ('typeName', 'Cisco 2811'), ('mac', '00:1b:d4:47:1e:68'), ('link', OrderedDict([('@op', 'GET'), ('@rel', 'self'), ('@href', 'http://10.3.10.220:8080/imcrs/plat/res/device/116')]))]))]) | |
>>> |
This file contains 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
import ipaddress | |
def ip_in_network(startIp, endIp): | |
mask = 32 | |
startIp = ipaddress.ip_address(startIp) | |
endIp = ipaddress.ip_address(endIp) | |
netrange = ipaddress.ip_network(str(startIp)+'/'+str(mask), strict=False) | |
while ((endIp in netrange) == False): | |
mask -= 1 | |
netrange = ipaddress.ip_network(str(startIp)+'/'+str(mask), strict=False) |
OlderNewer