def findCode(community,ip): command = router.command(community,ip,SNMPv2MIB_sysDescr) data = router.getData(command) #print data if (data == []): pass else: data = router.detail(data) #print "data[0] : "+ str(data[0]) data = data[0].split("(C")[1] #print "datasadasdasd : "+ str(data) data = data.split("-")[0] #print data #print "data : "+ str(data) #data = data[0].split(","); #data = data[1].strip() #data = data.split(" "); #data = data[0].strip("C"); return data
def findCode(community, ip): command = router.command(community, ip, SNMPv2MIB_sysDescr) data = router.getData(command) #print data if (data == []): pass else: data = router.detail(data) #print "data[0] : "+ str(data[0]) data = data[0].split("(C")[1] #print "datasadasdasd : "+ str(data) data = data.split("-")[0] #print data #print "data : "+ str(data) #data = data[0].split(","); #data = data[1].strip() #data = data.split(" "); #data = data[0].strip("C"); return data
def switch(ip,done_list,notdone_list,filename,index,coll,ipTraffic,community,username,password): name_data = router.reArrange(router.getData(router.command(community,ip,SNMPv2MIB_sysName))) detail_data = router.detail(router.getData(router.command(community,ip,SNMPv2MIB_sysDescr))) ip_data = router.reArrange(router.getData(router.command(community,ip,IPMIB_ipAdEntAddr))) subnet_data = router.reArrange(router.getData(router.command(community,ip,IPMIB_ipAdEntNetMask))) index_data = router.reArrange(router.getData(router.command(community,ip,IPMIB_ipAdEntIfIndex))) interface_data = router.reArrange(router.getData(router.command(community,ip,IFMIB_ifDescr))) ## new version #name_data_cdps = reArrange(getData(command(community,ip,SNMPv2MIB_sysName))) interface_data_cdps = cdps.New_reArrange_name(router.getData(router.command(community,ip,CISCOCDPMIB_cdpInterfaceName))) name_cdp_cdps = cdps.New_reArrange_cdpname(router.getData(router.command(community,ip,CISCOCDPMIB_cdpCacheDeviceId))) interface_cdps = cdps.New_reArrange_cdpinterface(router.getData(router.command(community,ip,CISCOCDPMIB_cdpCacheDevicePort))) ## name_cdp = router.reArrange(router.getData(router.command(community,ip,CISCOCDPMIB_cdpCacheDeviceId))) interface_cdp = router.reArrange(router.getData(router.command(community,ip,CISCOCDPMIB_cdpCacheDevicePort))) ip_cdp = router.reArrange(router.getData(router.command(community,ip,IPMIB_ipNetToMediaNetAddress))) ### forwarding blocking #stp_port = ps.reArrange(ps.getData(ps.command(community,ip,BRIDGEMIB_dot1dStpPort))) #stp_portstate = ps.New_reArrange(ps.getData(ps.command(community,ip,BRIDGEMIB_dot1dStpPortState))) #stp_portindex = ps.New_reArrange(ps.getData(ps.command(community,ip,BRIDGEMIB_dot1dBasePortIfIndex))) #ps_interface_data = ps.New_reArrange(router.getData(router.command(community,ip,IFMIB_ifDescr))) ### ### vlan vlan_name vtp_vlanname = vn.New_reArrange(router.getData(router.command(community,ip,CISCOVTPMIB_vtpVlanName))) ### ### interface vlan iv_interface_data = iv.New_reArrange(router.getData(router.command(community,ip,IFMIB_ifDescr))) trunk = iv.New_reArrange(router.getData(router.command(community,ip,CISCOVTPMIB_vlanTrunkPortDynamicStatus))) vlan_interface = iv.New_reArrange_vlan(router.getData(router.command(community,ip,CISCOSMI_ciscoMgmt))) ### #print "name : " + str(name_data) #print "detail : " + str(detail_data) #print "------------------------------------------------" #print "ip : " + str(ip_data) #print "subnet : " + str(subnet_data) #print "index : " + str(index_data) #print "interface_data : " + str(interface_data) #print "------------------------------------------------" #print "name of neighbors : " + str(name_cdp) #print "interface of neighbors : " + str(interface_cdp) #print "ip of neighbors : " + str(ip_cdp) #print "------------------------------------------------" #print "stp port : " + str(stp_port) #print "stp port state : " + str(stp_portstate) #print "stp port index : " + str(stp_portindex) #print "stp interface : " + str(ps_interface_data) #print "------------------------------------------------" #print "vlan name : " + str(vtp_vlanname) #print "------------------------------------------------" #print "interface : " + str(iv_interface_data) #print "trunk : " + str(trunk) #print "vlan : " + str(vlan_interface) #print "------------------------------------------------" #print stp_port #"1.3.6.1.2.1.17.2.15.1.1" #print stp_portstate #".1.3.6.1.2.1.17.2.15.1.3" #print stp_portindex #".1.3.6.1.2.1.17.1.4.1.2" #print vlan_index #.1.3.6.1.2.1.2.2.1.1 #print vlan_interface #"1.3.6.1.4.1.9.9.46.1.3.1.1.4" #print interface_data #.1.3.6.1.2.1.2.2.1.2 ## add to database : index,switch_name,detail for i in range(0,len(name_data)): form = {"index":str(index),"switch_name":str(name_data[i]),"detail":str(detail_data[i])} coll.insert_one(form) ## type type = [] type.append("switch") coll.update({"index":str(index)},{'$set':{"type":"switch"}}) ## vlan , vlan_name vlan_name = [] vlan_name = vn.vlanname(vtp_vlanname) for i in range(0,len(vlan_name)): coll.update({"index":str(index)},{'$set':{"vlan_name"+str(i):str(vlan_name[i])}}) ## vlan , ip , subnet newData = [] for i in range(0,len(ip_data)): done_list.append(ip_data[i]) newData.append("Vlan" + index_data[i] + "," + ip_data[i] + "," + subnet_data[i]) coll.update({"index":str(index)},{'$set':{"vlan_ip"+str(i):str(newData[i])}}) ## interface , vlan interface_vlan = [] interface_vlan2 = [] interface_vlan = iv.interfaceVlan(iv_interface_data,trunk,vlan_interface) for i in range(0,len(interface_vlan)): #print interface_vlan[i] interface_vlan2.append(interface_vlan[i]) coll.update({"index":str(index)},{'$set':{"interface_vlan" + str(i):str(interface_vlan[i])}}) #interface_vlan2 = [] #interface_vlan2 = interface_vlan ### interface , state vlan1 #interface_state = [] #interface_state = ps.portState(stp_port,stp_portstate,stp_portindex,ps_interface_data) #print "state : " + str(interface_state) #for i in range(0,len(interface_state)): # coll.update({"index":str(index)},{'$set':{"interface_state" + str(i):str(interface_state[i])}}) ## interface , state vlan 2 up #interface_state = [] interface_state_vlan = [] interface_state_vlan = s.ssh_portstate(ip,username,password) #interface_state_vlan = t.port_state(interface_vlan,interface_state) for i in range(0,len(interface_state_vlan)): coll.update({"index":str(index)},{'$set':{"interface_state" + str(i):str(interface_state_vlan[i])}}) ## donelist notdonelist done_list,notdone_list = fl.findlist(ip_data,ip_cdp,done_list,notdone_list) ## update cdp_interface newCDP = [] for i in range(0,len(name_cdp)): newCDP.append(name_cdp[i] + "," + interface_cdp[i]) coll.update({"index":str(index)},{'$set':{"cdp_interface"+str(i):str(newCDP[i])}}) newCDPs = [] newCDPs = cdps.New_CDPs(name_data,interface_data_cdps,name_cdp_cdps,interface_cdps) for i in range(0,len(newCDPs)): coll.update({"index":str(index)},{'$set':{"new_cdp"+str(i):str(newCDPs[i])}}) #add X , Y for position #x = [] #y = [] #x.append("none") #y.append("none") coll.update({"index":str(index)},{'$set':{"location":"none"}}) #coll.update({"index":str(index)},{'$set':{"y":"none"}}) #print "done : " + str(done_list) #print "##############################" #print "Not donw : " + str(notdone_list) a = name_data + detail_data + type + vlan_name + newData + interface_vlan2 + interface_state_vlan + newCDP +newCDPs #a = name_data + detail_data + type + vlan_name + newData + interface_vlan + newCDP router.writeFile(a,filename) return done_list,notdone_list,index
def switch(ip, done_list, notdone_list, filename, index, coll, ipTraffic, community, username, password): name_data = router.reArrange( router.getData(router.command(community, ip, SNMPv2MIB_sysName))) detail_data = router.detail( router.getData(router.command(community, ip, SNMPv2MIB_sysDescr))) ip_data = router.reArrange( router.getData(router.command(community, ip, IPMIB_ipAdEntAddr))) subnet_data = router.reArrange( router.getData(router.command(community, ip, IPMIB_ipAdEntNetMask))) index_data = router.reArrange( router.getData(router.command(community, ip, IPMIB_ipAdEntIfIndex))) interface_data = router.reArrange( router.getData(router.command(community, ip, IFMIB_ifDescr))) ## new version #name_data_cdps = reArrange(getData(command(community,ip,SNMPv2MIB_sysName))) interface_data_cdps = cdps.New_reArrange_name( router.getData( router.command(community, ip, CISCOCDPMIB_cdpInterfaceName))) name_cdp_cdps = cdps.New_reArrange_cdpname( router.getData( router.command(community, ip, CISCOCDPMIB_cdpCacheDeviceId))) interface_cdps = cdps.New_reArrange_cdpinterface( router.getData( router.command(community, ip, CISCOCDPMIB_cdpCacheDevicePort))) ## name_cdp = router.reArrange( router.getData( router.command(community, ip, CISCOCDPMIB_cdpCacheDeviceId))) interface_cdp = router.reArrange( router.getData( router.command(community, ip, CISCOCDPMIB_cdpCacheDevicePort))) ip_cdp = router.reArrange( router.getData( router.command(community, ip, IPMIB_ipNetToMediaNetAddress))) ### forwarding blocking #stp_port = ps.reArrange(ps.getData(ps.command(community,ip,BRIDGEMIB_dot1dStpPort))) #stp_portstate = ps.New_reArrange(ps.getData(ps.command(community,ip,BRIDGEMIB_dot1dStpPortState))) #stp_portindex = ps.New_reArrange(ps.getData(ps.command(community,ip,BRIDGEMIB_dot1dBasePortIfIndex))) #ps_interface_data = ps.New_reArrange(router.getData(router.command(community,ip,IFMIB_ifDescr))) ### ### vlan vlan_name vtp_vlanname = vn.New_reArrange( router.getData(router.command(community, ip, CISCOVTPMIB_vtpVlanName))) ### ### interface vlan iv_interface_data = iv.New_reArrange( router.getData(router.command(community, ip, IFMIB_ifDescr))) trunk = iv.New_reArrange( router.getData( router.command(community, ip, CISCOVTPMIB_vlanTrunkPortDynamicStatus))) vlan_interface = iv.New_reArrange_vlan( router.getData(router.command(community, ip, CISCOSMI_ciscoMgmt))) ### #print "name : " + str(name_data) #print "detail : " + str(detail_data) #print "------------------------------------------------" #print "ip : " + str(ip_data) #print "subnet : " + str(subnet_data) #print "index : " + str(index_data) #print "interface_data : " + str(interface_data) #print "------------------------------------------------" #print "name of neighbors : " + str(name_cdp) #print "interface of neighbors : " + str(interface_cdp) #print "ip of neighbors : " + str(ip_cdp) #print "------------------------------------------------" #print "stp port : " + str(stp_port) #print "stp port state : " + str(stp_portstate) #print "stp port index : " + str(stp_portindex) #print "stp interface : " + str(ps_interface_data) #print "------------------------------------------------" #print "vlan name : " + str(vtp_vlanname) #print "------------------------------------------------" #print "interface : " + str(iv_interface_data) #print "trunk : " + str(trunk) #print "vlan : " + str(vlan_interface) #print "------------------------------------------------" #print stp_port #"1.3.6.1.2.1.17.2.15.1.1" #print stp_portstate #".1.3.6.1.2.1.17.2.15.1.3" #print stp_portindex #".1.3.6.1.2.1.17.1.4.1.2" #print vlan_index #.1.3.6.1.2.1.2.2.1.1 #print vlan_interface #"1.3.6.1.4.1.9.9.46.1.3.1.1.4" #print interface_data #.1.3.6.1.2.1.2.2.1.2 ## add to database : index,switch_name,detail for i in range(0, len(name_data)): form = { "index": str(index), "switch_name": str(name_data[i]), "detail": str(detail_data[i]) } coll.insert_one(form) ## type type = [] type.append("switch") coll.update({"index": str(index)}, {'$set': {"type": "switch"}}) ## vlan , vlan_name vlan_name = [] vlan_name = vn.vlanname(vtp_vlanname) for i in range(0, len(vlan_name)): coll.update({"index": str(index)}, {'$set': { "vlan_name" + str(i): str(vlan_name[i]) }}) ## vlan , ip , subnet newData = [] for i in range(0, len(ip_data)): done_list.append(ip_data[i]) newData.append("Vlan" + index_data[i] + "," + ip_data[i] + "," + subnet_data[i]) coll.update({"index": str(index)}, {'$set': { "vlan_ip" + str(i): str(newData[i]) }}) ## interface , vlan interface_vlan = [] interface_vlan2 = [] interface_vlan = iv.interfaceVlan(iv_interface_data, trunk, vlan_interface) for i in range(0, len(interface_vlan)): #print interface_vlan[i] interface_vlan2.append(interface_vlan[i]) coll.update( {"index": str(index)}, {'$set': { "interface_vlan" + str(i): str(interface_vlan[i]) }}) #interface_vlan2 = [] #interface_vlan2 = interface_vlan ### interface , state vlan1 #interface_state = [] #interface_state = ps.portState(stp_port,stp_portstate,stp_portindex,ps_interface_data) #print "state : " + str(interface_state) #for i in range(0,len(interface_state)): # coll.update({"index":str(index)},{'$set':{"interface_state" + str(i):str(interface_state[i])}}) ## interface , state vlan 2 up #interface_state = [] interface_state_vlan = [] interface_state_vlan = s.ssh_portstate(ip, username, password) #interface_state_vlan = t.port_state(interface_vlan,interface_state) for i in range(0, len(interface_state_vlan)): coll.update({"index": str(index)}, { '$set': { "interface_state" + str(i): str(interface_state_vlan[i]) } }) ## donelist notdonelist done_list, notdone_list = fl.findlist(ip_data, ip_cdp, done_list, notdone_list) ## update cdp_interface newCDP = [] for i in range(0, len(name_cdp)): newCDP.append(name_cdp[i] + "," + interface_cdp[i]) coll.update({"index": str(index)}, {'$set': { "cdp_interface" + str(i): str(newCDP[i]) }}) newCDPs = [] newCDPs = cdps.New_CDPs(name_data, interface_data_cdps, name_cdp_cdps, interface_cdps) for i in range(0, len(newCDPs)): coll.update({"index": str(index)}, {'$set': { "new_cdp" + str(i): str(newCDPs[i]) }}) #add X , Y for position #x = [] #y = [] #x.append("none") #y.append("none") coll.update({"index": str(index)}, {'$set': {"location": "none"}}) #coll.update({"index":str(index)},{'$set':{"y":"none"}}) #print "done : " + str(done_list) #print "##############################" #print "Not donw : " + str(notdone_list) a = name_data + detail_data + type + vlan_name + newData + interface_vlan2 + interface_state_vlan + newCDP + newCDPs #a = name_data + detail_data + type + vlan_name + newData + interface_vlan + newCDP router.writeFile(a, filename) return done_list, notdone_list, index
def packetSize(community, ip): size = New_reArrange( router.getData(router.command(community, ip, IFMIB_ifMtu))) return size
def checkStatus(community, ip): status = New_reArrange( router.getData(router.command(community, ip, IFMIB_ifOperStatus))) return status
def checkInterface(community, ip): interface = New_reArrange_Descr( router.getData(router.command(community, ip, IFMIB_ifDescr))) return interface
def traffOut(community, ip): Out = New_reArrange( router.getData(router.command(community, ip, IFMIB_ifOnOctets))) return Out
def ifSpeed(community, ip): #print ip #print type(ip) Speed = New_reArrange( router.getData(router.command(community, ip, IFMIB_ifSpeed))) return Speed
def packetSize(community,ip): size = New_reArrange(router.getData(router.command(community,ip,IFMIB_ifMtu))) return size
def traffIn(community, ip): In = New_reArrange( router.getData(router.command(community, ip, IFMIB_ifInOctets))) return In
def checkInterface(community,ip): interface = New_reArrange_Descr(router.getData(router.command(community,ip,IFMIB_ifDescr))) return interface
def checkStatus(community,ip): status = New_reArrange(router.getData(router.command(community,ip,IFMIB_ifOperStatus))) return status
def ifSpeed(community,ip): #print ip #print type(ip) Speed = New_reArrange(router.getData(router.command(community,ip,IFMIB_ifSpeed))) return Speed
def traffOut(community,ip): Out = New_reArrange(router.getData(router.command(community,ip,IFMIB_ifOnOctets))) return Out
def traffIn(community,ip): In = New_reArrange(router.getData(router.command(community,ip,IFMIB_ifInOctets))) return In