def _executeZenModelerCommand(self, zenmodelerOpts, *args):
    """
    Execute zenmodeler and return result

    @param zenmodelerOpts: zenmodeler command-line options
    @type zenmodelerOpts: string
    @param REQUEST: Zope REQUEST object
    @type REQUEST: Zope REQUEST object
    @return: results of command
    @rtype: string
    """
    zm = binPath('zenmodeler')
    zenmodelerCmd = [zm]
    zenmodelerCmd.extend(zenmodelerOpts)
    if zenmodelerOpts[3] != 'localhost':
        zenmodelerCmd.extend(['--hubhost', socket.getfqdn()])
        zenmodelerCmd = ['/usr/bin/ssh', zenmodelerOpts[3]] + zenmodelerCmd
    if len(args) == 3:
        background, REQUEST, write = args
        if background:
#            log.info('queued job: %s', " ".join(zenmodelerCmd))
            if 'SubprocessJob' in locals():
                log.info('queued job: %s', " ".join(zenmodelerCmd))
                result = self.dmd.JobManager.addJob(SubprocessJob,
                    description="Run zenmodeler %s" % ' '.join(zenmodelerOpts),
                    args=(zenmodelerCmd,))
            else:
                result = self.dmd.JobManager.addJob(ShellCommandJob,zenmodelerCmd)
        else:
            result = executeCommand(zenmodelerCmd, REQUEST, write)
    else:
        result = executeCommand(zenmodelerCmd, args[0])
    return result
def _executeZenModelerCommand(self, zenmodelerOpts, *args):
    """
    Execute zenmodeler and return result

    @param zenmodelerOpts: zenmodeler command-line options
    @type zenmodelerOpts: string
    @param REQUEST: Zope REQUEST object
    @type REQUEST: Zope REQUEST object
    @return: results of command
    @rtype: string
    """
    zm = binPath('zenmodeler')
    zenmodelerCmd = [zm]
    zenmodelerCmd.extend(zenmodelerOpts)
    if zenmodelerOpts[3] != 'localhost':
        zenmodelerCmd.extend(['--hubhost', socket.getfqdn()])
        zenmodelerCmd = ['/usr/bin/ssh', zenmodelerOpts[3]] + zenmodelerCmd
    if len(args) == 3:
        background, REQUEST, write = args
        if background:
            log.info('queued job: %s', " ".join(zenmodelerCmd))
            from Products.Jobber.jobs import SubprocessJob
            result = self.dmd.JobManager.addJob(SubprocessJob, zenmodelerCmd)
        else:
            result = executeCommand(zenmodelerCmd, REQUEST, write)
    else:
        result = executeCommand(zenmodelerCmd, args[0])
    return result
def _executeZenModelerCommand(self, zenmodelerOpts, *args):
    """
    Execute zenmodeler and return result

    @param zenmodelerOpts: zenmodeler command-line options
    @type zenmodelerOpts: string
    @param REQUEST: Zope REQUEST object
    @type REQUEST: Zope REQUEST object
    @return: results of command
    @rtype: string
    """
    zm = binPath("zenmodeler")
    zenmodelerCmd = [zm]
    zenmodelerCmd.extend(zenmodelerOpts)
    if zenmodelerOpts[3] != "localhost":
        zenmodelerCmd.extend(["--hubhost", socket.getfqdn()])
        zenmodelerCmd = ["/usr/bin/ssh", zenmodelerOpts[3]] + zenmodelerCmd
    if len(args) == 3:
        background, REQUEST, write = args
        if background:
            #            log.info('queued job: %s', " ".join(zenmodelerCmd))
            result = self.dmd.JobManager.addJob(ShellCommandJob, zenmodelerCmd)
        else:
            result = executeCommand(zenmodelerCmd, REQUEST, write)
    else:
        result = executeCommand(zenmodelerCmd, args[0])
    return result
Ejemplo n.º 4
0
def _executeZenDiscCommand(self, deviceName, devicePath= "/Discovered", 
                               performanceMonitor="localhost",
                               background=False, REQUEST=None):
    """
    Execute zendisc on the new device and return result

    @param deviceName: Name of a device
    @type deviceName: string
    @param devicePath: DMD path to create the new device in
    @type devicePath: string
    @param performanceMonitor: DMD object that collects from a device
    @type performanceMonitor: DMD object
    @param background: should command be scheduled job?
    @type background: boolean
    @param REQUEST: Zope REQUEST object
    @type REQUEST: Zope REQUEST object
    @return:
    @rtype:
    """
    zendiscCmd = self._getZenDiscCommand(deviceName, devicePath,
                                             performanceMonitor, REQUEST)
    if background:
