示例#1
0
 def getDeviceBrains(self, uid=None, start=0, limit=50, sort='name',
                     dir='ASC', params=None, hashcheck=None):
     cat = ICatalogTool(self._getObject(uid))
     reverse = dir=='DESC'
     qs = []
     query = None
     globFilters = {}
     if params is None:
         params = {}
     for key, value in params.iteritems():
         if key == 'ipAddress':
             ip = ensureIp(value)
             try:
                 checkip(ip)
             except IpAddressError:
                 pass
             else:
                 if numbip(ip):
                     minip, maxip = getSubnetBounds(ip)
                     qs.append(Between('ipAddress', str(minip), str(maxip)))
         elif key == 'deviceClass':
             qs.append(MatchRegexp('uid', '(?i).*%s.*' %
                                   value))
         elif key == 'productionState':
             qs.append(Or(*[Eq('productionState', str(state))
                          for state in value]))
         else:
             globFilters[key] = value
     if qs:
         query = And(*qs)
     brains = cat.search('Products.ZenModel.Device.Device', start=start,
                        limit=limit, orderby=sort, reverse=reverse,
                         query=query, globFilters=globFilters, hashcheck=hashcheck)
     return brains
示例#2
0
 def getDeviceBrains(self, uid=None, start=0, limit=50, sort='name',
                     dir='ASC', params=None, hashcheck=None):
     cat = ICatalogTool(self._getObject(uid))
     reverse = dir=='DESC'
     qs = []
     query = None
     globFilters = {}
     if params is None:
         params = {}
     for key, value in params.iteritems():
         if key == 'ipAddress':
             ip = ensureIp(value)
             try:
                 checkip(ip)
             except IpAddressError:
                 pass
             else:
                 if numbip(ip):
                     minip, maxip = getSubnetBounds(ip)
                     qs.append(Between('ipAddress', str(minip), str(maxip)))
         elif key == 'deviceClass':
             qs.append(MatchRegexp('uid', '(?i).*%s.*' %
                                   value))
         elif key == 'productionState':
             qs.append(Or(*[Eq('productionState', str(state))
                          for state in value]))
         else:
             globFilters[key] = value
     if qs:
         query = And(*qs)
     brains = cat.search('Products.ZenModel.Device.Device', start=start,
                        limit=limit, orderby=sort, reverse=reverse,
                         query=query, globFilters=globFilters, hashcheck=hashcheck)
     return brains
示例#3
0
 def __init__(self, id, netmask=24):
     checkip(id)
     ManagedEntity.__init__(self, ipwrap(id))
     ipobj = IPAddress(ipunwrap_strip(id))
     if ipobj.version == 6:
         # No user-definable subnet masks for IPv6
         netmask = 64
     self._netmask = maskToBits(netmask)
     self.ptrName = None
     self.title = ipunwrap(id)
     self.version = ipobj.version
示例#4
0
 def __init__(self, id, netmask=24):
     checkip(id)
     ManagedEntity.__init__(self, ipwrap(id))
     ipobj = IPAddress(ipunwrap_strip(id))
     if ipobj.version == 6:
         # No user-definable subnet masks for IPv6
         netmask = 64
     self._netmask = maskToBits(netmask)
     self.ptrName = None
     self.title = ipunwrap(id)
     self.version = ipobj.version
示例#5
0
 def setIpAddress(self, ip):
     """
     Set the IP address. Use the format 1.1.1.1/24 to also set the netmask
     """
     iparray = ip.split("/")
     if len(iparray) > 1:
         ip = iparray[0]
         self._netmask = maskToBits(iparray[1])
     checkip(ip)
     aqself = self.primaryAq()  #set aq path
     network = aqself.aq_parent
     netip = netFromIpAndNet(ip, network.netmask)
     if netip == network.id:
         network._renameObject(aqself.id, ipwrap(ip))
     else:
         raise WrongSubnetError("IP %s is in a different subnet than %s" %
                                (ipunwrap(ip), ipunwrap(self.id)))
示例#6
0
 def setIpAddress(self, ip):
     """
     Set the IP address. Use the format 1.1.1.1/24 to also set the netmask
     """
     iparray = ip.split("/")
     if len(iparray) > 1:
         ip = iparray[0]
         self._netmask = maskToBits(iparray[1])
     checkip(ip)
     aqself = self.primaryAq() #set aq path
     network = aqself.aq_parent
     netip = netFromIpAndNet(ip, network.netmask)
     if netip == network.id:
         network._renameObject(aqself.id, ipwrap(ip))
     else:
         raise WrongSubnetError(
                 "IP %s is in a different subnet than %s" % (ipunwrap(ip), ipunwrap(self.id)) )
