Example #1
0
    def getIpAddresses(self, limit=0, start=0, sort='ipAddressAsInt', dir='DESC',
              params=None, uid=None, criteria=()):
        infos = []
        cat = ICatalogTool(self._getObject(uid))
        reverse = dir=='DESC'

        brains = cat.search("Products.ZenModel.IpAddress.IpAddress",
                            start=start, limit=limit,
                            orderby=sort, reverse=reverse)

        for brain in brains:
            infos.append(IInfo(unbrain(brain)))

        devuuids = set(info.device.uuid for info in infos if info.device)

        # get ping severities
        zep = getFacade('zep')
        pingSeverities = zep.getEventSeverities(devuuids,
                                                      severities=(),
                                                      status=(),
                                                      eventClass=Status_Ping)
        self._assignPingStatuses(infos, pingSeverities)

        # get snmp severities
        snmpSeverities = zep.getEventSeverities(devuuids,
                                                      severities=(),
                                                      status=(),
                                                      eventClass=Status_Snmp)
        self._assignSnmpStatuses(infos, snmpSeverities)

        return SearchResults(infos, brains.total, brains.hash_)
Example #2
0
    def remove(self, app, leaveObjects=False):
        if not leaveObjects:
            log.info('Removing Hadoop components')
            cat = ICatalogTool(app.zport.dmd)
            for brain in cat.search(types=NEW_COMPONENT_TYPES):
                component = brain.getObject()
                component.getPrimaryParent()._delObject(component.id)

            # Remove our Device relations additions.
            Device._relations = tuple(
                [x for x in Device._relations
                    if x[0] not in NEW_DEVICE_RELATIONS])
            # Remove zHBaseMasterPort if HBase ZenPack is not installed
            try:
                self.dmd.ZenPackManager.packs._getOb(
                    'ZenPacks.zenoss.HBase'
                )
            except AttributeError:
                if self.dmd.Devices.hasProperty('zHBaseMasterPort'):
                    self.dmd.Devices.deleteZenProperty('zHBaseMasterPort')
                    log.debug('Removing zHBaseMasterPort property')

            log.info('Removing Hadoop device relationships')
            self._buildDeviceRelations()

        super(ZenPack, self).remove(app, leaveObjects=leaveObjects)
Example #3
0
    def getIpAddresses(self, limit=0, start=0, sort='ipAddressAsInt', dir='DESC',
              params=None, uid=None, criteria=()):
        infos = []
        cat = ICatalogTool(self._getObject(uid))
        reverse = dir=='DESC'

        brains = cat.search("Products.ZenModel.IpAddress.IpAddress",
                            start=start, limit=limit,
                            orderby=sort, reverse=reverse)

        for brain in brains:
            infos.append(IInfo(unbrain(brain)))

        devuuids = set(info.device.uuid for info in infos if info.device)

        # get ping severities
        zep = getFacade('zep')
        pingSeverities = zep.getEventSeverities(devuuids,
                                                      severities=(),
                                                      status=(),
                                                      eventClass=Status_Ping)
        self._assignPingStatuses(infos, pingSeverities)

        # get snmp severities
        snmpSeverities = zep.getEventSeverities(devuuids,
                                                      severities=(),
                                                      status=(),
                                                      eventClass=Status_Snmp)
        self._assignSnmpStatuses(infos, snmpSeverities)

        return SearchResults(infos, brains.total, brains.hash_)
Example #4
0
 def test(self, dmd):
     from Products.Zuul.interfaces import ICatalogTool
     results = ICatalogTool(dmd.Devices).search(
         'Products.ZenModel.DeviceOrganizer.DeviceOrganizer')
     instances = ICatalogTool(
         dmd.Devices).search('Products.ZenModel.Device.Device')
     tree = PathIndexCache(results, instances, 'devices')
Example #5
0
 def getSubComponents(self, dmd):
     i = 0
     catalog = ICatalogTool(dmd.Devices)
     COMPONENT = 'Products.ZenModel.DeviceComponent.DeviceComponent'
     query = Eq('monitored', '1')
     for brain in catalog.search(COMPONENT, query=query):
         i += 1
         obj = None
         try:
             obj = brain.getObject()
         except KeyError:
             continue
         dev = obj.device()
         status = obj.getStatus()
         row = (dict(
                 getParentDeviceTitle=obj.getParentDeviceTitle(),
                 hostname=obj.getParentDeviceTitle(),
                 name=obj.name(),
                 meta_type=obj.meta_type,
                 getInstDescription=obj.getInstDescription(),
                 getStatusString=obj.convertStatus(status),
                 getDeviceLink=obj.getDeviceLink(),
                 getPrimaryUrlPath=obj.getPrimaryUrlPath(),
                 cssclass=obj.getStatusCssClass(status),
                 status=status
                 ))
         obj._p_invalidate()
         dev._p_invalidate()
         if i % 100 == 0:
             transaction.abort()
         yield Utils.Record(**row)