#        log.info('queued job: %s', " ".join(zendiscCmd))
        result = self.dmd.JobManager.addJob(ShellCommandJob,
                                                zendiscCmd)
    else:
        result = executeCommand(zendiscCmd, REQUEST)
    return result
Ejemplo n.º 5
0
    def _executeZenDiscCommand(self,
                               deviceName,
                               devicePath="/Discovered",
                               performanceMonitor="localhost",
                               productionState=1000,
                               background=False,
                               REQUEST=None):
        """
        Execute zendisc on the new device and return result

        @param deviceName: Name of a device
        @type deviceName: string
        @param devicePath: DMD path to create the new device in
        @type devicePath: string
        @param performanceMonitor: DMD object that collects from a device
        @type performanceMonitor: DMD object
        @param background: should command be scheduled job?
        @type background: boolean
        @param REQUEST: Zope REQUEST object
        @type REQUEST: Zope REQUEST object
        @return:
        @rtype:
        """
        zendiscCmd = self._getZenDiscCommand(deviceName, devicePath,
                                             performanceMonitor,
                                             productionState, REQUEST)
        if background:
            log.info('queued job: %s', " ".join(zendiscCmd))
            result = self.dmd.JobManager.addJob(
                SubprocessJob,
                description="Discover and model device %s" % deviceName,
                args=(zendiscCmd, ))
        else:
            result = executeCommand(zendiscCmd, REQUEST)
        return result
Ejemplo n.º 6
0
    def _executeZenModelerCommand(self,
                                  zenmodelerOpts,
                                  background=False,
                                  REQUEST=None,
                                  write=None):
        """
        Execute zenmodeler and return result

        @param zenmodelerOpts: zenmodeler command-line options
        @type zenmodelerOpts: string
        @param REQUEST: Zope REQUEST object
        @type REQUEST: Zope REQUEST object
        @return: results of command
        @rtype: string
        """
        zm = binPath('zenmodeler')
        zenmodelerCmd = [zm]
        zenmodelerCmd.extend(zenmodelerOpts)
        if background:
            log.info('queued job: %s', " ".join(zenmodelerCmd))
            result = self.dmd.JobManager.addJob(
                SubprocessJob,
                description="Run zenmodeler %s" % ' '.join(zenmodelerOpts),
                args=(zenmodelerCmd, ))
        else:
            result = executeCommand(zenmodelerCmd, REQUEST, write)
        return result
    def _executeZenDiscCommand(self, deviceName, devicePath= "/Discovered",
                               performanceMonitor="localhost", productionState=1000,
                               background=False, REQUEST=None):
        """
        Execute zendisc on the new device and return result

        @param deviceName: Name of a device
        @type deviceName: string
        @param devicePath: DMD path to create the new device in
        @type devicePath: string
        @param performanceMonitor: DMD object that collects from a device
        @type performanceMonitor: DMD object
        @param background: should command be scheduled job?
        @type background: boolean
        @param REQUEST: Zope REQUEST object
        @type REQUEST: Zope REQUEST object
        @return:
        @rtype:
        """
        args = [deviceName, devicePath, performanceMonitor, productionState]
        if background:
            zendiscCmd = self._getZenDiscCommand(*args)
            result = self.dmd.JobManager.addJob(
                    SubprocessJob, args=(zendiscCmd,),
                    description="Discover and model device %s as %s" % (
                        args[0], args[1]
                    )
                )
        else:
            args.append(REQUEST)
            zendiscCmd = self._getZenDiscCommand(*args)
            result = executeCommand(zendiscCmd, REQUEST)
        return result
Ejemplo n.º 8
0
    def _executeZenModelerCommand(
            self, zenmodelerOpts, background=False, REQUEST=None, write=None):
        """
        Execute zenmodeler and return result

        @param zenmodelerOpts: zenmodeler command-line options
        @type zenmodelerOpts: string
        @param REQUEST: Zope REQUEST object
        @type REQUEST: Zope REQUEST object
        @return: results of command
        @rtype: string
        """
        zm = binPath('zenmodeler')
        zenmodelerCmd = [zm]
        zenmodelerCmd.extend(zenmodelerOpts)
        if background:
            log.info('queued job: %s', " ".join(zenmodelerCmd))
            result = self.dmd.JobManager.addJob(
                SubprocessJob,
                description="Run zenmodeler %s" % ' '.join(zenmodelerOpts),
                args=(zenmodelerCmd,)
            )
        else:
            result = executeCommand(zenmodelerCmd, REQUEST, write)
        return result
