def testEnsureIp(self): ip = '10' self.assertEqual(ensureIp(ip), '10.0.0.0') # strips the characters ip = '10a.12.aaa' self.assertEqual(ensureIp(ip), '10.12.0.0') # invalid number ip = '1212121212121' self.assertEqual(ensureIp(ip), '0.0.0.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
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
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