Example #6
0
    def hidden(self):
        """
        Make sure we don't show the root node of a tree
        if we don't have permission on it or any of its children
        """
        # always show the root Device organizer so restricted users can see
        # all of the devices they have access to
        if self.uid == '/zport/dmd/Devices':
            return False

        # make sure we are looking at a root node
        pieces = self.uid.split('/')
        if len(pieces) != 4:
            return False

        # check for our permission
        manager = getSecurityManager()
        obj = self._object.unrestrictedTraverse(self.uid)
        if manager.checkPermission("View", obj):
            return False

        # search the catalog to see if we have permission with any of the children
        cat = ICatalogTool(obj)
        numInstances = cat.count('Products.ZenModel.DeviceOrganizer.DeviceOrganizer', self.uid)


        # if anything is returned we have view permissions on a child
        return not numInstances > 0
Example #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 = 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
Example #8
0
 def getSubComponents(self, dmd):
     i = 0
     catalog = ICatalogTool(dmd.Devices)
     COMPONENT = 'Products.ZenModel.DeviceComponent.DeviceComponent'
     query = Eq('monitored', '1')
     for brain in catalog.search(COMPONENT, query=query):
         i += 1
         obj = None
         try:
             obj = brain.getObject()
         except KeyError:
             continue
         dev = obj.device()
         status = obj.getStatus()
         row = (dict(getParentDeviceTitle=obj.getParentDeviceTitle(),
                     hostname=obj.getParentDeviceTitle(),
                     name=obj.name(),
                     meta_type=obj.meta_type,
                     getInstDescription=obj.getInstDescription(),
                     getStatusString=obj.convertStatus(status),
                     getDeviceLink=obj.getDeviceLink(),
                     getPrimaryUrlPath=obj.getPrimaryUrlPath(),
                     cssclass=obj.getStatusCssClass(status),
                     status=status))
         obj._p_invalidate()
         dev._p_invalidate()
         if i % 100 == 0:
             transaction.abort()
         yield Utils.Record(**row)
    def remove(self, app, leaveObjects=False):
        if not leaveObjects:

            from Products.ZenModel.DeviceHW import DeviceHW

            NEW_COMPONENT_TYPES = tuple([x for x in productNames])

            log.info('Removing ZenPacks.community.CiscoEnvmonE components')
            cat = ICatalogTool(app.zport.dmd)

            # Search the catalog for components of this zenpacks type.
            if NEW_COMPONENT_TYPES:
                for brain in cat.search(types=NEW_COMPONENT_TYPES):
                    component = brain.getObject()
                    component.getPrimaryParent()._delObject(component.id)

            hw_relations = ("ciscoenvvoltagesensors", "ciscoenvtempsensors"
                            "ciscoenvfans"
                            "ciscoenvpowersupplies")

            # remote HW component relations
            DeviceHW._relations = tuple(
                [x for x in DeviceHW._relations if x[0] not in hw_relations])

            log.info('Removing ZenPacks.community.CiscoEnvMonE'
                     'relationships from existing devices')

            self._buildHWRelations()

        super(ZenPack, self).remove(app, leaveObjects=leaveObjects)
Example #10
0
    def hidden(self):
        """
        Make sure we don't show the root node of a tree
        if we don't have permission on it or any of its children
        """
        # always show the root Device organizer so restricted users can see
        # all of the devices they have access to
        if self.uid == '/zport/dmd/Devices':
            return False

        # make sure we are looking at a root node
        pieces = self.uid.split('/')
        if len(pieces) != 4:
            return False

        # check for our permission
        manager = getSecurityManager()
        obj = self._object.unrestrictedTraverse(self.uid)
        if manager.checkPermission("View", obj):
            return False

        # search the catalog to see if we have permission with any of the children
        cat = ICatalogTool(obj)
        numInstances = cat.count(
            'Products.ZenModel.DeviceOrganizer.DeviceOrganizer', self.uid)

        # if anything is returned we have view permissions on a child
        return not numInstances > 0
Example #11
0
    def _processSearch(self,
                       limit=None,
                       start=None,
                       sort='name',
                       dir='ASC',
                       params=None,
                       uid=None,
                       criteria=()):
        ob = self._getObject(uid) if isinstance(uid, basestring) else uid
        cat = ICatalogTool(ob)

        reverse = dir == 'DESC'
        qs = []
        query = None
        if params:
            if 'name' in params:
                qs.append(MatchRegexp('name', '(?i).*%s.*' % params['name']))
        if qs:
            query = And(*qs)

        return cat.search("Products.ZenModel.OSProcessClass.OSProcessClass",
                          start=start,
                          limit=limit,
                          orderby=sort,
                          reverse=reverse,
                          query=query)