Ejemplo n.º 9
0
    def bootsequencetype(self, deviceip, bootsequence, allbmcdevice):
        '''
        bootsequencetype
        '''
        deviceroot = self._dmd.getDmdRoot("Devices")
        device = deviceroot.findDevice(deviceip)
        if device is None:
            return [deviceip, "device Not found!"]
        log.debug("myFacadeFunc data %s %s %s %s", deviceip, allbmcdevice,
                  device.__class__, device.zSnmpVer)
        #         arg1 = deviceip
        #         arg2 = "-v2c"
        #         arg3 = "-cpublic"
        #         arg4 = ""
        #         arg5 = ""
        #         arg6 = ""
        #         arg7 = ""
        #         arg8 = ""
        arg1 = deviceip
        arg2 = "-" + device.zSnmpVer
        arg3 = "-c" + device.zSnmpCommunity
        arg4 = "-u" + device.zSnmpSecurityName
        arg5 = "-a" + device.zSnmpAuthType
        arg6 = "-A" + device.zSnmpAuthPassword
        arg7 = "-x" + device.zSnmpPrivType
        arg8 = "-X" + device.zSnmpPrivPassword
        arg9 = bootsequence

        if not bootsequence.isdigit():
            return [deviceip, 'option not in range']
        if int(bootsequence) > 20:
            return [deviceip, 'option not in range']

        libexec = os.path.join(os.path.dirname(__file__), 'libexec')
        predefinedcmd = []
        if arg2 == "-v2c":
            predefinedcmd = [
                libexec + '/bmcboottype.sh', arg1, arg2, arg3, arg4, arg5,
                arg6, arg7, arg8, arg9
            ]
        else:
            predefinedcmd = [
                libexec + '/bmcboottype.sh', arg1, arg2, arg3, arg4, arg5,
                arg6, arg7, arg8, arg9
            ]
        result = executeCommand(predefinedcmd, None, None)

        retstr = "Fail"
        if result == 0:
            retstr = "Success"
        log.info("executeCommand result %s ", result)
        return [deviceip, retstr]
Ejemplo n.º 10
0
    def stream(self):
        # Setup a logging file
        logfile = open('/opt/zenoss/log/rancid_example_logging.log', 'a')
        logfile.write('Start logging')
        # data is a list that will contain 2 elemets:
        #   the url argument and the uid

        #self.write('TEST parameter = %s\n' % (self.request.arguments()))

        data = unjson(self.request.get('data'))
        self.write('data stream = %s\n' % (data))

        #data = ""

        logfile.write(' data is %s \n' % (data))
        try:
            args = data['args']
            logfile.write('Argument is %s \n' % (args))
            arg3 = args
        except:
            logfile.write(' No args \n')
            arg3 = ''
        try:
            uids = data['uids']
            logfile.write('uids is %s \n' % (uids))
            arg4 = uids
        except:
            logfile.write('No uids \n')
            arg4 = ''

        libexec = os.path.join(os.path.dirname(__file__), 'libexec')

        arg1 = "Hello"
        arg2 = "World"

        # Put the  script in the libexec directory of the ZenPack
        myPredefinedCmd1 = [
            #libexec + '/mywrapper_script1',
            #"ls -a"
            #arg1, arg2, arg3, arg4
            "find",
            "/tmp"
        ]
        logfile.write(' myPredefinedCmd1 is %s ' % (myPredefinedCmd1))
        self.write('Preparing my command...')
        result = executeCommand(myPredefinedCmd1, None, write=self.write)
        #logfile.write(result)
        #self.write(result)
        self.write('End of command...')
        logfile.close()
        return result
    def executeCollectorCommand(self, command, args, REQUEST=None):
        """
        Executes the collector based daemon command.

        @param command: the collector daemon to run, should not include path
        @type command: string
        @param args: list of arguments for the command
        @type args: list of strings
        @param REQUEST: Zope REQUEST object
        @type REQUEST: Zope REQUEST object
        @return: result of the command
        @rtype: string
        """
        cmd = binPath(command)
        daemonCmd = [cmd]
        daemonCmd.extend(args)
        result = executeCommand(daemonCmd, REQUEST)
        return result
