Exemple #1
0
 def execute(self, config=None):
     """
     ***********************************************************************
     
     ***********************************************************************
     """ 
     if not self.arg1:
         return cli.LogMapperCommandResponse(False, "Invalid option")        
     
     if self.arg1 == 'map':
         if len(self.args) < 2: return cli.LogMapperCommandResponse(False, "Invalid arguments")
         #TODO MEJOR FORMA DE SELECCIONAR KEY
         key = self.args[1]
         readerConfig = cfg.loadReaderConfig(config, key)
         mapperThread = mapper.MapperThread(readerConfig, readerConfig)
         mapperThread.start()             
         
         return cli.LogMapperCommandResponse(True, "Mapper started") 
     
     if self.arg1 == 'readers':
         startReadersThreads(config)
         return cli.LogMapperCommandResponse(True, "All readers started")         
     
     if self.arg1 == 'mappers':
         startMapperThreads(config)
         return cli.LogMapperCommandResponse(True, "All mappers started") 
     
     if self.arg1 == 'monitors':
         startMonitorsThreads(config)
         return cli.LogMapperCommandResponse(True, "All monitors started")         
     
     if self.arg1 == 'register':
         return cli.LogMapperCommandResponse(True, startRegister(config))         
     
     return cli.LogMapperCommandResponse(False, "Invalid option")
Exemple #2
0
def startMapperThreads(config):
    """ 
    ===========================================================================
    Summary 
    ===========================================================================   
    
    **Args**:
        arg1
    **Returns**:
        None
    """    
    readers = cfg.getReaders(config)
    for readerName in readers:
        readerConfig = cfg.loadReaderConfig(config, readerName)
        if readerConfig.enable:
            mapperThread = mapper.MapperThread(readerConfig, th.OperationMode.NORMAL)
            mapperThread.start() 
Exemple #3
0
def getReaders(config):
    """
    Get Readers and Component Data
    """
    logger.info('getReaders')
    readersList = []
    for reader in cfg.getReaders(config):
        readerConfig = cfg.loadReaderConfig(config, reader)
        r = {
            'readerKey': readerConfig.key,
            'component': readerConfig.component,
            'host': readerConfig.hostname,
            'enable': readerConfig.enable,
            'sourceFilePath': readerConfig.sourcefilepath,
            'parserModuleName': readerConfig.moduleName,
            'parserClassName': readerConfig.className
        }
        readersList.append(r)

    data = {'readers': readersList}
    return data
Exemple #4
0
def startReadersThreads(config):
    """ 
    ===========================================================================
    Summary 
    ===========================================================================   
    
    **Args**:
        arg1
    **Returns**:
        None
    """     
    # Start Readers Threads    
    readers = cfg.getReaders(config)
    for key in readers:
        readerConfig = cfg.loadReaderConfig(config, key)
        readerThread = thutil.getThread(cfg.THREAD_READER+readerConfig.key)
        
        if readerThread:
            logger.debug("Thread already running:"+readerConfig.key)
            continue
        
        if readerConfig.enable:
            readerThread = reader.ReaderThread(readerConfig, th.OperationMode.NORMAL)
            readerThread.start()             
Exemple #5
0
def stopMapperThreads(config):
    readers = cfg.getReaders(config)
    for readerName in readers:
        readerConfig = cfg.loadReaderConfig(config, readerName)
        mapperThread = thutil.getThread(cfg.THREAD_MAPPER + readerConfig.key)
        if mapperThread: mapperThread.stopRun()
Exemple #6
0
def stopReaderThreads(config):
    readers = cfg.getReaders(config)
    for readerName in readers:
        readerConfig = cfg.loadReaderConfig(config, readerName)
        readerThread = thutil.getThread(cfg.THREAD_READER + readerConfig.key)
        if readerThread: readerThread.stopRun()
Exemple #7
0
#%%
"""
*******************************************************************************
Module Execution
This code helps to developer to know the usage of the module
*******************************************************************************
"""
if __name__ == '__main__':
    print('Start module execution:')
    logging.basicConfig(level=logging.DEBUG,
                        format='%(asctime)s - %(levelname)s - %(message)s',
                        datefmt='%H:%M:%S')

    cfg.createDefaultConfigfile()
    config = cfg.loadConfig()

    readers = cfg.getReaders(config)
    for readerName in readers:
        readerName = 'device'
        readerConfig = cfg.loadReaderConfig(config, readerName)
        if readerConfig.enable:
            mapperThread = MapperThread(readerConfig, th.OperationMode.NORMAL)
            mapperThread.start()

    print("Wait mapper finish")
    mapperThread.join()

    #    print("PathsFound = " + str(mapperThread.countPathsFound))
    #    print("output     = " + str(mapperThread.output))

    print("End module execution")
Exemple #8
0
def setReaderThreads(config, cmd, value):
    readers = cfg.getReaders(config)
    for readerName in readers:
        readerConfig = cfg.loadReaderConfig(config, readerName)
        readerThread = thutil.getThread(cfg.THREAD_READER+readerConfig.key)
        applyOptionInThread(readerThread, cmd, value)