Example #12
0
    def getAddTemplateTargets(self, query=None):
        """
        @returns list of targets for our new template
        """
        cat = ICatalogTool(self._dmd)
        results = []
        # it can be any device class that we add the template too
        brains = cat.search(types=[DeviceClass])
        for brain in brains:
            # HACK: use the path to get the organizer name so we don't have to wake up the object
            label = brain.getPath()
            if label == "/zport/dmd/Devices":
                label = "/"
            else:
                label = label.replace("/zport/dmd/Devices/", "/")

            results.append(dict(uid=brain.getPath(), label=label))
        # the display is organizer name and we do not index it
        # so filter after the query
        if query is not None:
            results = [
                result for result in results
                if query.lower() in result['label'].lower()
            ]
        return sorted(results, key=lambda org: org['label'])
    def remove(self, app, leaveObjects=False):
        if not leaveObjects:
            self.remove_plugin_symlinks()

            log.info(
                'Removing ZenPacks.zenoss.OrderedComponentLists components')
            cat = ICatalogTool(app.zport.dmd)

            # Search the catalog for components of this zenpacks type.
            if NEW_COMPONENT_TYPES:
                for brain in cat.search(types=NEW_COMPONENT_TYPES):
                    component = brain.getObject()
                    component.getPrimaryParent()._delObject(component.id)

            # Remove our Device relations additions.
            Device._relations = tuple(
                [x for x in Device._relations \
                    if x[0] not in NEW_DEVICE_RELATIONS])

            log.info(
                'Removing ZenPacks.zenoss.OrderedComponentLists relationships from existing devices'
            )
            self._buildDeviceRelations()

        super(ZenPack, self).remove(app, leaveObjects=leaveObjects)
Example #14
0
    def _serviceSearch(self,
                       limit=None,
                       start=None,
                       sort='name',
                       dir='ASC',
                       params=None,
                       uid=None,
                       criteria=()):
        cat = ICatalogTool(self._getObject(uid))
        reverse = dir == 'DESC'

        qs = []
        query = None
        if params:
            if 'name' in params:
                qs.append(MatchRegexp('name', '(?i).*%s.*' % params['name']))
            if 'port' in params:
                qs.append(MatchRegexp('port', '(?i).*%s.*' % params['port']))
        if qs:
            query = And(*qs)

        return cat.search("Products.ZenModel.ServiceClass.ServiceClass",
                          start=start,
                          limit=limit,
                          orderby=sort,
                          reverse=reverse,
                          query=query)
Example #15
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 moveProcess(self, uid, targetUid):
        obj = self._getObject(uid)
        target = self._getObject(targetUid)
        brainsCollection = []

        # reindex all the devices and processes underneath this guy and the target
        for org in (obj.getPrimaryParent().getPrimaryParent(), target):
            catalog = ICatalogTool(org)
            brainsCollection.append(catalog.search(OSProcess))

        if isinstance(obj, OSProcessClass):
            source = obj.osProcessOrganizer()
            source.moveOSProcessClasses(targetUid, obj.id)
            newObj = getattr(target.osProcessClasses, obj.id)
        elif isinstance(obj, OSProcessOrganizer):
            source = aq_parent(obj)
            source.moveOrganizer(targetUid, (obj.id,))
            newObj = getattr(target, obj.id)
        else:
            raise Exception('Illegal type %s' % obj.__class__.__name__)

        # fire the object moved event for the process instances (will update catalog)
        for brains in brainsCollection:
            objs = imap(unbrain, brains)
            for item in objs:
                notify(ObjectMovedEvent(item, item.os(), item.id, item.os(), item.id))


        return newObj.getPrimaryPath()
Example #17
0
 def __init__(self, dmd, event_summary):
     self._dmd = dmd
     self._event_summary = event_summary
     self._eventOccurrence = event_summary['occurrence'][0]
     self._eventActor = self._eventOccurrence['actor']
     self._eventDetails = self._findDetails(self._eventOccurrence)
     self._catalog = ICatalogTool(dmd)
     self._manager = IGUIDManager(dmd)
 def removeSoftwareAndOperatingSystems(self, dmd):
     """
     Find everything that is an OperationSystem Or
     Software and unindex it
     """
     cat = ICatalogTool(dmd)
     brains = cat.search(types=(OperatingSystem, Software))
     for brain in brains:
         dmd.global_catalog.uncatalog_object(brain.getPath())