Ejemplo n.º 12
0
    def executeCollectorCommand(self, command, args, REQUEST=None, write=None):
        """
        Executes the collector based daemon command.

        @param command: the collector daemon to run, should not include path
        @type command: string
        @param args: list of arguments for the command
        @type args: list of strings
        @param REQUEST: Zope REQUEST object
        @type REQUEST: Zope REQUEST object
        @return: result of the command
        @rtype: string
        """
        cmd = binPath(command)
        daemonCmd = [cmd]
        daemonCmd.extend(args)
        result = executeCommand(daemonCmd, REQUEST, write)
        return result
Ejemplo n.º 13
0
 def frucontrolsingleblade(self, arg1, arg2, arg3, arg4, arg5,
                           arg6, arg7, arg8, arg9, arg10):
     '''
     frucontrolsingleblade
     '''
     libexec = os.path.join(os.path.dirname(__file__), 'libexec')
     predefinedcmd = []
     if arg2 == "-v2c":
         predefinedcmd = [
             libexec + '/hmmbladefrucontrol.sh', arg1, arg2,
             arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10]
     else:
         predefinedcmd = [
             libexec + '/hmmbladefrucontrol.sh', arg1, arg2,
             arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10]
     result = executeCommand(predefinedcmd, None, None)
     log.info("executeCommand result %s ", result)
     return result
Ejemplo n.º 14
0
    def frupowerctrlsingle(self, deviceip, frupowercontrol):
        '''
        frupowerctrlsingle
        '''
        deviceroot = self._dmd.getDmdRoot("Devices")
        device = deviceroot.findDevice(deviceip)
        if device is None:
            return [deviceip, "device Not found!"]
        arg1 = deviceip
        arg2 = "-" + device.zSnmpVer
        arg3 = "-c" + device.zSnmpCommunity
        arg4 = "-u" + device.zSnmpSecurityName
        arg5 = "-a" + device.zSnmpAuthType
        arg6 = "-A" + device.zSnmpAuthPassword
        arg7 = "-x" + device.zSnmpPrivType
        arg8 = "-X" + device.zSnmpPrivPassword
        frupowercontrolarg = str(frupowercontrol)
        arg9 = frupowercontrolarg

        if not frupowercontrolarg.isdigit():
            return [deviceip, 'option not in range']
        if int(frupowercontrolarg) > 10:
            return [deviceip, 'option not in range']

        libexec = os.path.join(os.path.dirname(__file__), 'libexec')
        predefinedcmd = []
        if arg2 == "-v2c":
            predefinedcmd = [
                libexec + '/bmcfrupowercontrol.sh', arg1, arg2, arg3, arg4,
                arg5, arg6, arg7, arg8, arg9
            ]
        else:
            predefinedcmd = [
                libexec + '/bmcfrupowercontrol.sh', arg1, arg2, arg3, arg4,
                arg5, arg6, arg7, arg8, arg9
            ]
        result = executeCommand(predefinedcmd, None, None)
        retstr = "Fail"
        if result == 0:
            retstr = "Success"
        log.info("executeCommand result %s ", result)
        return [deviceip, retstr]
    def stream(self):
    # Setup a logging file
        lf = os.path.join(os.environ['ZENHOME'], 'log/example_logging.log')
        logfile = open(lf, 'a')

        logfile.write('Start logging')
        # data is a list that will contain 2 elements:
        #   the url argument and the uid
        data = unjson(self.request.get('data'))
        logfile.write(' data is \n' % (data))
        try:
            args = data['args']
            logfile.write('Argument is %s \n' % (args))
            arg3 = args
        except:
            logfile.write(' No args \n')
            arg3 = ''
        try:
            uids = data['uids']
            logfile.write('uids is %s \n' % (uids))
            arg4 = uids
        except:
            logfile.write('No uids \n')
            arg4 = ''

        libexec = os.path.join(os.path.dirname(__file__), 'libexec')

        arg1 = "Hello"
        arg2 = "World"

        # Find the  script in the libexec directory of the ZenPack
        myPredefinedCmd1 = [
             libexec + '/mywrapper_script1',
            arg1, arg2, arg3, arg4
        ]
        logfile.write(' myPredefinedCmd1 is %s ' % (myPredefinedCmd1))
        self.write('Preparing my command...')
        result = executeCommand(myPredefinedCmd1, None, write=self.write)
        self.write('End of command...')
        logfile.close()
        return result
    def stream(self):
