def collectDevice(self, device=None, setlog=True, REQUEST=None,
        generateEvents=False, background=False, write=None):
        """
        Collect the configuration of this device AKA Model Device

        @permission: ZEN_MANAGE_DEVICE
        @param device: Name of a device or entry in DMD
        @type device: string
        @param setlog: If true, set up the output log of this process
        @type setlog: boolean
        @param REQUEST: Zope REQUEST object
        @type REQUEST: Zope REQUEST object
        @param generateEvents: unused
        @type generateEvents: string
        """
        xmlrpc = isXmlRpc(REQUEST)
        zenmodelerOpts = ['run', '--now', '--monitor', self.id, '-d', device.id]
        result = self._executeZenModelerCommand(zenmodelerOpts, background,
                                                REQUEST, write)
        if result and xmlrpc:
            return result
        log.info('configuration collected')

        if xmlrpc:
            return 0
Пример #2
0
    def collectDevice(self,
                      device=None,
                      setlog=True,
                      REQUEST=None,
                      generateEvents=False,
                      background=False,
                      write=None):
        """
        Collect the configuration of this device AKA Model Device

        @permission: ZEN_MANAGE_DEVICE
        @param device: Name of a device or entry in DMD
        @type device: string
        @param setlog: If true, set up the output log of this process
        @type setlog: boolean
        @param REQUEST: Zope REQUEST object
        @type REQUEST: Zope REQUEST object
        @param generateEvents: unused
        @type generateEvents: string
        """
        xmlrpc = isXmlRpc(REQUEST)
        zenmodelerOpts = [
            'run', '--now', '--monitor', self.id, '-d', device.id
        ]
        result = self._executeZenModelerCommand(zenmodelerOpts, background,
                                                REQUEST, write)
        if result and xmlrpc:
            return result
        log.info('configuration collected')

        if xmlrpc:
            return 0
Пример #3
0
    def collectDevice(
            self, device=None, setlog=True, REQUEST=None,
            generateEvents=False, background=False, write=None,
            collectPlugins='', debug=False):
        """
        Collect the configuration of this device AKA Model Device

        @permission: ZEN_MANAGE_DEVICE
        @param device: Name of a device or entry in DMD
        @type device: string
        @param setlog: If true, set up the output log of this process
        @type setlog: boolean
        @param REQUEST: Zope REQUEST object
        @type REQUEST: Zope REQUEST object
        @param generateEvents: unused
        @type generateEvents: string
        @param collectPlugins: (optional) Modeler plugins to use.
                               Takes a regular expression (default: '')
        @type  collectPlugins: string
        """
        xmlrpc = isXmlRpc(REQUEST)
        result = self._executeZenModelerCommand(device.id, self.id, background,
                                                REQUEST, write,
                                                collectPlugins=collectPlugins, debug=debug)
        if result and xmlrpc:
            return result
        log.info('configuration collected')

        if xmlrpc:
            return 0
Пример #4
0
 def __call__(self):
     """
     Invokes the default view.
     """
     if isXmlRpc(self.REQUEST):
         return self
     else:
         newpath = INewPath(self)
         self.REQUEST.response.redirect(newpath)
Пример #5
0
 def __call__(self):
     """
     Invokes the default view.
     """
     if isXmlRpc(self.REQUEST):
         return self
     else:
         newpath = INewPath(self)
         self.REQUEST.response.redirect(newpath)
Пример #6
0
 def __call__(self):
     """
     Invokes the default view.
     """
     if isXmlRpc(self.REQUEST):
         return self
     else:
         newpath = INewPath(self)
         newpath = getUtility(IVirtualRoot).ensure_virtual_root(newpath)
         self.REQUEST.response.redirect(newpath)
Пример #7
0
 def __call__(self):
     """
     Invokes the default view.
     """
     if isXmlRpc(self.REQUEST):
         return self
     else:
         newpath = INewPath(self)
         newpath = getUtility(IVirtualRoot).ensure_virtual_root(newpath)
         self.REQUEST.response.redirect(newpath)
Пример #8
0
    def runDeviceMonitor(
            self, device=None, REQUEST=None, write=None,
            collection_daemons=None, debug=False):
        """
        Run collection daemons against specific device
        """
        xmlrpc = isXmlRpc(REQUEST)
        result = self._executeMonitoringCommands(device.id, self.id, write,
                                                 REQUEST, collection_daemons,
                                                 debug)
        if result and xmlrpc:
            return result
        log.info('configuration collected')

        if xmlrpc:
            return 0
