def GetStatViewPy( getStatsBy='Flow Statistics' ): ''' Description: This API will return you a Python Dict of all the stats based on your specified stat name which are shown below. getStatsBy options (case sensitive): "Port Statistics" "Tx-Rx Frame Rate Statistics" "Port CPU Statistics" "Global Protocol Statistics" "Protocols Summary" "Port Summary" "OSPFv2-RTR Drill Down" "OSPFv2-RTR Per Port" "IPv4 Drill Down" "L2-L3 Test Summary Statistics" "Flow Statistics" "Traffic Item Statistics" ''' viewList = ixNet.getList(ixNet.getRoot()+'/statistics', 'view') statViewSelection = getStatsBy try: statsViewIndex = viewList.index('::ixNet::OBJ-/statistics/view:"' + getStatsBy +'"') except Exception, errMsg: sys.exit('\nNo such statistic name: %s' % getStatsBy) view = viewList[statsViewIndex] ixNet.setAttribute(view, '-enabled', 'true') ixNet.commit() columnList = ixNet.getAttribute(view+'/page', '-columnCaptions') print '\n', columnList startTime = 1 stopTime = 30 for timer in xrange(startTime, stopTime + 1): totalPages = ixNet.getAttribute(view+'/page', '-totalPages') if totalPages == 'null': print 'GetStatView: Getting total pages for %s is not ready: %s/%s' % (getStatsBy, startTime, stopTime) time.sleep(2) else: break row = 0 statDict = {} for currentPage in xrange(1, int(totalPages)+1): ixNet.setAttribute(view+'/page', '-currentPage', currentPage) ixNet.commit() whileLoopStopCounter = 0 while (ixNet.getAttribute(view+'/page', '-isReady')) != 'true': if whileLoopStopCounter == 5: print'\nGetStatView: Could not get stats' return 1 if whileLoopStopCounter < 5: print'\nGetStatView: Not ready yet. Waiting %s/5 seconds ...' % whileLoopStopCounter time.sleep(1) whileLoopStopCounter += 1 pageList = ixNet.getAttribute(view+'/page', '-rowValues') totalFlowStatistics = len(pageList) for pageListIndex in xrange(0, totalFlowStatistics): rowList = pageList[pageListIndex] for rowIndex in xrange(0, len(rowList)): row += 1 cellList = rowList[rowIndex] statDict[row] = {} # CellList: ['Ethernet - 002', 'Ethernet - 001', 'OSPF T1 to T2', '206.27.0.0-201.27.0.0', 'OSPF T1 to T2-FlowGroup-1 - Flow Group 0002', '1225', '1225', '0', '0', '0', '0', '0', '0', '156800', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '00:00:00.781', '00:00:00.849'] index = 0 for statValue in cellList: statDict[row].update({columnList[index]: statValue}) index += 1 return statDict