# Setup a logging file
        logfile = open('/usr/local/zenoss/zenoss/log/example_logging.log', 'a')
        logfile.write('Start logging')
        data = unjson(self.request.get('data'))
        logfile.write(' data is \n' % (data))
        try:
            args = data['args']
            logfile.write('Argument is %s \n' % (args))
            arg3 = args
        except:
            logfile.write(' No args \n')
            arg3 = ''
        try:
            uids = data['uids']
            logfile.write('uids is %s \n' % (uids))
            arg4 = uids
        except:
            logfile.write('No uids \n')
            arg4 = ''
#        facade = getFacade('device', self.context)
#        organizer = facade._getObject(uids[0])
#        logfile.write(' organizer is %s ' % (organizer))

        libexec = os.path.join(os.path.dirname(__file__), 'libexec')

        arg1 = "Hello"
        arg2 = "World"

# Put the  script in the libexec directory of the ZenPack
        myPredefinedCmd1 = [
             libexec + '/mywrapper_script1',
            arg1, arg2, arg3, arg4
        ]
        logfile.write(' myPredefinedCmd1 is %s ' % (myPredefinedCmd1))
        self.write('Preparing my command...')
        result = executeCommand(myPredefinedCmd1, None, write=self.write)
        self.write('End of command...')
        logfile.close()
        return result
Ejemplo n.º 17
0
 def frucontrolsingleblade(self, arg1, arg2, arg3, arg4, arg5, arg6, arg7,
                           arg8, arg9, arg10):
     '''
     frucontrolsingleblade
     '''
     libexec = os.path.join(os.path.dirname(__file__), 'libexec')
     predefinedcmd = []
     # 2018-01-12 add power on and off oid
     valarg = int(arg10)
     if valarg >= 100:
         if valarg == 100:
             arg10 = "poweron"
         if valarg == 101:
             arg10 = "poweroff"
         if arg2 == "-v2c":
             predefinedcmd = [
                 libexec + '/hmmbladefruonoff.sh', arg1, arg2, arg3, arg4,
                 arg5, arg6, arg7, arg8, arg9, arg10
             ]
         else:
             predefinedcmd = [
                 libexec + '/hmmbladefruonoff.sh', arg1, arg2, arg3, arg4,
                 arg5, arg6, arg7, arg8, arg9, arg10
             ]
     else:
         if arg2 == "-v2c":
             predefinedcmd = [
                 libexec + '/hmmbladefrucontrol.sh', arg1, arg2, arg3, arg4,
                 arg5, arg6, arg7, arg8, arg9, arg10
             ]
         else:
             predefinedcmd = [
                 libexec + '/hmmbladefrucontrol.sh', arg1, arg2, arg3, arg4,
                 arg5, arg6, arg7, arg8, arg9, arg10
             ]
     result = executeCommand(predefinedcmd, None, None)
     log.info("executeCommand result %s ", result)
     return result
def _executeZenDiscCommand(self, deviceName, devicePath= "/Discovered", 
                               performanceMonitor="localhost", *args):
    """
    Execute zendisc on the new device and return result

    @param deviceName: Name of a device
    @type deviceName: string
    @param devicePath: DMD path to create the new device in
    @type devicePath: string
    @param performanceMonitor: DMD object that collects from a device
    @type performanceMonitor: DMD object
    @param background: should command be scheduled job?
    @type background: boolean
    @param REQUEST: Zope REQUEST object
    @type REQUEST: Zope REQUEST object
    @return:
    @rtype:
    """
    if len(args) == 3:
        productionState, background, REQUEST = args
    else:
        background,REQUEST = args

    zendiscCmd = self._getZenDiscCommand(deviceName, devicePath,
                                             performanceMonitor, REQUEST)
    if background:
#        log.info('queued job: %s', " ".join(zendiscCmd))
        if 'SubprocessJob' in globals():
            result = self.dmd.JobManager.addJob(SubprocessJob,
                description="Discover and model device %s" % deviceName,
                args=(zendiscCmd,))
        else:
            result = self.dmd.JobManager.addJob(ShellCommandJob,
                                                    zendiscCmd)
    else:
        result = executeCommand(zendiscCmd, REQUEST)
    return result
Ejemplo n.º 19
0
 def _executeCommand(self, remoteCommand, REQUEST=None, write=None):
     result = executeCommand(remoteCommand, REQUEST, write)
     return result
Ejemplo n.º 20
0
 def _executeCommand(self, remoteCommand, REQUEST=None, write=None):
     result = executeCommand(remoteCommand, REQUEST, write)
     return result