def interfaces_by_type(device, type_):
    """Yield Interface objects matching the given type."""
    catalog = ICatalogTool(device.primaryAq())

    search_results = catalog.search(
        types=('ZenPacks.Rackspace.BTI7200.%s.%s' % (type_, type_)))

    for result in search_results.results:
        yield result.getObject()
 def removeSoftwareAndOperatingSystems(self, dmd):
     """
     Find everything that is an OperationSystem Or
     Software and unindex it
     """
     cat = ICatalogTool(dmd)
     brains = cat.search(types=(OperatingSystem,Software))
     for brain in brains:
         dmd.global_catalog.uncatalog_object(brain.getPath())
Example #21
0
 def _buildCache(self, orgtype=None, instancetype=None, relname=None, treePrefix=None, orderby=None):
     if orgtype and not getattr(self._root, "_cache", None):
         cat = ICatalogTool(self._object.unrestrictedTraverse(self.uid))
         results = cat.search(orgtype, orderby=orderby)
         if instancetype:
             instanceresults = cat.search(instancetype, orderby=None)
             self._root._cache = PathIndexCache(results, instanceresults, relname, treePrefix)
         else:
             self._root._cache = PathIndexCache(results)
     return self._root._cache
Example #22
0
    def getInstances(self, uid=None, start=0, limit=50, sort='name',
                     dir='ASC', params=None):
        # do the catalog search
        cat = ICatalogTool(self._getObject(uid))
        reverse = bool(dir == 'DESC')
        brains = cat.search(self._instanceClass, start=start, limit=limit,
                            orderby=sort, reverse=reverse)
        objs = imap(unbrain, brains)

        # convert to info objects
        return SearchResults(imap(IInfo, objs), brains.total, brains.hash_)
Example #23
0
    def getInstances(self, uid=None, start=0, limit=50, sort='name',
                     dir='ASC', params=None):
        # do the catalog search
        cat = ICatalogTool(self._getObject(uid))
        reverse = bool(dir == 'DESC')
        brains = cat.search(self._instanceClass, start=start, limit=limit,
                            orderby=sort, reverse=reverse)
        objs = imap(unbrain, brains)

        # convert to info objects
        return SearchResults(imap(IInfo, objs), brains.total, brains.hash_)
Example #24
0
 def getSubComponents(self):
     cat = ICatalogTool(self)
     query = And(Not(Eq('objectImplements', 'Products.ZenModel.ComponentGroup.ComponentGroup')),
                 Not(Eq('objectImplements', 'Products.ZenModel.Device.Device')))
     brains = cat.search(query=query)
     children = []
     for brain in brains:
         try:
             children.append(brain.getObject())
         except:
             pass
     return children
 def remote_createAllUsers(self):
     cat = ICatalogTool(self.dmd)
     brains = cat.search(("Products.ZenModel.Device.Device", "Products.ZenModel.DeviceClass.DeviceClass"))
     users = []
     for brain in brains:
         device = brain.getObject()
         user = self._create_user(device)
         if user is not None:
             users.append(user)
     fmt = 'SnmpTrapConfig.remote_createAllUsers {0} users'
     log.debug(fmt.format(len(users)))
     return users
def interfaces_by_names(device, interface_names, type_='Interface'):
    """Yield Interface objects matching the given names."""
    catalog = ICatalogTool(device.primaryAq())

    name_equals = (Eq('name', x) for x in interface_names)

    search_results = catalog.search(
        types=('ZenPacks.Rackspace.BTI7200.%s.%s' % (type_, type_,)),
        query=Or(*name_equals))

    for result in search_results.results:
        yield result.getObject()
    def initialize(self, context):
        LOG.debug("initializing invalidation checksums")
        catalog = ICatalogTool(context.dmd.Devices.primaryAq())
        self.checksums = {}
        for b in catalog.search(CHECKSUMMERS.keys()):
            try:
                self.checksums[b.getPath()] = checksum(b.getObject())
            except Exception:
                # Catalog or database inconsistencies must not prevent
                # zenhub from starting.
                pass

        LOG.debug("initialized %d invalidation checksums", len(self.checksums))
Example #28
0
 def remote_createAllUsers(self):
     cat = ICatalogTool(self.dmd)
     brains = cat.search(("Products.ZenModel.Device.Device",
                          "Products.ZenModel.DeviceClass.DeviceClass"))
     users = []
     for brain in brains:
         device = brain.getObject()
         user = self._create_user(device)
         if user is not None:
             users.append(user)
     fmt = 'SnmpTrapConfig.remote_createAllUsers {0} users'
     log.debug(fmt.format(len(users)))
     return users
Example #29
0
 def __init__(self, ob, root=None, parent=None):
     self._root = root or self
     if getattr(self._root, '_ob_cache', None) is None:
         self._root._ob_cache = {}
     if not ICatalogBrain.providedBy(ob):
         brain = ICatalogTool(ob).getBrain(ob)
         if brain is None:
             raise UncataloguedObjectException(ob)
         # We already have the object - cache it here so _get_object doesn't
         # have to look it up again.
         self._root._ob_cache[brain.getPath()] = ob
         ob = brain
     self._object = ob
     self._parent = parent or None
     self._severity = None