示例#7
0
 def getDeviceBrains(self, uid=None, start=0, limit=50, sort='name',
                     dir='ASC', params=None, hashcheck=None):
     cat = ICatalogTool(self._getObject(uid))
     reverse = bool(dir == 'DESC')
     qs = []
     query = None
     globFilters = {}
     if params is None:
         params = {}
     for key, value in params.iteritems():
         if key == 'ipAddress':
             ip = ensureIp(value)
             try:
                 checkip(ip)
             except IpAddressError:
                 pass
             else:
                 if numbip(ip):
                     minip, maxip = getSubnetBounds(ip)
                     qs.append(Between('ipAddress', str(minip), str(maxip)))
         elif key == 'deviceClass':
             qs.append(MatchRegexp('uid', '(?i).*%s.*' % value))
         # ZEN-10057 - move filtering on indexed groups/systems/location from post-filter to query
         elif key in organizersToClass:
             organizerQuery = self.findMatchingOrganizers(organizersToClass[key], organizersToPath[key], value)
             if not organizerQuery:
                 return []
             qs.append(organizerQuery)
         elif key == 'productionState':
             qs.append(Or(*[Eq('productionState', str(state))
                          for state in value]))
         else:
             globFilters[key] = value
     if qs:
         query = And(*qs)
     brains = cat.search(
         'Products.ZenModel.Device.Device', start=start,
         limit=limit, orderby=sort, reverse=reverse,
         query=query, globFilters=globFilters, hashcheck=hashcheck
     )
     return brains
示例#8
0
 def getDeviceBrains(self, uid=None, start=0, limit=50, sort='name',
                     dir='ASC', params=None, hashcheck=None):
     cat = ICatalogTool(self._getObject(uid))
     reverse = bool(dir == 'DESC')
     qs = []
     query = None
     globFilters = {}
     if params is None:
         params = {}
     for key, value in params.iteritems():
         if key == 'ipAddress':
             ip = ensureIp(value)
             try:
                 checkip(ip)
             except IpAddressError:
                 pass
             else:
                 if numbip(ip):
                     minip, maxip = getSubnetBounds(ip)
                     qs.append(Between('ipAddress', str(minip), str(maxip)))
         # ZEN-10057 - move filtering on indexed groups/systems/location from post-filter to query
         elif key in organizersToClass:
             organizerQuery = self.findMatchingOrganizers(organizersToClass[key], organizersToPath[key], value)
             if not organizerQuery:
                 return []
             qs.append(organizerQuery)
         elif key == 'productionState':
             qs.append(Or(*[Eq('productionState', str(state))
                          for state in value]))
         else:
             globFilters[key] = value
     if qs:
         query = And(*qs)
     brains = cat.search(
         'Products.ZenModel.Device.Device', start=start,
         limit=limit, orderby=sort, reverse=reverse,
         query=query, globFilters=globFilters, hashcheck=hashcheck
     )
     return brains
