Example #1
0
 def zmanage_importObjects(self, context=None, REQUEST=None):
     """Import an XML file as the Zenoss objects and properties it
     represents.
     """
     # XXX
     # for right now, we're only using this through the web, so a REQUEST is
     # always define; when we have a use-case for imports via command line,
     # we will add that code here
     if not context:
         context = self.getPhysicalRoot()
     # get the submitted data
     filenames = REQUEST.form.get("filenames")
     urlnames = REQUEST.form.get("urlnames")
     doDelete = REQUEST.form.get("dodelete")
     xmlfiles = []
     for collection in [filenames, urlnames]:
         if collection:
             if isinstance(collection, list):
                 xmlfiles.extend(collection)
             else:
                 xmlfiles.append(collection)
     # load the objects into Zenoss
     im = ImportRM(noopts=True, app=self.getPhysicalRoot())
     for xmlfile in xmlfiles:
         im.loadObjectFromXML(context, xmlfile)
         if doDelete and xmlfile in filenames:
             os.unlink(xmlfile)
     if REQUEST:
         messaging.IMessageSender(self).sendToBrowser("Import Objects", "Objects imported")
         return self.callZenScreen(REQUEST)
Example #2
0
 def cutover(self, dmd):
     dmd.buildMenus({  
         'PerformanceMonitor_list': [
             {  'action': 'performanceTemplates',
                'description': 'Templates',
                'id': 'performanceTemplates',
                'ordering': 16.0,
                'permissions': ('View Device',),
             }],
         'StatusMonitor_list': [
             {  'action': 'performanceTemplates',
                'description': 'Templates',
                'id': 'performanceTemplates',
                'ordering': 16.0,
                'permissions': ('View Device',),
             }],
     })
     for c in dmd.Monitors.objectValues(spec='MonitorClass'):
         c.buildRelations()
     for c in dmd.Monitors.objectValues(spec='Monitor'):
         c.buildRelations()
     dmd.Monitors.buildRelations()
     if len(dmd.Monitors.rrdTemplates()) == 0:
         from Products.ZenRelations.ImportRM import ImportRM
         from Products.ZenUtils.Utils import zenPath
         template = zenPath('Products/ZenModel/migrate/monitorTemplate.xml')
         im = ImportRM(noopts=True, app=dmd.zport)
         im.loadObjectFromXML(xmlfile=template)
Example #3
0
 def zmanage_importObjects(self, context=None, REQUEST=None):
     """Import an XML file as the Zenoss objects and properties it
     represents.
     """
     # XXX
     # for right now, we're only using this through the web, so a REQUEST is
     # always define; when we have a use-case for imports via command line,
     # we will add that code here
     if not context:
         context = self.getPhysicalRoot()
     # get the submitted data
     filenames = REQUEST.form.get('filenames')
     urlnames = REQUEST.form.get('urlnames')
     doDelete = REQUEST.form.get('dodelete')
     xmlfiles = []
     for collection in [filenames, urlnames]:
         if collection:
             if isinstance(collection, list):
                 xmlfiles.extend(collection)
             else:
                 xmlfiles.append(collection)
     # load the objects into Zenoss
     im = ImportRM(noopts=True, app=self.getPhysicalRoot())
     for xmlfile in xmlfiles:
         im.loadObjectFromXML(context, xmlfile)
         if doDelete and xmlfile in filenames:
             os.unlink(xmlfile)
     if REQUEST:
         messaging.IMessageSender(self).sendToBrowser(
             'Import Objects', 'Objects imported')
         return self.callZenScreen(REQUEST)
