Example #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
Example #2
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
Example #3
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`
Example #4
0
	def loop_monitor(self):
		"""
		Monitoring loop
		"""
		
		logging.debug('loop_monitor for ' + `self.target`)
		while 1:
			try:
				if not self.poll_routes():
					return
				if snmp.get(self.target,
					snmp.load_symbol('IF-MIB', 'ifAdminStatus') +
						(self.if_index,))[0][1] != 1:
					logging.info(`self.target` + ' interface ' + self.if_name + ' is inactive')
					sleep(5)
					continue
				break
			except Exception, e:
				logging.debug('Could not check interface status: ' + `e`)
				sleep(5)
				continue
Example #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)
Example #6
0
__doc__ = """
MeshMon data-gathering backend classes
Version 0.1 - Jerry Chong <*****@*****.**>

Based on meshtraffic.pl by Dirk Lessner, National ICT Australia
"""

import logging, os, rrdtool
import aodv, config, nodes, snmp, threads, wifi
import rendering.rrd

# Look up OIDs for in/out octets
logging.debug('Loading SNMP symbols')
InOctets = snmp.load_symbol('IF-MIB', 'ifInOctets')
OutOctets = snmp.load_symbol('IF-MIB', 'ifOutOctets')

# cache for UCD-SNMP-MIB::ext*
execResults = {}

# cache for parsed AODV
aodvResults = {}


#-------------------------------------------------------------------------------
class AodvThread(threads.MonitorThread):
	""" Thread for checking AODV status """

	def __init__(self):
		super(AodvThread, self).__init__()
		self.func = self.loop_aodv
		self.interval = config.TrafficInterval