Exemple #9
0
    def execute(self, config=None):
        """
        ***********************************************************************
        
        ***********************************************************************
        """
        if not self.arg1:
            return cli.LogMapperCommandResponse(False, "Invalid option")

        if self.arg1 == 'agent':
            return cli.LogMapperCommandResponse(True,
                                                json.dumps(getAgent(config)))

        if self.arg1 == 'readers':
            return cli.LogMapperCommandResponse(True,
                                                json.dumps(getReaders(config)))

        if self.arg1 == 'monitors':
            return cli.LogMapperCommandResponse(
                True, json.dumps(getMonitors(config)))

        if self.arg1 == 'logkeys' and len(self.args) == 2:
            key = self.args[1]
            readerConfig = cfg.loadReaderConfig(config, key)
            return cli.LogMapperCommandResponse(
                True, json.dumps(getLogNodesByCategoryTrace(readerConfig)))

        if self.arg1 == 'paths' and len(self.args) == 2:
            key = self.args[1]
            readerConfig = cfg.loadReaderConfig(config, key)
            return cli.LogMapperCommandResponse(
                True, json.dumps(getLogPaths(readerConfig)))

        if self.arg1 == 'pathMeasures' and len(self.args) == 4:
            key = self.args[1]
            readerConfig = cfg.loadReaderConfig(config, key)
            start = datetime.datetime.strptime(self.args[2], '%Y-%m-%dT%H:%M')
            end = datetime.datetime.strptime(self.args[3], '%Y-%m-%dT%H:%M')
            return cli.LogMapperCommandResponse(
                True, json.dumps(getJsonPathMeasures(readerConfig, start,
                                                     end)))

        if self.arg1 == 'logEventsCount' and len(self.args) == 4:
            key = self.args[1]
            readerConfig = cfg.loadReaderConfig(config, key)
            start = datetime.datetime.strptime(self.args[2], '%Y-%m-%dT%H:%M')
            end = datetime.datetime.strptime(self.args[3], '%Y-%m-%dT%H:%M')
            return cli.LogMapperCommandResponse(
                True,
                json.dumps(getJsonLogEventsCount(readerConfig, start, end)))

        if self.arg1 == 'logMetrics' and len(self.args) == 4:
            key = self.args[1]
            readerConfig = cfg.loadReaderConfig(config, key)
            start = datetime.datetime.strptime(self.args[2], '%Y-%m-%dT%H:%M')
            end = datetime.datetime.strptime(self.args[3], '%Y-%m-%dT%H:%M')
            return cli.LogMapperCommandResponse(
                True, json.dumps(getJsonLogMetrics(readerConfig, start, end)))

        if self.arg1 == 'logMetricsColnames' and len(self.args) == 2:
            key = self.args[1]
            readerConfig = cfg.loadReaderConfig(config, key)
            return cli.LogMapperCommandResponse(
                True, json.dumps(getJsonLogColnames(readerConfig)))

        if self.arg1 == 'monMeasures' and len(self.args) == 4:
            key = self.args[1]
            monitorConfig = cfg.loadMonitorConfig(config, key)
            start = datetime.datetime.strptime(self.args[2], '%Y-%m-%dT%H:%M')
            end = datetime.datetime.strptime(self.args[3], '%Y-%m-%dT%H:%M')
            return cli.LogMapperCommandResponse(
                True,
                json.dumps(getJsonMonitorMeasures(monitorConfig, start, end)))

        if self.arg1 == 'monMeasuresColnames' and len(self.args) == 2:
            key = self.args[1]
            monitorConfig = cfg.loadMonitorConfig(config, key)
            return cli.LogMapperCommandResponse(
                True, json.dumps(getJsonMonitorColnames(monitorConfig)))

        if self.arg1 == 'logRecords' and len(self.args) == 4:
            key = self.args[1]
            readerConfig = cfg.loadReaderConfig(config, key)
            start = datetime.datetime.strptime(self.args[2], '%Y-%m-%dT%H:%M')
            end = datetime.datetime.strptime(self.args[3], '%Y-%m-%dT%H:%M')
            return cli.LogMapperCommandResponse(
                True,
                json.dumps(getLogEventsWithRemoteCall(readerConfig, start,
                                                      end)))

        if self.arg1 == 'logkeysEvents' and len(self.args) == 3:
            category = cat.LogEventCategories[self.args[1]]
            key = self.args[2]
            readerConfig = cfg.loadReaderConfig(config, key)
            return cli.LogMapperCommandResponse(
                True, json.dumps(getLogNodesByCategory(readerConfig,
                                                       category)))

        return cli.LogMapperCommandResponse(False, "Invalid option")
Exemple #10
0
#%%
"""
*******************************************************************************
Module Execution
This code helps to developer to know the usage of the module
*******************************************************************************
"""
if __name__ == '__main__':
    print('Start module execution:')
    logging.basicConfig(level=logging.DEBUG,
                        format='%(asctime)s - %(levelname)s - %(message)s',
                        datefmt='%H:%M:%S')

    cfg.createDefaultConfigfile()
    config = cfg.loadConfig()

    key = 'device'
    readerConfig = cfg.loadReaderConfig(config, key)
    if readerConfig.enable:
        readerThread = ReaderThread(readerConfig, th.OperationMode.NORMAL)
        readerThread.start()

    input("Press key to finish")
    readerThread.stopRun()

    print("BytesReaded = " + str(readerThread.bytesProcessed))
    print("Lines       = " + str(readerThread.loopCount))
    print("Parsed      = " + str(readerThread.recordsProcessed))
    print("PathsFound  = " + str(readerThread.countPathsFound))

    print("End module execution")