Example #4
0
    def cutover(self, dmd):
        from Products.ZenModel.MonitorClass import manage_addMonitorClass
        if not hasattr(dmd.Monitors, 'Performance'):
            manage_addMonitorClass(dmd.Monitors, 'Performance')

        from Products.ZenModel.PerformanceConf import manage_addPerformanceConf
        if hasattr(dmd.Monitors, 'Cricket'):
            for c in dmd.Monitors.Cricket.objectValues():
                if not hasattr(dmd.Monitors.Performance, c.id):
                    manage_addPerformanceConf(dmd.Monitors.Performance, c.id)
                    p = dmd.Monitors.Performance._getOb(c.id)
                    p.renderurl = c.cricketurl
                    p.renderuser = c.cricketuser
                    p.renderpass = c.cricketpass
            if hasattr(dmd.Monitors.Cricket, 'localhost'):
                dmd.Monitors.Cricket._delObject('localhost')
            dmd.Monitors._delObject("Cricket")

        for dev in dmd.Devices.getSubDevices():
            dev.buildRelations()
            if hasattr(dev, 'cricket') and dev.cricket.getRelatedId():
                dev.setPerformanceMonitor(dev.cricket.getRelatedId())
            if hasattr(dev, '_snmpUpTime'):
                delattr(dev, '_snmpUpTime')
            for fs in dev.os.filesystems():
                if not callable(fs.totalBytes):
                    delattr(fs, 'totalBytes')
                if not callable(fs.usedBytes):
                    delattr(fs, 'usedBytes')
                if not callable(fs.availBytes):
                    delattr(fs, 'availBytes')
                if not callable(fs.availFiles):
                    delattr(fs, 'availFiles')
                if not callable(fs.capacity):
                    delattr(fs, 'capacity')
                if not callable(fs.inodeCapacity):
                    delattr(fs, 'inodeCapacity')

        for dc in dmd.Devices.getSubOrganizers():
            self.convert(dc)
        self.convert(dmd.Devices)

        if not hasattr(dmd.Devices, 'zProdStateThreshold'):
            dmd.Devices._setProperty("zProdStateThreshold", 500, type="int")

        if getattr(dmd.Devices.rrdTemplates, 'Device', None) is None:
            from Products.ZenRelations.ImportRM import ImportRM
            imp = ImportRM(noopts=True, app=dmd.getPhysicalRoot())
            imp.options.noCommit = True
            imp.options.infile = zenPath('Products', 'ZenModel', 'data',
                                         'rrdconfig.update')
            imp.loadDatabase()
    def cutover(self, dmd):
        from Products.ZenModel.MonitorClass import manage_addMonitorClass
        if not hasattr(dmd.Monitors, 'Performance'):
            manage_addMonitorClass(dmd.Monitors, 'Performance')

        from Products.ZenModel.PerformanceConf import manage_addPerformanceConf
        if hasattr(dmd.Monitors, 'Cricket'):
            for c in dmd.Monitors.Cricket.objectValues():
                if not hasattr(dmd.Monitors.Performance, c.id):
                    manage_addPerformanceConf(dmd.Monitors.Performance, c.id)
                    p = dmd.Monitors.Performance._getOb(c.id)
                    p.renderurl = c.cricketurl
                    p.renderuser = c.cricketuser
                    p.renderpass = c.cricketpass
            if hasattr(dmd.Monitors.Cricket, 'localhost'):
                dmd.Monitors.Cricket._delObject('localhost')
            dmd.Monitors._delObject("Cricket")

        for dev in dmd.Devices.getSubDevices():
            dev.buildRelations()
            if hasattr(dev, 'cricket') and dev.cricket.getRelatedId():
                dev.setPerformanceMonitor(dev.cricket.getRelatedId())
            if hasattr(dev, '_snmpUpTime'):
                delattr(dev, '_snmpUpTime')
            for fs in dev.os.filesystems():
                if not callable(fs.totalBytes):
                    delattr(fs, 'totalBytes')
                if not callable(fs.usedBytes):
                    delattr(fs, 'usedBytes')
                if not callable(fs.availBytes):
                    delattr(fs, 'availBytes')
                if not callable(fs.availFiles):
                    delattr(fs, 'availFiles')
                if not callable(fs.capacity):
                    delattr(fs, 'capacity')
                if not callable(fs.inodeCapacity):
                    delattr(fs, 'inodeCapacity')

        for dc in dmd.Devices.getSubOrganizers():
            self.convert(dc)
        self.convert(dmd.Devices)

        if not hasattr(dmd.Devices, 'zProdStateThreshold'):
            dmd.Devices._setProperty("zProdStateThreshold", 500, type="int")

        if getattr(dmd.Devices.rrdTemplates, 'Device', None) is None:
            from Products.ZenRelations.ImportRM import ImportRM
            imp = ImportRM(noopts=True, app=dmd.getPhysicalRoot())
            imp.options.noCommit = True
            imp.options.infile = zenPath(
                'Products', 'ZenModel', 'data', 'rrdconfig.update')
            imp.loadDatabase()