示例#9
0
    def process(self, device, results, log):
        log.info('Collecting interfaces for device %s' % device.id)
        skipifregex = getattr(device, 'zInterfaceMapIgnoreNames', None)
        log.debug("zIpInterfaceMapIgnoreNames = '%s'" % skipifregex)

        maps = []
        rm = self.relMap()

        adapterResults = results["Win32_NetworkAdapterConfiguration"]
        raw = results["Win32_PerfRawData_Tcpip_NetworkInterface"]

        perfmonInstanceMap = self.buildPerfmonInstances(adapterResults, log)

        for adapter in adapterResults:
            if adapter.description is not None:
                if skipifregex and re.match(skipifregex, adapter.description):
                    log.debug( "Interface %s matched regex -- skipping" % \
                               adapter.description)
                    continue

                om = self.objectMap()

                ips = []
                if adapter.ipaddress:
                    log.debug("Network adapter '%s' has IP addresses of %s/%s",
                              adapter.description, adapter.ipaddress,
                              adapter.ipsubnet)
                    for ipRecord, ipMask in zip(adapter.ipaddress,
                                                adapter.ipsubnet):
                        # make sure the IP Address for this adapter is valid
                        # invalid addresses will usually mean IPv6
                        try:
                            checkip(ipRecord)
                            if not ipMask:
                                raise IpAddressError()

                            ipEntry = '%s/%s' % (ipRecord,
                                                 self.maskToBits(ipMask))
                            log.debug("Adding IP entry %s", ipEntry)
                            ips.append(ipEntry)
                        except IpAddressError:
                            log.debug(
                                "Invalid IP address %s encountered and "
                                "skipped", ipRecord)

                om.setIpAddresses = ips
                om.interfaceName = adapter.description
                om.macaddress = adapter.macaddress
                om.description = adapter.description
                om.mtu = adapter.mtu
                om.monitor = om.operStatus = bool(adapter.ipenabled)
                om.id = self.prepId(adapter.description)

                # Windows XP, Windows 2000, and Windows NT 4.0:
                # This property is not available. Use the Index instead if not
                # not available.
                try:
                    om.ifindex = adapter.interfaceindex
                except AttributeError:
                    om.ifindex = adapter.index

                if perfmonInstanceMap.has_key(adapter.index):
                    om.perfmonInstance = perfmonInstanceMap[adapter.index]
                else:
                    log.warning(
                        "Adapter '%s':%d does not have a perfmon "
                        "instance name and will not be monitored for "
                        "performance data", adapter.description, adapter.index)

                # These virtual adapters should not be monitored as they are
                # like loopback, and are NOT available via perfmon
                if 'Microsoft Failover Cluster Virtual Adapter' in om.description:
                    om.monitor = False

                # TODO expensive O(n^2) algorithm to worry about if N gets large
                for data in raw:
                    if data.Name == adapter.description:
                        om.speed = data.CurrentBandwidth

                om.id = self.prepId(adapter.description)
                rm.append(om)
        maps.append(rm)
        return maps
    def process(self, device, results, log):
        log.info(
            "Modeler %s processing data for device %s",
            self.name(), device.id)

        netInt = results.get('Win32_NetworkAdapter', ())
        netConf = results.get('Win32_NetworkAdapterConfiguration', ())

        regresults = results.get('registry')
        if regresults:
            regresults = ''.join(regresults.stdout).split('|')

        broadcomresults = results.get('broadcomnic')
        if broadcomresults:
            broadcomresults = ''.join(broadcomresults.stdout).split('|')

        # Performance Counters for Windows 2012
        counters = self.sanitize_counters(results.get('counters2012'))

        # Interface Map
        mapInter = []

        # Virtual Team Interface Map
        mapTeamInter = []

        # Registry Interface formatting
        regInterface = {}
        if regresults:
            for intFace in regresults:
                interfaceDict = {}
                try:
                    for keyvalues in intFace.split(';'):
                        key, value = keyvalues.split('=')
                        interfaceDict[key] = value
                    regInterface[int(interfaceDict['id'])] = interfaceDict
                except (KeyError, ValueError):
                    pass

        # Broadcom member nic map
        bdcDict = {}
        if broadcomresults:
            for memberNic in broadcomresults:
                memberDict = {}
                try:
                    for keyvalues in memberNic.split(';'):
                        key, value = keyvalues.split('=')
                        memberDict[key] = value
                    bdcDict[memberDict['id']] = memberDict['teamname']
                except (KeyError, ValueError):
                    pass
        perfmonInstanceMap = self.buildPerfmonInstances(netConf, log, counters)

        for inter in netInt:
            #Get the Network Configuration data for this interface

            # Merge broadcom NIC Team information into object
            try:
                inter.TeamName = bdcDict[inter.GUID]
            except (KeyError, AttributeError):
                pass

            # Merge registry data for Team Interface into object
            try:
                interfaceRegistry = regInterface[int(inter.DeviceID)]
                if not interfaceRegistry['teamname']:
                    if not interfaceRegistry['altteamname']:
                        inter.TeamName = inter.NetConnectionID
                    else:
                        inter.TeamMode = '0'
                        inter.TeamName = interfaceRegistry['altteamname']
                    inter.netinterfaceid = interfaceRegistry['netinterfaceid']
                else:
                    inter.TeamName = interfaceRegistry['teamname']
                    inter.TeamMode = interfaceRegistry['teammode']

                inter.Provider = interfaceRegistry['provider']
                inter.InterfaceID = interfaceRegistry['netinterfaceid']
                inter.TeamMAC = interfaceRegistry['networkaddress']

            except (KeyError):
                pass
            for intconf in netConf:
                if intconf.InterfaceIndex == inter.InterfaceIndex:
                    interconf = intconf
                    break
            else:
                log.warn(
                    "No configuration found for %s on %s",
                    inter.Description, device.id)

                continue

            if getattr(interconf, 'ServiceName', None) is not None:
                if 'netft' in interconf.ServiceName.lower():
                    # This is a Network Fault-Tolerant interface
                    # This should not be modeled as a local interface
                    continue

            ips = []

            if getattr(interconf, 'IPAddress', None) is not None:
                iplist = []
                masklist = []

                if isinstance(interconf.IPAddress, basestring):
                    iplist.append(interconf.IPAddress)
                else:
                    iplist = interconf.IPAddress

                if isinstance(interconf.IPSubnet, basestring):
                    masklist.append(interconf.IPSubnet)
                else:
                    masklist = interconf.IPSubnet

                for ip, mask in itertools.izip(iplist, masklist):
                    try:
                        checkip(ip)
                    except IpAddressError:
                        log.debug(
                            "Invalid IP Address {} encountered and skipped"
                            .format(ip))

                        continue

                    ips.append('{}/{}'.format(ip, self.maskToBits(mask)))

            int_om = self.objectMap()
            int_om.id = self.prepId(
                standardizeInstance(
                    inter.Index + "-" + interconf.Description))

            int_om.title = interconf.Description
            int_om.setIpAddresses = ips
            int_om.interfaceName = inter.Description
            if getattr(inter, 'NetConnectionID') is not None:
                int_om.description = inter.NetConnectionID
            else:
                int_om.description = interconf.Description
            int_om.macaddress = inter.MACAddress

            if getattr(interconf, 'MTU', 0) is not None:
                int_om.mtu = interconf.MTU
            else:
                int_om.mtu = 0

            if getattr(inter, 'Speed', 0) is not None:
                int_om.speed = int(inter.Speed)
            else:
                int_om.speed = 0

            int_om.duplex = 0
            int_om.type = inter.AdapterType

            try:
                int_om.adminStatus = 0
                # ZEN-15493: workaround LPU cannot access NetEnabled property
                # Check IPEnabled property of configuration
                if inter.NetEnabled is None:
                    if inter.NetConnectionStatus in ENABLED_NC_STATUSES:
                        int_om.adminStatus = 1
                    elif inter.NetConnectionStatus is None:
                        int_om.adminStatus = int(lookup_adminstatus(interconf.IPEnabled))
                else:
                    int_om.adminStatus = int(lookup_adminstatus(inter.NetEnabled))
            except (AttributeError):
                # Workaround for 2003 / XP
                if inter.NetConnectionStatus in ENABLED_NC_STATUSES:
                    int_om.adminStatus = 1

            try:
                int_om.ifindex = inter.InterfaceIndex
            except (AttributeError, TypeError):
                int_om.ifindex = inter.Index

            if inter.Index in perfmonInstanceMap:
                int_om.perfmonInstance = perfmonInstanceMap[inter.Index]
            else:
                log.warning("Adapter '%s':%d does not have a perfmon "
                            "instance name and will not be monitored for "
                            "performance data", inter.Description,
                            inter.Index)

            # These virtual adapters should not be monitored as they are
            # like loopback, and are NOT available via perfmon
            if 'Microsoft Failover Cluster Virtual Adapter' in int_om.description:
                int_om.monitor = False

            # These physical interfaces should not be monitored as they are
            # in a Team configuration and will be monitored at the Team interface

            if getattr(inter, 'TeamName', None) is not None:
                if 'TEAM' in inter.TeamName:
                    # Intel interface that is member of TEAM interface
                    int_om.teamname = inter.TeamName.split('-')[0].strip()
                    int_om.monitor = False
                else:
                    if hasattr(inter, 'GUID') and (inter.GUID in bdcDict):
                        # Broadcom interface that is member of TEAM interface
                        int_om.teamname = inter.TeamName
                        int_om.monitor = False

            # These interfaces are virtual TEAM interfaces
            if getattr(inter, 'TeamMode', None) is not None:
                if inter.TeamMode == '0':
                    if counters and counters.get(inter.netinterfaceid):
                        pass
                    else:
                        int_om.perfmonInstance = "\\network interface({0})".format(
                            "isatap." + inter.netinterfaceid)
                    log.debug('The TeamNic ID {0}'.format(int_om.id))
                    if not inter.TeamName:
                        # Get the team name from the Description of the interface
                        # This will be for Intel Team interfaces
                        int_om.teamname = interconf.Description.strip()
                    else:
                        # The Broadcom TeamName can be set early in the process
                        int_om.teamname = inter.TeamName
                    int_om.modname = 'ZenPacks.zenoss.Microsoft.Windows.TeamInterface'
                    mapTeamInter.append(int_om)
                    continue
            mapInter.append(int_om)

        # Set supporting interfaces on TEAM nics
        for teamNic in mapTeamInter:
            members = []
            for nic in mapInter:
                if getattr(nic, 'teamname', None) is not None:
                    if nic.teamname == teamNic.teamname:
                        # This nic is a member of this team interface
                        members.append(nic.id)

            teamNic.setInterfaces = members

        rm = self.relMap()
        rm.maps.extend(mapInter + mapTeamInter)

        # Filter interfaces using filtering zProperties.
        rm.maps = list(filter_maps(rm.maps, device, log))

        return rm
