Trees | Indices | Help |
|
---|
|
1 ########################################################################### 2 # 3 # This program is part of Zenoss Core, an open source monitoring platform. 4 # Copyright (C) 2007, 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 import re 15 16 from CommandPlugin import CommandPlugin 1719 """ 20 Linux_ifconfig maps a linux ifconfig command to the interfaces relation. 21 """ 22 maptype = "InterfaceMap" 23 command = 'ifconfig' 24 compname = "os" 25 relname = "interfaces" 26 modname = "Products.ZenModel.IpInterface" 27 28 ifstart = re.compile( 29 "^(\S+)\s+Link encap:(.+)HWaddr (\S+)" 30 "|^(\S+)\s+Link encap:(.+)" 31 ).search 32 v4addr = re.compile("inet addr:(\S+).*Mask:(\S+)").search 33 flags = re.compile("^(.*) MTU:(\d+)\s+Metric:.*").search 34 35 39 407842 log.info('Collecting interfaces for device %s' % device.id) 43 rm = self.relMap() 44 rlines = results.split("\n") 45 for line in rlines: 46 m = self.ifstart(line) 47 if m: 48 # start new interface and get name, type, and macaddress 49 iface = self.objectMap() 50 rm.append(iface) 51 if m.lastindex == 3: 52 name, itype, iface.macaddress=m.groups()[:3] 53 else: 54 name, itype = m.groups()[3:] 55 iface.type = itype.strip() 56 # Left iface.name in place, but added 57 # iface.title for consistency 58 iface.title = name 59 iface.name = name 60 iface.id = self.prepId(name) 61 continue 62 m = self.v4addr(line) 63 if m: 64 # get ip and netmask 65 ip, netmask = m.groups() 66 netmask = self.maskToBits(netmask) 67 iface.setIpAddresses = ["%s/%s" % (ip, netmask)] 68 m = self.flags(line) 69 if m: 70 # get adminStatus, operStatus, and mtu 71 flags, mtu = m.groups() 72 if "UP" in flags: iface.operStatus = 1 73 else: iface.operStatus = 2 74 if "RUNNING" in flags: iface.adminStatus = 1 75 else: iface.adminStatus = 2 76 iface.mtu = int(mtu) 77 return rm
Trees | Indices | Help |
|
---|
Generated by Epydoc 3.0beta1 on Thu Oct 25 16:28:35 2007 | http://epydoc.sourceforge.net |