Пример #9
0
    def discoverDevices(self, organizerPaths=None, REQUEST=None):
        """
        Load a device into the database connecting its major relations
        and collecting its configuration.
        """
        xmlrpc = isXmlRpc(REQUEST)

        if not organizerPaths:
            if xmlrpc: return 1
            return self.callZenScreen(REQUEST)

        zDiscCommand = "empty"

        from Products.ZenUtils.ZenTales import talesEval

        orgroot = self.getNetworkRoot()
        for organizerName in organizerPaths:
            organizer = orgroot.getOrganizer(organizerName)
            if organizer is None:
                if xmlrpc: return 1  # XML-RPC error
                log.error("Couldn't obtain a network entry for '%s' "
                          "-- does it exist?" % organizerName)
                continue

            zDiscCommand = getattr(organizer, "zZenDiscCommand", None)
            if zDiscCommand:
                cmd = talesEval('string:' + zDiscCommand, organizer).split(" ")
            else:
                cmd = ["zendisc", "run", "--net", organizer.getNetworkName()]
                if getattr(organizer, "zSnmpStrictDiscovery", False):
                    cmd += ["--snmp-strict-discovery"]
                if getattr(organizer, "zPreferSnmpNaming", False):
                    cmd += ["--prefer-snmp-naming"]
            zd = binPath('zendisc')
            zendiscCmd = [zd] + cmd[1:]
            status = self.dmd.JobManager.addJob(
                SubprocessJob,
                description="Discover devices in network %s" %
                organizer.getNetworkName(),
                args=(zendiscCmd, ))

        log.info('Done')

        if REQUEST and not xmlrpc:
            REQUEST.RESPONSE.redirect('/zport/dmd/JobManager/joblist')

        if xmlrpc: return 0
Пример #10
0
    def discoverDevices(self, organizerPaths=None, REQUEST = None):
        """
        Load a device into the database connecting its major relations
        and collecting its configuration.
        """
        xmlrpc = isXmlRpc(REQUEST)

        if not organizerPaths:
            if xmlrpc: return 1
            return self.callZenScreen(REQUEST)

        zDiscCommand = "empty"

        from Products.ZenUtils.ZenTales import talesEval

        orgroot = self.getNetworkRoot()
        for organizerName in organizerPaths:
            organizer = orgroot.getOrganizer(organizerName)
            if organizer is None:
                if xmlrpc: return 1 # XML-RPC error
                log.error("Couldn't obtain a network entry for '%s' "
                            "-- does it exist?" % organizerName)
                continue

            zDiscCommand = getattr(organizer, "zZenDiscCommand", None)
            if zDiscCommand:
                cmd = talesEval('string:' + zDiscCommand, organizer).split(" ")
            else:
                cmd = ["zendisc", "run", "--net", organizer.getNetworkName()]
                if getattr(organizer, "zSnmpStrictDiscovery", False):
                    cmd += ["--snmp-strict-discovery"]
                if getattr(organizer, "zPreferSnmpNaming", False):
                    cmd += ["--prefer-snmp-naming"]
            zd = binPath('zendisc')
            zendiscCmd = [zd] + cmd[1:]
            status = self.dmd.JobManager.addJob(SubprocessJob,
                description="Discover devices in network %s" % organizer.getNetworkName(),
                args=(zendiscCmd,))

        log.info('Done')

        if REQUEST and not xmlrpc:
            REQUEST.RESPONSE.redirect('/zport/dmd/JobManager/joblist')

        if xmlrpc: return 0
Пример #11
0
    def runDeviceMonitor(self,
                         device=None,
                         REQUEST=None,
                         write=None,
                         collection_daemons=None,
                         debug=False):
        """
        Run collection daemons against specific device
        """
        xmlrpc = isXmlRpc(REQUEST)
        result = self._executeMonitoringCommands(device.id, self.id, write,
                                                 REQUEST, collection_daemons,
                                                 debug)
        if result and xmlrpc:
            return result
        log.info('configuration collected')

        if xmlrpc:
            return 0
