def queryInterface(self): # Get the device's ifTable query = snmpQuery.snmpWalk(self.agent.snmpVersion, self.agent.community, self.agent.address, self.agent.port, '1.3.6.1.2.1.2.2.1') # Loop through the entries to find the first # interface ot type ethernetCsmacd (6) ifIndex = None for key, value in query.items(): # Check if this is an ifType column. if key.startswith('1.3.6.1.2.1.2.2.1.3.'): if not value == '6': continue # The ifIndex is the las item on the OID. ifIndex = key.split('.')[-1] break if not ifIndex: return None ifInOctets = int(query['1.3.6.1.2.1.2.2.1.10.' + ifIndex]) return ifInOctets
def getAgentSysDescr(self): return snmp.snmpWalk( self.agent.snmpVersion, self.agent.community, self.agent.address, self.agent.port, '1.3.6.1.2.1.1' )
def getCpuInfo(self): return snmpQuery.snmpWalk( self.agentInfo.snmpVersion, self.agentInfo.community, self.agentInfo.address, self.agentInfo.port, '1.3.6.1.2.1.25.3.3.1.2', )
def getDiskCapacities(self): return snmpQuery.snmpWalk( self.agentInfo.snmpVersion, self.agentInfo.community, self.agentInfo.address, self.agentInfo.port, '1.3.6.1.2.1.25.3.6.1.4', )
def getRAMInfo(self): return snmpQuery.snmpWalk( self.agentInfo.snmpVersion, self.agentInfo.community, self.agentInfo.address, self.agentInfo.port, '1.3.6.1.4.1.2021.4', )
def getAverageProcessorLoad(snmpAgentInfo): table = snmp.snmpWalk(snmpAgentInfo.snmpVersion, snmpAgentInfo.community, snmpAgentInfo.address, snmpAgentInfo.port, HR_PROCESSOR_LOAD_COLUMN) if table == None: return table totalProcessorLoad = 0 processorCount = 0 # Compute the total load of all processors. for key, value in table.items(): totalProcessorLoad += float(value) processorCount += 1 # Compute the average. if not processorCount: return totalProcessorLoad return totalProcessorLoad / float(processorCount)
def run(self): while self.running: try: updateValues = dict() responses = snmpQuery.snmpGet( self.snmpAgentInfo.snmpVersion, self.snmpAgentInfo.community, self.snmpAgentInfo.address, self.snmpAgentInfo.port, appConstants.SIMPLE_OIDS ) if responses: for oid in responses: name = appConstants.OID_TO_NAME[oid] updateValues[name] = responses[oid] for oid in appConstants.COMPLEX_OIDS: responses = snmpQuery.snmpWalk( self.snmpAgentInfo.snmpVersion, self.snmpAgentInfo.community, self.snmpAgentInfo.address, self.snmpAgentInfo.port, oid ) if responses: total = 0 for key in responses: total += int(responses[key]) name = appConstants.OID_TO_NAME[oid] updateValues[name] = str(total) self.storage.updateDatabase(updateValues) time.sleep(appConstants.MONITOR_FREQ) except: logging.error('Exception while monitoring %s : %s', self.snmpAgentInfo, sys.exc_info()) self.stop()
def getAgentSysInfo(self): return snmpQuery.snmpWalk(self.agentInfo.snmpVersion, self.agentInfo.community, self.agentInfo.address, self.agentInfo.port, '1.3.6.1.2.1.1')
def getStorageTable(snmpAgentInfo): return snmp.snmpWalk(snmpAgentInfo.snmpVersion, snmpAgentInfo.community, snmpAgentInfo.address, snmpAgentInfo.port, HR_STORAGE_TABLE_OID)