ip_addr.py place in: Products/DataCollector/plugins/zenoss/cmd/linux/ Then restart Zenoss
Code: ########################################################################### # # This program is an addendum to Zenoss Core, an open source monitoring platform. # Copyright (C) 2009, Ross R. Duncan # # This program is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License version 2 as published by # the Free Software Foundation. # # For complete information on Zenoss please visit: http://www.zenoss.com/oss/ # ########################################################################### import re from CollectorPlugin import CommandPlugin class ip_addr(CommandPlugin): """ ip_addr maps a linux 'ip addr show' command to the interfaces relation. """ maptype = "InterfaceMap" command = '/sbin/ip addr show' compname = "os" relname = "interfaces" modname = "Products.ZenModel.IpInterface" ifstart = re.compile( "^\d+:\s+(\S+):\s+<(\S+)> mtu (\d+).*" ).search v4addr = re.compile( "^\s+inet (\S+)/(\d+) .*" ).search link = re.compile( "^\s+link/(.*) (\S+) brd .*" ).search def condition(self, device, log): return device.os.uname == 'Linux' def process(self, device, results, log): log.info('Collecting interfaces for device %s' % device.id) rm = self.relMap() rlines = results.split("\n") iface = None for line in rlines: # reset state to no interface if not line.strip(): iface = None # new interface starting miface = self.ifstart(line) if miface: # start new interface and get name, flags, and mtu iface = self.objectMap() rm.append(iface) name, flags, mtu = miface.groups() if "UP" in flags: iface.operStatus = 1 else: iface.operStatus = 2 if "NO-CARRIER" in flags: iface.adminStatus = 2 else: iface.adminStatus = 1 iface.mtu = int(mtu) iface.interfaceName = name iface.id = self.prepId(name) continue # get the ip address of an interface maddr = self.v4addr(line) if maddr and iface: # get ip and netmask ip, netmask = maddr.groups() if not hasattr(iface, 'setIpAddresses'): iface.setIpAddresses = [] iface.setIpAddresses.append( "%s/%s" % (ip, netmask) ) # get the state UP/DOWN of the interface mlink = self.link(line) if mlink and iface: # get interface type and mac address itype, iface.macaddress = mlink.groups() if itype.startswith("ether"): itype = "ethernetCsmacd" iface.type = itype.strip() return rm -------------------- m2f -------------------- Read this topic online here: http://forums.zenoss.com/viewtopic.php?p=31015#31015 -------------------- m2f -------------------- _______________________________________________ zenoss-users mailing list [email protected] http://lists.zenoss.org/mailman/listinfo/zenoss-users