Пример #12
0
    def runDeviceMonitorPerDatasource(self,
                                      device=None,
                                      REQUEST=None,
                                      write=None,
                                      collection_daemon=None,
                                      parameter='',
                                      value=''):
        """
        Run collection daemon against specific datasource
        """
        xmlrpc = isXmlRpc(REQUEST)
        monitoringCmd = self._getMonitoringCommand(device.id, self.id, write,
                                                   collection_daemon,
                                                   parameter, value)
        result = self._executeCommand(monitoringCmd, REQUEST, write)
        if result and xmlrpc:
            return result
        log.info('configuration collected')

        if xmlrpc:
            return 0
Пример #13
0
    def collectDevice(self,
                      device=None,
                      setlog=True,
                      REQUEST=None,
                      generateEvents=False,
                      background=False,
                      write=None,
                      collectPlugins='',
                      debug=False):
        """
        Collect the configuration of this device AKA Model Device

        @permission: ZEN_MANAGE_DEVICE
        @param device: Name of a device or entry in DMD
        @type device: string
        @param setlog: If true, set up the output log of this process
        @type setlog: boolean
        @param REQUEST: Zope REQUEST object
        @type REQUEST: Zope REQUEST object
        @param generateEvents: unused
        @type generateEvents: string
        @param collectPlugins: (optional) Modeler plugins to use.
                               Takes a regular expression (default: '')
        @type  collectPlugins: string
        """
        xmlrpc = isXmlRpc(REQUEST)
        result = self._executeZenModelerCommand(device.id,
                                                self.id,
                                                background,
                                                REQUEST,
                                                write,
                                                collectPlugins=collectPlugins,
                                                debug=debug)
        if result and xmlrpc:
            return result
        log.info('configuration collected')

        if xmlrpc:
            return 0
Пример #14
0
    def loadDevice(self,
                   deviceName,
                   devicePath="/Discovered",
                   tag="",
                   serialNumber="",
                   zSnmpCommunity="",
                   zSnmpPort=161,
                   zSnmpVer=None,
                   rackSlot=0,
                   productionState=1000,
                   comments="",
                   hwManufacturer="",
                   hwProductName="",
                   osManufacturer="",
                   osProductName="",
                   locationPath="",
                   groupPaths=[],
                   systemPaths=[],
                   performanceMonitor="localhost",
                   manageIp="",
                   discoverProto="snmp",
                   priority=3,
                   title=None,
                   REQUEST=None):
        """
        Load a device into the database connecting its major relations
        and collecting its configuration.
        """
        device = None
        if not deviceName:
            return self.callZenScreen(REQUEST)
        xmlrpc = isXmlRpc(REQUEST)
        if REQUEST and not xmlrpc:
            handler = setupLoggingHeader(self, REQUEST)

        loader = WeblogDeviceLoader(self, REQUEST)

        try:
            device = loader.load_device(
                deviceName,
                devicePath,
                discoverProto,
                performanceMonitor,
                manageIp,
                zProperties=dict(zSnmpCommunity=zSnmpCommunity,
                                 zSnmpPort=zSnmpPort,
                                 zSnmpVer=zSnmpVer),
                deviceProperties=dict(tag=tag,
                                      serialNumber=serialNumber,
                                      rackSlot=rackSlot,
                                      productionState=productionState,
                                      comments=comments,
                                      hwManufacturer=hwManufacturer,
                                      hwProductName=hwProductName,
                                      osManufacturer=osManufacturer,
                                      osProductName=osProductName,
                                      locationPath=locationPath,
                                      groupPaths=groupPaths,
                                      systemPaths=systemPaths,
                                      priority=priority,
                                      title=title))
        except ZentinelException as e:
            log.info(e)
            if xmlrpc:
                return 1
        except DeviceExistsError as e:
            log.info(e)
            if xmlrpc:
                return 2
        except NoSnmp as e:
            log.info(e)
            if xmlrpc:
                return 3
        except Exception as e:
            log.exception(e)
            log.exception('load of device %s failed', deviceName)
            transaction.abort()
        if device is None:
            log.error("Unable to add the device %s", deviceName)
        else:
            log.info("Device %s loaded!", deviceName)

        if REQUEST and not xmlrpc:
            self.loaderFooter(device, REQUEST.RESPONSE)
            clearWebLoggingStream(handler)
        if xmlrpc:
            return 0