Beispiel #1
0
	def refresh_interfaces(self):
		""" Initialize the SNMP OIDs to poll depending on interfaces this node will use """

		# check available network interfaces on host
		try:
			oids = snmp.walk(self.target.address,
					snmp.load_symbol('IF-MIB', 'ifDescr'))
			up = snmp.walk(self.target.address,
					snmp.load_symbol('IF-MIB', 'ifAdminStatus'))
		except Exception, e:
			logging.error('Unable to get interface OIDs for ' +
				`self.target.address` + ': ' + `e`)
			raise e
Beispiel #2
0
def get_data(ups: dict, env) -> dict:
    '''
    Get the raw snmp values
    '''
    # IP address to snmp walk
    ip = ups['device']['ip']
    # SNMP community
    snmp_community = env.ups_snmp
    # Reset the dictionary
    ups_data = {}
    # List of OIDs to start the snmp walk from
    start_oids = ['1.3.6.1.4.1.534.1', '1.3.6.1.2.1.33.1']
    # Iterate over the oids
    for start_oid in start_oids:
        # SNMP walk in the snmp module
        data = snmp.walk(ip, start_oid, snmp_community)
        if data:
            # Merge resulting dictionary to the main dictionary
            ups_data = ups_data | data
        else:
            break

    if data:
        return (ups_data)
    else:
        return (False)
Beispiel #3
0
	def init_interfaces(self, target):
		""" Check target node interfaces """
		
		# SNMP GET
		try:
			oids = snmp.walk(target, snmp.load_symbol('IF-MIB', 'ifDescr'))
		except Exception, e:
			logging.error('Unable to get interface OIDs for ' +
				`target` + ': ' + `e`)
			return
Beispiel #4
0
	def poll_routes(self):
		"""
		Update ip index and routing tables for node
		"""
		
		logging.debug('poll_route for ' + `self.target`)
		try:			
			# TODO: transition to GETBULK
			# TODO: 'Simulate' support
			# Interface index for routing entries
			indices = snmp.walk(self.target,
				snmp.load_symbol('RFC1213-MIB', 'ipRouteIfIndex'))
			# Routing table destinations/IPs to neighbours
			routes = parse_routes(snmp.walk(self.target,
				snmp.load_symbol('RFC1213-MIB', 'ipRouteDest')))
			# Route types
			types = snmp.walk(self.target,
				snmp.load_symbol('RFC1213-MIB', 'ipRouteType'))
			# Netmasks
			masks = parse_routes(snmp.walk(self.target,
				snmp.load_symbol('RFC1213-MIB', 'ipRouteMask')))
		except Exception, e:
			raise Exception, 'Could not poll routing tables for ' + \
				`self.target` + ': ' + `e`
Beispiel #5
0
	def loop_aodv(self):

		for target in nodes.collection:

			# BUG: (maybe?) if a node does not have SNMP there's no way
			# to fetch its SNMP status
			if target.type != nodes.ROUTER:
				continue

			# first, reset neighbours list so we can redetect links
			target.neighbours = {}

			############
			text = None
			global execResults
			logging.debug('loop_aodv for %s' % target.address)
			
			try:
				execResults[target.address] = \
						snmp.walk(target.address, (1,3,6,1,4,1,2021,8))
				# try and increase interval
				if self.interval > 10:
					self.interval -= 1

			except Exception, e:
				logging.error('Unable to get AODV output for ' +
					`target.address` + ': ' + `e`)

				# try and reduce traffic interval
				if self.interval < 30:
					self.interval += 1
				continue

			target.aodv_data = \
					aodv.parse(str(execResults[target.address][8][0][1]))
			target.wifi_data = \
					wifi.parse(str(execResults[target.address][9][0][1]))

			for interface in target.aodv_data:
				# fetch entry for this link
				entry = target.aodv_data[interface]
				destaddress = entry['destination']

				# check if it already exists
				dest = nodes.find(destaddress)

				if dest == None:
					# add newly discovered nodes to collection
					dest = nodes.create(destaddress)
					nodes.add(dest)

					try:
						logging.debug(snmp.walk(dest.address,
								snmp.load_symbol('SNMPv2-MIB',
										'sysDescr'))[0][0][1])
						# no problems here. this destination supports SNMP
						dest.type = nodes.ROUTER

						logging.debug('Starting SNMP poll thread for ' + `dest.address`)
						threads.add(GathererThread(dest))

						logging.debug('Starting graphing thread for ' + `dest.address`)
						threads.add(rendering.rrd.GraphingThread(dest))

					except Exception, e:
						if e.message == 'requestTimedOut':
							# assume machine does not have SNM
							# assume machine does not have SNMP?
							logging.debug('PROBING %s has timed out!' % dest.address)
							dest.type = nodes.GENERIC
						else:
							# we have a real error!
							logging.error(e)


				# also check for AODV gateway nodes
				gateway = nodes.find(entry['gateway'])
				if gateway == None:
					gateway = nodes.create(entry['gateway'])
					nodes.add(gateway)

					try:
						logging.debug(snmp.walk(gateway.address,
								snmp.load_symbol('SNMPv2-MIB',
										'sysDescr'))[0][0][1])
						# no problems here. this gateway supports SNMP
						gateway.type = nodes.ROUTER

						logging.debug('Starting SNMP poll thread for ' + `gateway.address`)
						threads.add(GathererThread(gateway))

						logging.debug('Starting graphing thread for ' + `gateway.address`)
						threads.add(rendering.rrd.GraphingThread(gateway))

					except Exception, e:
						if e.message == 'requestTimedOut':
							# assume machine does not have SNMP?
							logging.debug('PROBING %s has timed out!' % gateway.address)
							gateway.type = nodes.GENERIC
						else:
							# we have a real error!
							logging.error(e)