def keyword_search(root, keywords):
    """Generate objects that match one or more of given keywords."""
    if isinstance(keywords, basestring):
        keywords = [keywords]
    elif isinstance(keywords, set):
        keywords = list(keywords)

    if keywords:
        catalog = ICatalogTool(root)
        query = In('searchKeywords', keywords)
        for result in catalog.search(query=query):
            try:
                yield result.getObject()
            except Exception:
                pass
 def getSubComponents(self):
     cat = ICatalogTool(self)
     query = And(
         Not(
             Eq('objectImplements',
                'Products.ZenModel.ComponentGroup.ComponentGroup')),
         Not(Eq('objectImplements', 'Products.ZenModel.Device.Device')))
     brains = cat.search(query=query)
     children = []
     for brain in brains:
         try:
             children.append(brain.getObject())
         except:
             pass
     return children
    def remove(self, app, leaveObjects=False):
        if not leaveObjects:
            log.info("Removing MySqlMonitor components")
            cat = ICatalogTool(app.zport.dmd)
            for brain in cat.search(types=NEW_COMPONENT_TYPES):
                component = brain.getObject()
                component.getPrimaryParent()._delObject(component.id)

            # Remove our Device relations additions.
            Device._relations = tuple([x for x in Device._relations if x[0] not in NEW_DEVICE_RELATIONS])

            log.info("Removing MySqlMonitor device relationships")
            self._buildDeviceRelations()

        super(ZenPack, self).remove(app, leaveObjects=leaveObjects)
 def cleanDevicePath(self, dmd):
     """
     Make sure only groups systems and locations and device classes
     are the only thing indexed by the path
     """
     cat = ICatalogTool(dmd)
     brains = cat.search(types=(Device,))
     idx = dmd.global_catalog._catalog.indexes['path']
     for brain in brains:
         badPaths = []
         for path in idx._unindex[brain.getRID()]:
             if not self.keepDevicePath(path):
                 badPaths.append(path)
         if badPaths:
             dmd.global_catalog.unindex_object_from_paths(DummyDevice(brain), badPaths)
 def cleanDevicePath(self, dmd):
     """
     Make sure only groups systems and locations and device classes
     are the only thing indexed by the path
     """
     cat = ICatalogTool(dmd)
     brains = cat.search(types=(Device, ))
     idx = dmd.global_catalog._catalog.indexes['path']
     for brain in brains:
         badPaths = []
         for path in idx._unindex[brain.getRID()]:
             if not self.keepDevicePath(path):
                 badPaths.append(path)
         if badPaths:
             dmd.global_catalog.unindex_object_from_paths(
                 DummyDevice(brain), badPaths)
    def migrate(self, pack):
        results = ICatalogTool(pack.dmd.Devices).search(Tenant)

        LOG.info("starting: %s total devices", results.total)
        progress = ProgressLogger(
            LOG,
            prefix="progress",
            total=results.total,
            interval=PROGRESS_LOG_INTERVAL)

        objects_migrated = 0

        for brain in results:
            try:
                if self.updateRelations(brain.getObject()):
                    objects_migrated += 1
            except Exception:
                LOG.exception(
                    "error updating relationships for %s",
                    brain.id)

            progress.increment()

        LOG.info(
            "finished: %s of %s devices required migration",
            objects_migrated,
            results.total)
Example #36
0
 def _buildCache(self,
                 orgtype=None,
                 instancetype=None,
                 relname=None,
                 treePrefix=None,
                 orderby=None):
     if orgtype and not getattr(self._root, '_cache', None):
         cat = ICatalogTool(self._object.unrestrictedTraverse(self.uid))
         results = cat.search(orgtype, orderby=orderby)
         if instancetype:
             instanceresults = cat.search(instancetype, orderby=None)
             self._root._cache = PathIndexCache(results, instanceresults,
                                                relname, treePrefix)
         else:
             self._root._cache = PathIndexCache(results)
     return self._root._cache
    def _search_catalog(self, obj, types=(), paths=(), query=None):
        if USE_MODEL_CATALOG:
            catalog = IModelCatalogTool(obj)
        else:
            catalog = ICatalogTool(obj)

        return catalog.search(types=types, paths=paths, query=query)
    def migrate(self, pack):
        LOG.info("Reindexing Processes")
        results = ICatalogTool(pack.getDmdRoot("Devices")).search(
            types=('ZenPacks.zenoss.Microsoft.Windows.OSProcess.OSProcess', ))

        if not results.total:
            return

        LOG.info("Found {} Processes that may require indexing".format(
            results.total))
        progress = progresslog.ProgressLogger(LOG,
                                              prefix="progress",
                                              total=results.total,
                                              interval=PROGRESS_LOG_INTERVAL)

        objects_migrated = 0

        for result in results:
            if self.migrate_result(result):
                objects_migrated += 1

            progress.increment()

        LOG.info("Finished indexing {} of {} Processes".format(
            objects_migrated, results.total))