示例#11
0
    def process(self, device, results, log):
        log.info("Modeler %s processing data for device %s", self.name(),
                 device.id)

        netInt = results.get('Win32_NetworkAdapter', ())
        netConf = results.get('Win32_NetworkAdapterConfiguration', ())
        win32_pnpentities = results.get('win32_pnpentity', None)
        counter_instances = results.get('counters', ())
        operating_system = results.get('win32_OperatingSystem', (None, ))[0]
        if operating_system:
            # Version is in x.x.xxxx format, e.g. 6.1.7601 for 2008
            os_version = [int(x) for x in operating_system.Version.split('.')]
        else:
            # default to lowest version supported (2008)
            os_version = [6, 1]

        # Actual instance names should be pulled in from the Win32_PnPEntity class
        if win32_pnpentities and isinstance(win32_pnpentities, dict):
            pnpentities = win32_pnpentities.get('Win32_PnPEntity', None)
        else:
            pnpentities = None

        regresults = results.get('registry')
        if regresults:
            regresults = ''.join(regresults.stdout).split('|')

        broadcomresults = results.get('broadcomnic')
        if broadcomresults:
            broadcomresults = ''.join(broadcomresults.stdout).split('|')

        if not netInt and (broadcomresults or regresults or counter_instances):
            log.warn("Received incomplete Interface modeling results.")
            return

        # Performance Counters for Windows 2012
        counters = self.sanitize_counters(results.get('counters2012'))

        # Interface Map
        mapInter = []

        # Virtual Team Interface Map
        mapTeamInter = []

        # Registry Interface formatting
        regInterface = {}
        if regresults:
            for intFace in regresults:
                interfaceDict = {}
                try:
                    for keyvalues in intFace.split(';'):
                        key, value = keyvalues.split('=')
                        interfaceDict[key] = value
                    regInterface[int(interfaceDict['id'])] = interfaceDict
                except (KeyError, ValueError):
                    pass

        # Broadcom member nic map
        bdcDict = {}
        if broadcomresults:
            for memberNic in broadcomresults:
                memberDict = {}
                try:
                    for keyvalues in memberNic.split(';'):
                        key, value = keyvalues.split('=')
                        memberDict[key] = value
                    bdcDict[memberDict['id']] = memberDict['teamname']
                except (KeyError, ValueError):
                    pass
        perfmonInstanceMap = self.buildPerfmonInstances(
            netConf, log, counters, pnpentities, netInt, os_version)

        for inter in netInt:
            # Get the Network Configuration data for this interface

            # Merge broadcom NIC Team information into object
            try:
                inter.TeamName = bdcDict[inter.GUID]
            except (KeyError, AttributeError):
                pass

            # Merge registry data for Team Interface into object
            try:
                interfaceRegistry = regInterface[int(inter.DeviceID)]
                if not interfaceRegistry['teamname']:
                    if not interfaceRegistry['altteamname']:
                        inter.TeamName = inter.NetConnectionID
                    else:
                        inter.TeamMode = '0'
                        inter.TeamName = interfaceRegistry['altteamname']
                    inter.netinterfaceid = interfaceRegistry['netinterfaceid']
                else:
                    inter.TeamName = interfaceRegistry['teamname']
                    inter.TeamMode = interfaceRegistry['teammode']

                inter.Provider = interfaceRegistry['provider']
                inter.InterfaceID = interfaceRegistry['netinterfaceid']
                inter.TeamMAC = interfaceRegistry['networkaddress']

            except (KeyError):
                pass
            for intconf in netConf:
                if intconf.InterfaceIndex == inter.InterfaceIndex:
                    interconf = intconf
                    break
            else:
                log.warn("No configuration found for %s on %s",
                         inter.Description, device.id)

                continue

            if getattr(interconf, 'ServiceName', None) is not None:
                if 'netft' in interconf.ServiceName.lower():
                    # This is a Network Fault-Tolerant interface
                    # This should not be modeled as a local interface
                    continue

            ips = []

            if getattr(interconf, 'IPAddress', None) is not None:
                iplist = []
                masklist = []

                if isinstance(interconf.IPAddress, basestring):
                    iplist.append(interconf.IPAddress)
                else:
                    iplist = interconf.IPAddress

                if isinstance(interconf.IPSubnet, basestring):
                    masklist.append(interconf.IPSubnet)
                else:
                    masklist = interconf.IPSubnet

                for ip, mask in itertools.izip(iplist, masklist):
                    try:
                        checkip(ip)
                    except IpAddressError:
                        log.debug(
                            "Invalid IP Address {} encountered and skipped".
                            format(ip))

                        continue

                    ips.append('{}/{}'.format(ip, self.maskToBits(mask)))

            int_om = self.objectMap()
            int_om.id = self.prepId(
                standardizeInstance(inter.Index + "-" + interconf.Description))

            int_om.title = interconf.Description
            int_om.setIpAddresses = ips
            int_om.interfaceName = inter.Description
            if getattr(inter, 'NetConnectionID') is not None:
                int_om.description = inter.NetConnectionID
            else:
                int_om.description = interconf.Description
            int_om.macaddress = inter.MACAddress

            if getattr(interconf, 'MTU', 0) is not None:
                int_om.mtu = interconf.MTU
            else:
                int_om.mtu = 0

            if getattr(inter, 'Speed', 0) is not None:
                int_om.speed = int(inter.Speed)
            else:
                int_om.speed = 0
                int_om.monitor = False

            int_om.duplex = 0
            int_om.type = inter.AdapterType

            try:
                int_om.adminStatus = 0
                # ZEN-15493: workaround LPU cannot access NetEnabled property
                # Check IPEnabled property of configuration
                if inter.NetEnabled is None:
                    if inter.NetConnectionStatus in ENABLED_NC_STATUSES:
                        int_om.adminStatus = 1
                    elif inter.NetConnectionStatus is None:
                        int_om.adminStatus = int(
                            lookup_adminstatus(interconf.IPEnabled))
                else:
                    int_om.adminStatus = int(
                        lookup_adminstatus(inter.NetEnabled))
            except (AttributeError):
                # Workaround for 2003 / XP
                if inter.NetConnectionStatus in ENABLED_NC_STATUSES:
                    int_om.adminStatus = 1

            int_om.operStatus = AVAILABILITY.get(inter.Availability, 0)

            try:
                int_om.ifindex = inter.InterfaceIndex
            except (AttributeError, TypeError):
                int_om.ifindex = inter.Index

            if inter.Index in perfmonInstanceMap:
                # only physical adapters will have perfmon data
                # 2003 does not have the PhysicalAdapter property
                if getattr(inter, 'PhysicalAdapter', 'true').lower() == 'true' or\
                        (hasattr(counter_instances, 'stdout') and
                            [x for x in counter_instances.stdout if perfmonInstanceMap[inter.Index].lower() in x]):
                    if pnpentities and isinstance(pnpentities, dict):
                        entry = pnpentities.get(inter.Index, [])
                        if entry:
                            int_om.instance_name = standardizeInstance(
                                entry[0].Name)
                    int_om.perfmonInstance = perfmonInstanceMap[inter.Index]
            else:
                log.warning(
                    "Adapter '%s':%d does not have a perfmon "
                    "instance name and will not be monitored for "
                    "performance data", inter.Description, inter.Index)

            # These virtual adapters should not be monitored as they are
            # like loopback, and are NOT available via perfmon
            if 'Microsoft Failover Cluster Virtual Adapter' in int_om.description:
                int_om.monitor = False

            # These physical interfaces should not be monitored as they are
            # in a Team configuration and will be monitored at the Team interface

            if getattr(inter, 'TeamName', None) is not None:
                if 'TEAM' in inter.TeamName:
                    # Intel interface that is member of TEAM interface
                    int_om.teamname = inter.TeamName.split('-')[0].strip()
                    int_om.monitor = False
                else:
                    if hasattr(inter, 'GUID') and (inter.GUID in bdcDict):
                        # Broadcom interface that is member of TEAM interface
                        int_om.teamname = inter.TeamName
                        int_om.monitor = False

            # These interfaces are virtual TEAM interfaces
            if getattr(inter, 'TeamMode', None) is not None:
                if inter.TeamMode == '0':
                    if counters and counters.get(inter.netinterfaceid):
                        pass
                    else:
                        int_om.perfmonInstance = "\\network interface({0})".format(
                            "isatap." + inter.netinterfaceid)
                    log.debug('The TeamNic ID {0}'.format(int_om.id))
                    if not inter.TeamName:
                        # Get the team name from the Description of the interface
                        # This will be for Intel Team interfaces
                        int_om.teamname = interconf.Description.strip()
                    else:
                        # The Broadcom TeamName can be set early in the process
                        int_om.teamname = inter.TeamName
                    int_om.modname = 'ZenPacks.zenoss.Microsoft.Windows.TeamInterface'
                    mapTeamInter.append(int_om)
                    continue
            mapInter.append(int_om)

        # Set supporting interfaces on TEAM nics
        for teamNic in mapTeamInter:
            members = []
            for nic in mapInter:
                if getattr(nic, 'teamname', None) is not None:
                    if nic.teamname == teamNic.teamname:
                        # This nic is a member of this team interface
                        members.append(nic.id)

            teamNic.setInterfaces = members

        rm = self.relMap()
        rm.maps.extend(mapInter + mapTeamInter)

        # Filter interfaces using filtering zProperties.
        rm.maps = list(filter_maps(rm.maps, device, log))

        return rm
