Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 3
0
    def ipAddress(self):
        """
        IP address associated with this object as 32-bit integer. For devices,
        the manageIp; for interfaces, the first ip address.

        This is a FieldIndex on the catalog.
        """
        if isinstance(self._context, IpNetwork): return
        getter = getattr(self._context, 'getIpAddress', None)
        if getter is None:
            getter = getattr(self._context, 'getManageIp', None)
        if getter is None: return
        ip = getter()
        if ip:
            ip = ip.partition('/')[0]
            return str(numbip(ip))
Ejemplo n.º 4
0
    def ipAddress(self):
        """
        IP address associated with this object as 32-bit integer. For devices,
        the manageIp; for interfaces, the first ip address.

        This is a FieldIndex on the catalog.
        """
        if isinstance(self._context, IpNetwork): return
        getter = getattr(self._context, 'getIpAddress', None)
        if getter is None:
            getter = getattr(self._context, 'getManageIp', None)
        if getter is None: return
        ip = getter()
        if ip:
            ip = ip.partition('/')[0]
            return str(numbip(ip))
Ejemplo n.º 5
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
Ejemplo n.º 6
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
Ejemplo n.º 7
0
 def ipAddressAsInt(self):
     ip = self.getIpAddress()
     if ip:
         ip = ip.partition('/')[0]
     return str(numbip(ip))
Ejemplo n.º 8
0
 def ipAddressAsInt(self):
     ip = self.getIpAddress()
     if ip:
         ip = ip.partition('/')[0]
     return str(numbip(ip))