Example #39
0
    def migrate(self, dmd):
        # Add state datasource/datapoint to subclasses
        # This will catch any device specific templates and make this migration quicker
        results = ICatalogTool(
            dmd.Devices.Server.Microsoft).search(RRDTemplate)
        if results.total == 0:
            return
        log.info('Searching for WinService templates.')
        templates = []
        for result in results:
            try:
                template = result.getObject()
            except Exception:
                continue
            if getattr(template, 'targetPythonClass',
                       '') == 'ZenPacks.zenoss.Microsoft.Windows.WinService':
                templates.append(template)

        progress = progresslog.ProgressLogger(log,
                                              prefix="WinService state",
                                              total=results.total,
                                              interval=PROGRESS_LOG_INTERVAL)

        for template in templates:
            progress.increment()
            self.add_state_ds_dp(template)
 def migrate(self, pack):
     hd_fs_brains = ICatalogTool(pack.dmd.Devices).search(HardDisk)
     for result in hd_fs_brains:
         try:
             notify(IndexingEvent(result.getObject()))
         except Exception:
             continue
    def getEdges(self):
        for impact in super(DeviceRelationsProvider, self).getEdges():
            yield impact

        # File Systems
        for obj in self._object.os.filesystems():
            yield edge(guid(obj), self.guid())

        # Processors
        for obj in self._object.hw.cpus():
            yield edge(guid(obj), self.guid())

        # Cluster Services
        for obj in self._object.os.clusterservices():
            yield edge(guid(obj), self.guid())

        for obj in self._object.os.winrmservices():
            yield edge(self.guid(), guid(obj))

        # Look up for HyperV server with same IP
        try:
            dc = self._object.getDmdRoot('Devices').getOrganizer(
                '/Server/Microsoft/HyperV')
        except Exception:
            return

        results = ICatalogTool(dc).search(
            types=('ZenPacks.zenoss.Microsoft.HyperV.HyperVVSMS.HyperVVSMS', ))

        for brain in results:
            obj = brain.getObject()
            if obj.ip == self._object.id:
                yield edge(self.guid(), guid(obj))
 def cutover(self, dmd):
     log.info(
         "Removing ignoreParameters and ignoreParametersWhenModeling from all OSProcessClass objects"
     )
     try:
         for brain in ICatalogTool(dmd).search(OSProcessClass):
             try:
                 pc = brain.getObject()
             except Exception:
                 log.warn("Failed to get %s", brain.getPath())
             else:
                 try:
                     ignore = False
                     if getattr(pc, 'ignoreParameters', False):
                         ignore = True
                         pc.ignoreParameters = False
                     if getattr(pc, 'ignoreParametersWhenModeling', False):
                         ignore = True
                         pc.ignoreParametersWhenModeling = False
                     if ignore and not getattr(pc, 'replaceRegex', False):
                         pc.replaceRegex = '.*'
                         pc.replacement = pc.name
                 except Exception:
                     log.warn("Failed to migrate %s",
                              brain.getPath(),
                              exc_info=True)
     except Exception:
         log.fail('Unable to search for OSProcessClass objects')
Example #43
0
 def cutover(self, dmd):
     items = ICatalogTool(dmd).search('Products.ZenModel.ZenMenuItem.ZenMenuItem')
     for brain in items:
         menuitem = brain.getObject()
         action = menuitem.action
         if action in ('../viewHistory', 'viewHistory', 'viewNewHistory'):
             menuitem.__primary_parent__.removeRelation(menuitem)