示例#12
0
    def process(self, device, results, log):
        log.info(
            "Modeler %s processing data for device %s",
            self.name(), device.id)

        netInt = results.get('Win32_NetworkAdapter', ())
        netConf = results.get('Win32_NetworkAdapterConfiguration', ())

        regresults = results.get('registry')
        if regresults:
            regresults = ''.join(regresults.stdout).split('|')

        broadcomresults = results.get('broadcomnic')
        if broadcomresults:
            broadcomresults = ''.join(broadcomresults.stdout).split('|')

        # Interface Map
        mapInter = []

        # Virtual Team Interface Map
        mapTeamInter = []

        # Registry Interface formatting
        regInterface = {}
        if regresults:
            for intFace in regresults:
                interfaceDict = {}
                try:
                    for keyvalues in intFace.split(';'):
                        key, value = keyvalues.split('=')
                        interfaceDict[key] = value
                    regInterface[int(interfaceDict['id'])] = interfaceDict
                except (KeyError, ValueError):
                    pass

        # Broadcom member nic map
        bdcDict = {}
        if broadcomresults:
            for memberNic in broadcomresults:
                memberDict = {}
                try:
                    for keyvalues in memberNic.split(';'):
                        key, value = keyvalues.split('=')
                        memberDict[key] = value
                    bdcDict[memberDict['id']] = memberDict['teamname']
                except (KeyError, ValueError):
                    pass
        perfmonInstanceMap = self.buildPerfmonInstances(netConf, log)

        for inter in netInt:
            #Get the Network Configuration data for this interface

            # Merge broadcom NIC Team information into object
            try:
                inter.TeamName = bdcDict[inter.GUID]
            except (KeyError, AttributeError):
                pass

            # Merge registry data for Team Interface into object
            try:
                interfaceRegistry = regInterface[int(inter.DeviceID)]
                if not interfaceRegistry['teamname']:
                    if not interfaceRegistry['altteamname']:
                        inter.TeamName = inter.NetConnectionID
                    else:
                        inter.TeamMode = '0'
                        inter.TeamName = interfaceRegistry['altteamname']
                    inter.netinterfaceid = interfaceRegistry['netinterfaceid']
                else:
                    inter.TeamName = interfaceRegistry['teamname']
                    inter.TeamMode = interfaceRegistry['teammode']

                inter.Provider = interfaceRegistry['provider']
                inter.InterfaceID = interfaceRegistry['netinterfaceid']
                inter.TeamMAC = interfaceRegistry['networkaddress']

            except (KeyError):
                pass
            for intconf in netConf:
                if intconf.InterfaceIndex == inter.InterfaceIndex:
                    interconf = intconf
                    break
            else:
                log.warn(
                    "No configuration found for %s on %s",
                    inter.Description, device.id)

                continue

            if interconf.MACAddress is None:
                continue

            if getattr(interconf, 'ServiceName', None) is not None:
                if 'netft' in interconf.ServiceName.lower():
                    # This is a Network Fault-Tolerant interface
                    # This should not be modeled as a local interface
                    continue

            ips = []

            if getattr(interconf, 'IPAddress', None) is not None:
                iplist = []
                masklist = []

                if isinstance(interconf.IPAddress, basestring):
                    iplist.append(interconf.IPAddress)
                else:
                    iplist = interconf.IPAddress

                if isinstance(interconf.IPSubnet, basestring):
                    masklist.append(interconf.IPSubnet)
                else:
                    masklist = interconf.IPSubnet

                for ip, mask in itertools.izip(iplist, masklist):
                    try:
                        checkip(ip)
                    except IpAddressError:
                        log.debug(
                            "Invalid IP Address {} encountered and skipped"
                            .format(ip))

                        continue

                    ips.append('{}/{}'.format(ip, self.maskToBits(mask)))

            int_om = self.objectMap()
            int_om.id = self.prepId(
                standardizeInstance(
                    inter.Index + "-" + interconf.Description))

            int_om.title = interconf.Description
            int_om.setIpAddresses = ips
            int_om.interfaceName = inter.Description
            if getattr(inter, 'NetConnectionID') is not None:
                int_om.description = inter.NetConnectionID
            else:
                int_om.description = interconf.Description
            int_om.macaddress = inter.MACAddress

            if getattr(interconf, 'MTU', 0) is not None:
                int_om.mtu = interconf.MTU
            else:
                int_om.mtu = 0

            if getattr(inter, 'Speed', 0) is not None:
                int_om.speed = inter.Speed
            else:
                int_om.speed = 0

            int_om.duplex = 0
            int_om.type = inter.AdapterType

            try:
                int_om.adminStatus = int(lookup_operstatus(inter.NetEnabled))
            except (AttributeError):
                int_om.adminStatus = 0

            int_om.operStatus = int(lookup_operstatus(interconf.IPEnabled))

            try:
                int_om.ifindex = inter.InterfaceIndex
            except (AttributeError, TypeError):
                int_om.ifindex = inter.Index

            if inter.Index in perfmonInstanceMap:
                int_om.perfmonInstance = perfmonInstanceMap[inter.Index]
            else:
                log.warning("Adapter '%s':%d does not have a perfmon "
                            "instance name and will not be monitored for "
                            "performance data", inter.Description,
                            inter.Index)

            # These virtual adapters should not be monitored as they are
            # like loopback, and are NOT available via perfmon
            if 'Microsoft Failover Cluster Virtual Adapter' in int_om.description:
                int_om.monitor = False

            # These physical interfaces should not be monitored as they are
            # in a Team configuration and will be monitored at the Team interface

            if getattr(inter, 'TeamName', None) is not None:
                if 'TEAM' in inter.TeamName:
                    # Intel interface that is member of TEAM interface
                    int_om.teamname = inter.TeamName.split('-')[0].strip()
                    int_om.monitor = False
                else:
                    if inter.GUID in bdcDict:
                        # Broadcom interface that is member of TEAM interface
                        int_om.teamname = inter.TeamName
                        int_om.monitor = False

            # These interfaces are virtual TEAM interfaces
            if getattr(inter, 'TeamMode', None) is not None:
                if inter.TeamMode == '0':
                    log.debug('The TeamNic ID {0}'.format(int_om.id))
                    if not inter.TeamName:
                        # Get the team name from the Description of the interface
                        # This will be for Intel Team interfaces
                        int_om.teamname = interconf.Description.strip()
                    else:
                        # The Broadcom TeamName can be set early in the process
                        int_om.teamname = inter.TeamName
                        int_om.perfmonInstance = "\\network interface({0})".format(
                            "isatap." + inter.netinterfaceid)
                    int_om.modname = 'ZenPacks.zenoss.Microsoft.Windows.TeamInterface'
                    mapTeamInter.append(int_om)
                    continue

            mapInter.append(int_om)

        # Set supporting interfaces on TEAM nics
        for teamNic in mapTeamInter:
            members = []
            for nic in mapInter:
                if getattr(nic, 'teamname', None) is not None:
                    if nic.teamname == teamNic.teamname:
                        # This nic is a member of this team interface
                        members.append(nic.id)

            teamNic.setInterfaces = members

        rm = self.relMap()
        rm.maps.extend(mapInter + mapTeamInter)

        # Filter interfaces using filtering zProperties.
        rm.maps = list(filter_maps(rm.maps, device, log))

        return rm