Guest User

Untitled

a guest
Jul 22nd, 2010
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 17.08 KB | None | 0 0
  1. ###########################################################################
  2. #
  3. # This program is part of Zenoss Core, an open source monitoring platform.
  4. # Copyright (C) 2007, 2009, Zenoss Inc.
  5. #
  6. # This program is free software; you can redistribute it and/or modify it
  7. # under the terms of the GNU General Public License version 2 as published by
  8. # the Free Software Foundation.
  9. #
  10. # For complete information please visit: http://www.zenoss.com/oss/
  11. #
  12. ###########################################################################
  13.  
  14. __doc__ = """TrangoInterfaceMap
  15.  
  16. Gather IP network interface information from SNMP, and
  17. create DMD interface objects
  18.  
  19. """
  20.  
  21. import re
  22.  
  23. from Products.ZenUtils.Utils import cleanstring, unsigned
  24. from Products.DataCollector.plugins.CollectorPlugin import SnmpPlugin, GetMap, GetTableMap
  25.  
  26. class TrangoInterfaceMap(SnmpPlugin):
  27. """
  28. Map IP network names and aliases to DMD 'interface' objects
  29. """
  30. order = 80
  31. maptype = "InterfaceMap"
  32. compname = "os"
  33. relname = "interfaces"
  34. modname = "Products.ZenModel.IpInterface"
  35. deviceProperties = \
  36. SnmpPlugin.deviceProperties + ('zInterfaceMapIgnoreNames',
  37. 'zInterfaceMapIgnoreTypes')
  38.  
  39. # Interface related tables likely to be used in all subclasses.
  40.  
  41. # gets data for eth0 and rf0 because they are not in su table
  42. columns = {
  43. '.1.3.6.1.4.1.5454.1.30.1.8' : 'ipAddress',
  44. '.1.3.6.1.4.1.5454.1.30.1.9' : 'netmask',
  45. '.1.3.6.1.4.1.5454.1.30.1.2' : 'macaddress',
  46. '.1.3.6.1.4.1.5454.1.30.1.5' : 'apsystemDefOpMode',
  47. '.1.3.6.1.4.1.5454.1.30.1.6' : 'apsystemCurOpMode',
  48. '.1.3.6.1.4.1.5454.1.30.1.7' : 'apsystemActivateOpMode'
  49. }
  50. snmpGetMap = GetMap(columns)
  51.  
  52.  
  53. # gets data for su's
  54. snmpGetTableMaps = (
  55. GetTableMap('iftable', '.1.3.6.1.4.1.5454.1.30.3.6.1',
  56. {'.1': 'ifindex',
  57. #'.8': 'id',
  58. #'.3': 'type',
  59. #'.4': 'mtu',
  60. #'.5': 'speed',
  61. '.5': 'ipAddress',
  62. '.6': 'netmask',
  63. '.8': 'description',
  64. '.14': 'suAssociation',
  65. '.2': 'macaddress'}
  66. #'.7': 'adminStatus',
  67. #'.8': 'operStatus'}
  68. #'.6' : 'ifHCInOctets',
  69. #'.7' : 'ifHCInUcastPkts',
  70. #'.15': 'highSpeed',
  71.  
  72. ),
  73. )
  74.  
  75.  
  76. def process(self, device, results, log):
  77. """
  78. From SNMP info gathered from the device, convert them
  79. to interface objects.
  80. """
  81. getdata, tabledata = results
  82. log.info('Modeler %s processing data for device %s', self.name(), device.id)
  83. log.debug( "%s tabledata = %s" % (device.id,tabledata) )
  84.  
  85. if not self.checkColumns(getdata, self.columns, log):
  86. return
  87. eth0 = self.objectMap(getdata)
  88. rf0 = self.objectMap(getdata)
  89. eth0.ifindex = ''
  90. eth0.id = 'eth0'
  91. eth0.description = 'Ethernet interface on AP'
  92. eth0.adminStatus = 1
  93. eth0.operStatus = 1
  94.  
  95.  
  96. rf0.ifindex = ''
  97. rf0.id = 'rf0'
  98. rf0.description = 'RF Interface on AP (i.e. Radio)'
  99. del(rf0.macaddress)
  100. if getattr(rf0,'apsystemDefOpMode') == 0 and getattr(rf0,'apsystemActivateOpMode'):
  101. rf0.adminStatus = 1
  102. else:
  103. rf0.adminStatus = 0
  104.  
  105. rf0.operStatus = not getattr(rf0,'apsystemCurOpMode')
  106.  
  107. rm = self.relMap()
  108.  
  109. om = self.processInt(log, device, rf0)
  110. if om: rm.append(om)
  111.  
  112. om = self.processInt(log, device, eth0)
  113. if om: rm.append(om)
  114.  
  115. iftable = tabledata.get("iftable")
  116. if iftable is None:
  117. log.error("Unable to get data for %s for iftable -- skipping model" % device.id)
  118. return None
  119.  
  120. omtable = {}
  121.  
  122. for iface in iftable.values():
  123. om = self.processInt(log, device, iface)
  124. if om: rm.append(om)
  125.  
  126. return rm
  127.  
  128.  
  129. def processInt(self, log, device, iface):
  130. """
  131. Convert each interface into an object map, if possible
  132. Return None if the zProperties match the name or type
  133. of this iface.
  134. """
  135. om = self.objectMap(iface)
  136. if not hasattr(om, 'id'):
  137. log.debug( "Can't find 'id' after self.objectMap(iface)"
  138. " -- using autonaming rule" )
  139. om.id = 'suid%s' % iface.get('ifindex', "")
  140.  
  141. om.interfaceName = om.id
  142. om.title = om.id
  143. om.id = self.prepId(om.interfaceName)
  144. if not om.id:
  145. log.debug( "prepId(%s) doesn't return an id -- skipping" % (
  146. om.interfaceName))
  147. return None
  148.  
  149. dontCollectIntNames = getattr(device, 'zInterfaceMapIgnoreNames', None)
  150. if dontCollectIntNames and re.search(dontCollectIntNames, om.interfaceName):
  151. log.debug( "Interface %s matched the zInterfaceMapIgnoreNames zprop '%s'" % (
  152. om.interfaceName, getattr(device, 'zInterfaceMapIgnoreNames')))
  153. return None
  154.  
  155. if om.id.startswith('suid'):
  156. om.type = 'TrangoSU'
  157. # su set operstatus and adminstatus based on suAssociation
  158. if getattr(om,'suAssociation') == 3:
  159. om.adminStatus = 0
  160. om.operStatus = 0
  161. elif getattr(om,'suAssociation') == 1:
  162. om.adminStatus = 1
  163. om.operStatus = 1
  164. else:
  165. om.adminStatus = 1
  166. om.operStatus = 0
  167. elif om.id.startswith('eth'):
  168. om.type = 'TrangoAP_eth'
  169. elif om.id.startswith('rf'):
  170. om.type = 'TrangoAP_rf'
  171. else:
  172. om.type = self.ifTypes.get(str(getattr(om, 'type', 1)), "Unknown")
  173.  
  174. dontCollectIntTypes = getattr(device, 'zInterfaceMapIgnoreTypes', None)
  175. if dontCollectIntTypes and re.search(dontCollectIntTypes, om.type):
  176. log.debug( "Interface %s type %s matched the zInterfaceMapIgnoreTypes zprop '%s'" % (
  177. om.interfaceName, om.type,
  178. getattr(device, 'zInterfaceMapIgnoreTypes')))
  179. return None
  180.  
  181. # Append _64 to interface type if high-capacity counters are supported
  182. if hasattr(om, 'hcCounters'):
  183. om.type += "_64"
  184. del(om.hcCounters)
  185.  
  186. if hasattr(om, 'macaddress'):
  187. if isinstance(om.macaddress, basestring):
  188. om.macaddress = self.asmac(om.macaddress)
  189. else:
  190. log.debug("The MAC address for interface %s is invalid (%s)" \
  191. " -- ignoring", om.id, om.macaddress)
  192.  
  193. # Handle misreported operStatus from Linux tun devices
  194. if om.id.startswith('tun') and om.adminStatus == 1: om.operStatus = 1
  195.  
  196. # Net-SNMP on Linux will always report the speed of bond interfaces as
  197. # 10Mbps. This is probably due to the complexity of figuring out the
  198. # real speed which would take into account all bonded interfaces and
  199. # the bonding method (aggregate/failover). The problem is that 10Mbps
  200. # is a really bad default. The following check changes this default to
  201. # 1Gbps instead. See the following article that explains how you can
  202. # manually set this per-interface in the device's snmpd.conf for better
  203. # accuracy.
  204. #
  205. # http://whocares.de/2007/12/28/speed-up-your-bonds/
  206. if om.id.startswith('bond') and om.speed == 1e7:
  207. newspeed = 1000000000
  208. log.debug( "Resetting bond interface %s speed from %s to %s" % (
  209. om.interfaceName, om.speed, newspeed))
  210. om.speed = newspeed
  211.  
  212. if hasattr(om, 'ipAddress'):
  213. ip = om.ipAddress
  214. ip_parts = ip.split('.')
  215. # If the ip address has five octets, that probably
  216. # means this is a classless subnet (that is, <256). Usually,
  217. # the first 4 octets will be the ipAddress we care about.
  218. # Regardless, we will be using the ip address in the row
  219. # later anyway.
  220. if len(ip_parts) == 5:
  221. ipAddress = '.'.join(ip_parts[:-1])
  222.  
  223. if not hasattr(om, 'setIpAddresses'):
  224. om.setIpAddresses = []
  225. if hasattr(om, 'netmask'):
  226. ip = ip + "/" + str(self.maskToBits(om.netmask.strip()))
  227.  
  228. # Ignore IP addresses with a 0.0.0.0 netmask.
  229. if ip.endswith("/0"):
  230. log.warn("Ignoring IP address with 0.0.0.0 netmask: %s", ip)
  231. else:
  232. om.setIpAddresses.append(ip)
  233.  
  234.  
  235.  
  236. return om
  237.  
  238.  
  239. ifTypes = {'1': 'Other',
  240. '2': 'regular1822',
  241. '3': 'hdh1822',
  242. '4': 'ddnX25',
  243. '5': 'rfc877x25',
  244. '6': 'ethernetCsmacd',
  245. '7': 'iso88023Csmacd',
  246. '8': 'iso88024TokenBus',
  247. '9': 'iso88025TokenRing',
  248. '10': 'iso88026Man',
  249. '11': 'starLan',
  250. '12': 'proteon10Mbit',
  251. '13': 'proteon80Mbit',
  252. '14': 'hyperchannel',
  253. '15': 'fddi',
  254. '16': 'lapb',
  255. '17': 'sdlc',
  256. '18': 'ds1',
  257. '19': 'e1',
  258. '20': 'basicISDN',
  259. '21': 'primaryISDN',
  260. '22': 'propPointToPointSerial',
  261. '23': 'ppp',
  262. '24': 'softwareLoopback',
  263. '25': 'eon',
  264. '26': 'ethernet-3Mbit',
  265. '27': 'nsip',
  266. '28': 'slip',
  267. '29': 'ultra',
  268. '30': 'ds3',
  269. '31': 'sip',
  270. '32': 'frame-relay',
  271. '33': 'rs232',
  272. '34': 'para',
  273. '35': 'arcnet',
  274. '36': 'arcnetPlus',
  275. '37': 'atm',
  276. '38': 'miox25',
  277. '39': 'sonet',
  278. '40': 'x25ple',
  279. '41': 'iso88022llc',
  280. '42': 'localTalk',
  281. '43': 'smdsDxi',
  282. '44': 'frameRelayService',
  283. '45': 'v35',
  284. '46': 'hssi',
  285. '47': 'hippi',
  286. '48': 'modem',
  287. '49': 'aal5',
  288. '50': 'sonetPath',
  289. '51': 'sonetVT',
  290. '52': 'smdsIcip',
  291. '53': 'propVirtual',
  292. '54': 'propMultiplexor',
  293. '55': '100BaseVG',
  294. '56': 'Fibre Channel',
  295. '57': 'HIPPI Interface',
  296. '58': 'Obsolete for FrameRelay',
  297. '59': 'ATM Emulation of 802.3 LAN',
  298. '60': 'ATM Emulation of 802.5 LAN',
  299. '61': 'ATM Emulation of a Circuit',
  300. '62': 'FastEthernet (100BaseT)',
  301. '63': 'ISDN',
  302. '64': 'CCITT V.11_X.21',
  303. '65': 'CCITT V.36',
  304. '66': 'CCITT G703 at 64Kbps',
  305. '67': 'Obsolete G702 see DS1-MIB',
  306. '68': 'SNA QLLC',
  307. '69': 'Full Duplex Fast Ethernet (100BaseFX)',
  308. '70': 'Channel',
  309. '71': 'Radio Spread Spectrum (802.11)',
  310. '72': 'IBM System 360_370 OEMI Channel',
  311. '73': 'IBM Enterprise Systems Connection',
  312. '74': 'Data Link Switching',
  313. '75': 'ISDN S_T Interface',
  314. '76': 'ISDN U Interface',
  315. '77': 'Link Access Protocol D (LAPD)',
  316. '78': 'IP Switching Opjects',
  317. '79': 'Remote Source Route Bridging',
  318. '80': 'ATM Logical Port',
  319. '81': 'ATT DS0 Point (64 Kbps)',
  320. '82': 'ATT Group of DS0 on a single DS1',
  321. '83': 'BiSync Protocol (BSC)',
  322. '84': 'Asynchronous Protocol',
  323. '85': 'Combat Net Radio',
  324. '86': 'ISO 802.5r DTR',
  325. '87': 'Ext Pos Loc Report Sys',
  326. '88': 'Apple Talk Remote Access Protocol',
  327. '89': 'Proprietary Connectionless Protocol',
  328. '90': 'CCITT-ITU X.29 PAD Protocol',
  329. '91': 'CCITT-ITU X.3 PAD Facility',
  330. '92': 'MultiProtocol Connection over Frame_Relay',
  331. '93': 'CCITT-ITU X213',
  332. '94': 'Asymetric Digitial Subscriber Loop (ADSL)',
  333. '95': 'Rate-Adapt Digital Subscriber Loop (RDSL)',
  334. '96': 'Symetric Digitial Subscriber Loop (SDSL)',
  335. '97': 'Very High Speed Digitial Subscriber Loop (HDSL)',
  336. '98': 'ISO 802.5 CRFP',
  337. '99': 'Myricom Myrinet',
  338. '100': 'Voice recEive and transMit (voiceEM)',
  339. '101': 'Voice Foreign eXchange Office (voiceFXO)',
  340. '102': 'Voice Foreign eXchange Station (voiceFXS)',
  341. '103': 'Voice Encapulation',
  342. '104': 'Voice Over IP Encapulation',
  343. '105': 'ATM DXI',
  344. '106': 'ATM FUNI',
  345. '107': 'ATM IMA',
  346. '108': 'PPP Multilink Bundle',
  347. '109': 'IBM IP over CDLC',
  348. '110': 'IBM Common Link Access to Workstation',
  349. '111': 'IBM Stack to Stack',
  350. '112': 'IBM Virtual IP Address (VIPA)',
  351. '113': 'IBM Multi-Protocol Channel Support',
  352. '114': 'IBM IP over ATM',
  353. '115': 'ISO 802.5j Fiber Token Ring',
  354. '116': 'IBM Twinaxial Data Link Control (TDLC)',
  355. '117': 'Gigabit Ethernet',
  356. '118': 'Higher Data Link Control (HDLC)',
  357. '119': 'Link Access Protocol F (LAPF)',
  358. '120': 'CCITT V.37',
  359. '121': 'CCITT X.25 Multi-Link Protocol',
  360. '122': 'CCITT X.25 Hunt Group',
  361. '123': 'Transp HDLC',
  362. '124': 'Interleave Channel',
  363. '125': 'Fast Channel',
  364. '126': 'IP (for APPN HPR in IP Networks)',
  365. '127': 'CATV MAC Layer',
  366. '128': 'CATV Downstream Interface',
  367. '129': 'CATV Upstream Interface',
  368. '130': 'Avalon Parallel Processor',
  369. '131': 'Encapsulation Interface',
  370. '132': 'Coffee Pot',
  371. '133': 'Circuit Emulation Service',
  372. '134': 'ATM Sub Interface',
  373. '135': 'Layer 2 Virtual LAN using 802.1Q',
  374. '136': 'Layer 3 Virtual LAN using IP',
  375. '137': 'Layer 3 Virtual LAN using IPX',
  376. '138': 'IP Over Power Lines',
  377. '139': 'Multi-Media Mail over IP',
  378. '140': 'Dynamic synchronous Transfer Mode (DTM)',
  379. '141': 'Data Communications Network',
  380. '142': 'IP Forwarding Interface',
  381. '143': 'Multi-rate Symmetric DSL',
  382. '144': 'IEEE1394 High Performance Serial Bus',
  383. '145': 'HIPPI-6400',
  384. '146': 'DVB-RCC MAC Layer',
  385. '147': 'DVB-RCC Downstream Channel',
  386. '148': 'DVB-RCC Upstream Channel',
  387. '149': 'ATM Virtual Interface',
  388. '150': 'MPLS Tunnel Virtual Interface',
  389. '151': 'Spatial Reuse Protocol',
  390. '152': 'Voice Over ATM',
  391. '153': 'Voice Over Frame Relay',
  392. '154': 'Digital Subscriber Loop over ISDN',
  393. '155': 'Avici Composite Link Interface',
  394. '156': 'SS7 Signaling Link',
  395. '157': 'Prop. P2P wireless interface',
  396. '158': 'Frame Forward Interface',
  397. '159': 'Multiprotocol over ATM AAL5',
  398. '160': 'USB Interface',
  399. '161': 'IEEE 802.3ad Link Aggregate',
  400. '162': 'BGP Policy Accounting',
  401. '163': 'FRF .16 Multilink Frame Relay',
  402. '164': 'H323 Gatekeeper',
  403. '165': 'H323 Voice and Video Proxy',
  404. '166': 'MPLS',
  405. '167': 'Multi-frequency signaling link',
  406. '168': 'High Bit-Rate DSL - 2nd generation',
  407. '169': 'Multirate HDSL2',
  408. '170': 'Facility Data Link 4Kbps on a DS1',
  409. '171': 'Packet over SONET_SDH Interface',
  410. '172': 'DVB-ASI Input',
  411. '173': 'DVB-ASI Output',
  412. '174': 'Power Line Communtications',
  413. '175': 'Non Facility Associated Signaling',
  414. '176': 'TR008',
  415. '177': 'Remote Digital Terminal',
  416. '178': 'Integrated Digital Terminal',
  417. '179': 'ISUP',
  418. '180': 'prop_Maclayer',
  419. '181': 'prop_Downstream',
  420. '182': 'prop_Upstream',
  421. '183': 'HIPERLAN Type 2 Radio Interface',
  422. '184': 'PropBroadbandWirelessAccesspt2multipt',
  423. '185': 'SONET Overhead Channel',
  424. '186': 'Digital Wrapper',
  425. '187': 'ATM adaptation layer 2',
  426. '188': 'MAC layer over radio links',
  427. '189': 'ATM over radio links',
  428. '190': 'Inter Machine Trunks',
  429. '191': 'Multiple Virtual Lines DSL',
  430. '192': 'Long Rach DSL',
  431. '193': 'Frame Relay DLCI End Point',
  432. '194': 'ATM VCI End Point',
  433. '195': 'Optical Channel',
  434. '196': 'Optical Transport',
  435. '197': 'Proprietary ATM',
  436. '198': 'Voice Over Cable Interface',
  437. '199': 'Infiniband',
  438. '200': 'TE Link',
  439. '201': 'Q.2931',
  440. '202': 'Virtual Trunk Group',
  441. '203': 'SIP Trunk Group',
  442. '204': 'SIP Signaling',
  443. '205': 'CATV Upstream Channel',
  444. '206': 'Acorn Econet',
  445. '207': 'FSAN 155Mb Symetrical PON interface',
  446. '208': 'FSAN622Mb Symetrical PON interface',
  447. '209': 'Transparent bridge interface',
  448. '210': 'Interface common to multiple lines',
  449. '211': 'voice E and M Feature Group D',
  450. '212': 'voice FGD Exchange Access North American',
  451. '213': 'voice Direct Inward Dialing',
  452. '214': 'MPEG transport interface',
  453. '215': '6to4 interface (DEPRECATED)',
  454. '216': 'GTP (GPRS Tunneling Protocol)',
  455. '217': 'Paradyne EtherLoop 1',
  456. '218': 'Paradyne EtherLoop 2',
  457. '219': 'Optical Channel Group',
  458. '220': 'HomePNA ITU-T G.989',
  459. '221': 'Generic Framing Procedure (GFP)',
  460. '222': 'Layer 2 Virtual LAN using Cisco ISL',
  461. '223': 'Acteleis proprietary MetaLOOP High Speed Link',
  462. '224': 'FCIP Link',
  463. '225': 'Resilient Packet Ring Interface Type',
  464. '226': 'RF Qam Interface',
  465. '227': 'Link Management Protocol',
  466. '228': 'Cambridge Broadband Limited VectaStar',
  467. '229': 'CATV Modular CMTS Downstream Interface',
  468. '230': 'Asymmetric Digital Subscriber Loop Version 2',
  469. '231': 'MACSecControlled',
  470. '232': 'MACSecUncontrolled',
  471. }
Advertisement
Add Comment
Please, Sign In to add comment