Example #44
0
    def deleteNode(self, uid):
        """
        Remove a report or report organizer.

        @type  uid: string
        @param uid: The UID of the node to delete
        @rtype:   [dictionary]
        @return:  B{Properties}:
           - tree: (dictionary) Object representing the new Reports tree
        """
        # make sure we are not deleting a required node
        if uid in essentialReportOrganizers:
            raise Exception('You cannot delete this organizer')

        # Getting all of the child nodes for auditing purposes
        node = self.context.dmd.unrestrictedTraverse(uid)
        brains = ICatalogTool(node).search((ReportClass,BaseReport))
        family = []
        for brain in brains:
            family.append([brain.getPath(), isinstance(brain.getObject(), ReportClass)])

        self._getFacade().deleteNode(uid)

        # Audit messaging
        for name, isOrganizer in family:
            if isOrganizer:
                audit('UI.Organizer.Delete', name)
            else:
                audit('UI.Report.Delete', name)

        contextUid = '/'.join(uid.split('/')[:-1])
        return self._getTreeUpdates(contextUid)
    def remove(self, app, leaveObjects=False):
        if not leaveObjects:
            log.info('Removing all ElementPool components')
            cat = ICatalogTool(app.zport.dmd)
            for brain in cat.search(types=NEW_COMPONENT_TYPES):
                component = brain.getObject()
                component.getPrimaryParent()._delObject(component.id)

            # Remove our relations additions.
            for relname, _, _, _, _, containingClass in NEW_DEVICE_RELATIONS:
                containingClass._relations = tuple(
                    [x for x in containingClass._relations if x[0] != relname])

            log.info('Removing ElementPool device/component relationships')
            self._buildDeviceRelations()

        super(ZenPack, self).remove(app, leaveObjects=leaveObjects)
Example #46
0
 def __init__(self, dmd, event_summary):
     self._dmd = dmd
     self._event_summary = event_summary
     self._eventOccurrence = event_summary['occurrence'][0]
     self._eventActor = self._eventOccurrence['actor']
     self._eventDetails = self._findDetails(self._eventOccurrence)
     self._catalog = ICatalogTool(dmd)
     self._manager = IGUIDManager(dmd)
    def _processSearch(self, limit=None, start=None, sort='name', dir='ASC',
              params=None, uid=None, criteria=()):
        ob = self._getObject(uid) if isinstance(uid, basestring) else uid
        cat = ICatalogTool(ob)

        reverse = dir=='DESC'
        qs = []
        query = None
        if params:
            if 'name' in params:
                qs.append(MatchRegexp('name', '(?i).*%s.*' % params['name']))
        if qs:
            query = And(*qs)

        return cat.search("Products.ZenModel.OSProcessClass.OSProcessClass",
                          start=start, limit=limit, orderby=sort,
                          reverse=reverse, query=query)
Example #48
0
    def _serviceSearch(self, limit=None, start=None, sort='name', dir='ASC',
              params=None, uid=None, criteria=()):
        cat = ICatalogTool(self._getObject(uid))
        reverse = dir=='DESC'

        qs = []
        query = None
        if params:
            if 'name' in params:
                qs.append(MatchRegexp('name', '(?i).*%s.*' % params['name']))
            if 'port' in params:
                qs.append(MatchRegexp('port', '(?i).*%s.*' % params['port']))
        if qs:
            query = And(*qs)

        return cat.search("Products.ZenModel.ServiceClass.ServiceClass",
                          start=start, limit=limit, orderby=sort,
                          reverse=reverse, query=query)
Example #49
0
 def __init__(self, ob, root=None, parent=None):
     self._root = root or self
     if getattr(self._root, '_ob_cache', None) is None:
         self._root._ob_cache = {}
     if not ICatalogBrain.providedBy(ob):
         brain = ICatalogTool(ob).getBrain(ob)
         if brain is None:
             raise UncataloguedObjectException(ob)
         # We already have the object - cache it here so _get_object doesn't
         # have to look it up again.
         self._root._ob_cache[brain.getPath()] = ob
         ob = brain
     self._object = ob
     self._parent = parent or None
     self._severity = None
     # allow showing the event severity icons to be configurable
     if not hasattr(self._root, 'showSeverityIcons'):
         self._root._showSeverityIcons = self._shouldShowSeverityIcons()
Example #50
0
 def processOrganizerUpdated(self, object, event):
     catalog = ICatalogTool(object.primaryAq())
     results = catalog.search(OSProcessClass)
     if not results.total:
         return
     devices = set()
     for organizer in results:
         if results.areBrains:
             organizer = organizer.getObject()
         for process in organizer.instances():
             device = process.device()
             if not device:
                 continue
             device = device.primaryAq()
             device_path = device.getPrimaryUrlPath()
             if not device_path in devices:
                 self._notifyAll(device)
                 devices.add(device_path)