Example #6
0
            def endElement(self, name):
                if name == 'object':
                    obj = self.objstack[-1]
                    log.debug('Now adding %s', obj.getPrimaryUrlPath())
                    try:
                        obj.buildRelations()
                        obj.removeRelation('pack')
                        obj.addRelation('pack', pack)
                    except Exception:
                        log.exception("Error adding pack to %s",
                                      obj.getPrimaryUrlPath())

                ImportRM.endElement(self, name)
Example #7
0
            def endElement(self, name):
                if name == 'object':
                    obj = self.objstack[-1]
                    log.debug('Now adding %s', obj.getPrimaryUrlPath())
                    try:
                        obj.buildRelations()
                        obj.removeRelation('pack')
                        obj.addRelation('pack', pack)
                    except Exception:
                        log.exception("Error adding pack to %s",
                                      obj.getPrimaryUrlPath())

                ImportRM.endElement(self, name)
Example #8
0
 def doImport(self):
     from Products.ZenRelations.ImportRM import ImportRM
     im = ImportRM(noopts=True, app=self.dmd.zport)
     
     f = None
     try:
         f = open(self.options.file, 'r')
     except:
         print >> sys.stderr, 'Error reading from %s.' % self.options.file
         sys.exit(2)
     
     print "Importing objects from %s." % self.options.file
     im.loadObjectFromXML(xmlfile=f)
     from transaction import commit
     commit()
     f.close()
Example #9
0
    def loadDatabase(self):

        # This is an initial load, so we can forgo incremental commits
        self.options.chunk_size = 0

        datadir = os.path.join(os.path.dirname(__file__),"data")
        self.log.info("loading data from:%s", datadir)
        for path, dirname, filenames in os.walk(datadir):
            filenames.sort()
            for filename in filter(lambda f: f.endswith(".xml"), filenames):
                self.options.infile = os.path.join(path,filename)
                self.log.info("loading: %s", self.options.infile)
                ImportRM.loadDatabase(self)
        # Reindex ProductKeys and EventClassKeys after XML load
        self.dmd.Manufacturers.reIndex()
        self.dmd.Events.reIndex()
        transaction.commit()
Example #10
0
    def cutover(self, dmd):

        if hasattr(dmd, 'Processes'):
            if not dmd.Processes.hasProperty('zFailSeverity'):
                dmd.Processes._setProperty("zFailSeverity", 4, type="int")
            return

        from Products.ZenModel.OSProcessOrganizer \
             import manage_addOSProcessOrganizer
        manage_addOSProcessOrganizer(dmd, 'Processes')

        if getattr(dmd.Devices.rrdTemplates, 'OSProcess', None) is None:
            from Products.ZenRelations.ImportRM import ImportRM
            imp = ImportRM(noopts=True, app=dmd.getPhysicalRoot())
            imp.options.noCommit = True
            imp.options.noindex = True
            imp.options.infile = zenPath('Products', 'ZenModel', 'data',
                                         'osproc.update')
            imp.loadDatabase()
    def cutover(self, dmd):
        
        if hasattr(dmd, 'Processes'):
            if not dmd.Processes.hasProperty('zFailSeverity'):
                dmd.Processes._setProperty("zFailSeverity", 4, type="int")
            return

        from Products.ZenModel.OSProcessOrganizer \
             import manage_addOSProcessOrganizer
        manage_addOSProcessOrganizer(dmd, 'Processes')

        if getattr(dmd.Devices.rrdTemplates, 'OSProcess', None) is None:
            from Products.ZenRelations.ImportRM import ImportRM
            imp = ImportRM(noopts=True, app=dmd.getPhysicalRoot())
            imp.options.noCommit = True
            imp.options.noindex = True
            imp.options.infile = zenPath(
                'Products', 'ZenModel', 'data', 'osproc.update')
            imp.loadDatabase()