Example #51
0
    def _findDevices(self, identifier, ipAddress, limit=None):
        """
        Returns a tuple ([device brains], [devices]) searching manage IP and
        interface IPs. limit is the maximum total number in both lists.
        """
        dev_cat = ICatalogTool(self._devices)

        try:
            ip_address = next(i for i in (ipAddress, identifier) if isip(i))
            ip_decimal = ipToDecimal(ip_address)
        except Exception:
            ip_address = None
            ip_decimal = None

        query_set = Or(Eq('id', identifier), Eq('name', identifier))
        if ip_decimal is not None:
            query_set.addSubquery(Eq('ipAddress', str(ip_decimal)))
        device_brains = list(dev_cat.search(types=Device,
                                            query=query_set,
                                            limit=limit,
                                            filterPermissions=False))

        limit = None if limit is None else limit - len(device_brains)
        if not limit:
            return device_brains, []

        if ip_decimal is not None:
            # don't search interfaces for 127.x.x.x IPv4 addresses
            if ipToDecimal('126.255.255.255') < ip_decimal < ipToDecimal('128.0.0.0'):
                ip_decimal = None
            # don't search interfaces for the ::1 IPv6 address
            elif ipToDecimal('::1') == ip_decimal:
                ip_decimal = None
        if ip_decimal is None and not device_brains:
            return [], []

        net_cat = ICatalogTool(self._networks)
        results = net_cat.search(types=IpAddress,
                                 query=(Eq('name', ip_address)),
                                 limit = limit,
                                 filterPermissions = False)
        devices = [brain.getObject().device() for brain in results]

        return device_brains, devices
Example #52
0
 def getCopyTargets(self, uid, query=''):
     catalog = ICatalogTool(self._dmd)
     template = self._getObject(uid)
     types = ['Products.ZenModel.DeviceClass.DeviceClass']
     brains = catalog.search(types=types)
     objs = imap(unbrain, brains)
     def genTargets():
         for obj in objs:
             container = obj.rrdTemplates
             organizer = '/' + '/'.join(obj.getPrimaryPath()[4:])
             label = organizer
             if template.id in container.objectIds():
                 label += " (%s)" % _t('Create Copy')
             if label.lower().startswith(query.lower()):
                 uid = '/'.join(obj.getPrimaryPath())
                 yield dict(uid=uid, label=label)
     def byLabel(left, right):
         return cmp(left['label'].lower(), right['label'].lower())
     return sorted(genTargets(), byLabel)
Example #53
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
Example #54
0
 def getSubComponents(self, meta_type="", monitored=True):
     """
     Return generator of components, by meta_type if specified
     """
     catalog = ICatalogTool(self)
     COMPONENT = 'Products.ZenModel.DeviceComponent.DeviceComponent'
     monitorq, typeq = None, None
     if monitored:
         monitorq = Eq('monitored', '1')
     if meta_type:
         typeq = Eq('meta_type', meta_type)
     queries = filter(None, (monitorq, typeq))
     if queries:
         query = And(*queries) if len(queries) > 1 else queries[0]
     else:
         query = None
     for brain in catalog.search(COMPONENT, query=query):
         try:
             yield brain.getObject()
         except KeyError:
             log.warn("bad path '%s' in global catalog", brain.getPath())
Example #55
0
    def getAddTemplateTargets(self, query=None):
        """
        @returns list of targets for our new template
        """
        cat = ICatalogTool(self._dmd)
        results = []
        # it can be any device class that we add the template too
        brains = cat.search(types=[DeviceClass])
        for brain in brains:
            # HACK: use the path to get the organizer name so we don't have to wake up the object
            label = brain.getPath()
            if label == "/zport/dmd/Devices":
                label = "/"
            else:
                label = label.replace("/zport/dmd/Devices/", "/")

            results.append(dict(uid=brain.getPath(), label=label))
        # the display is organizer name and we do not index it
        # so filter after the query
        if query is not None:
            results = [result for result in results if query.lower() in result['label'].lower()]
        return sorted(results, key=lambda org: org['label'])
    def remove(self, app, leaveObjects=False):
        if not leaveObjects:
            self.remove_plugin_symlinks()

            LOG.info('Removing ZenPacks.EE.HelloWorld components')
            cat = ICatalogTool(app.zport.dmd)

            # Search the catalog for components of this zenpacks type.
            if NEW_COMPONENT_TYPES:
                for brain in cat.search(types=NEW_COMPONENT_TYPES):
                    component = brain.getObject()
                    component.getPrimaryParent()._delObject(component.id)

            # Remove our Device relations additions.
            Device._relations = tuple(
                [x for x in Device._relations
                    if x[0] not in NEW_DEVICE_RELATIONS])

            LOG.info('Removing ZenPacks.EE.HelloWorld relationships from existing devices')
            self._buildDeviceRelations()

        super(ZenPack, self).remove(app, leaveObjects=leaveObjects)
def getOpenStackServer(self):
    device_ips = set()
    if self.manageIp:
        device_ips.add(self.manageIp)

    for iface in self.os.interfaces():
        for ip in iface.getIpAddresses():
            device_ips.add(ip.split('/')[0])

    catalog = ICatalogTool(self.dmd)
    for record in catalog.search('ZenPacks.zenoss.OpenStack.Server.Server'):
        server = record.getObject()
        server_ips = set()

        if server.publicIps:
            server_ips.update(server.publicIps)

        if server.privateIps:
            server_ips.update(server.privateIps)

        if server_ips.intersection(device_ips):
            return server