Ejemplo n.º 1
0
def ingester(args):
    """Process 'show ingester' commands.

    Args:
        args: Argparse arguments

    Returns:
        None

    """
    if args.subqualifier == 'logs':
        # Process logs
        config = configuration.Config()
        filename = config.log_file()
        tail = input_output.File(filename)
        tail.tail()

        # Done
        sys.exit(0)

    elif args.subqualifier == 'status':
        # Create agent objects
        agent_ingester = Agent(INGESTER_EXECUTABLE)

        # Get agent status
        daemon_ingester = AgentDaemon(agent_ingester)
        daemon_ingester.status()

        # Done
        sys.exit(0)

    # Show help if there are no matches
    general.cli_help()
Ejemplo n.º 2
0
def run(args):
    """Process 'stop' command.

    Args:
        args: Argparse arguments

    Returns:
        None

    """
    # Show help if no arguments provided
    if args.qualifier is None:
        general.cli_help()

    # Process 'show api' command
    if args.qualifier == 'api':
        api(args)
    elif args.qualifier == 'ingester':
        ingester(args)

    # Show help if there are no matches
    general.cli_help()
Ejemplo n.º 3
0
def api(args):
    """Process 'show api' commands.

    Args:
        args: Argparse arguments

    Returns:
        None

    """
    if args.subqualifier == 'logs':
        # Process logs
        config = configuration.Config()
        filename = config.web_log_file()
        tail = input_output.File(filename)
        tail.tail()

        # Done
        sys.exit(0)

    elif args.subqualifier == 'status':
        # Create agent objects
        agent_gunicorn = Agent(API_GUNICORN_AGENT)
        agent_api = AgentAPI(API_EXECUTABLE, API_GUNICORN_AGENT)

        # Get agent status
        daemon_gunicorn = AgentDaemon(agent_gunicorn)
        daemon_gunicorn.status()
        daemon_api = AgentDaemon(agent_api)
        daemon_api.status()

        # Done
        sys.exit(0)

    # Show help if there are no matches
    general.cli_help()
Ejemplo n.º 4
0
def run(args):
    """Process 'test' command.

    Args:
        parser: Argparse parser
        args: Argparse arguments

    Returns:
        None

    """
    if args.action == 'test':
        # Get configuration
        config = reference.ReferenceSampleConfig()
        api = reference.ReferenceSampleAPI(config)
        agent_name = config.agent_name()
        devicename = config.prefix
        id_agent = reference.get_id_agent(agent_name, test=True)

        # Instantiate an agent
        report = reference.ReferenceSampleAgent(config, devicename, test=True)

        # Populate data and post
        report.populate_dict(_data2post())
        success = report.post()

        # Posting success
        if success is True:
            # Log success
            log_message = ('Successfully posted test data for agent ID %s'
                           '') % (id_agent)
            log.log2see(1015, log_message)

            # Try to retrieve data
            uri = ('/agents?id_agent=%s') % (id_agent)
            results = api.get(uri)

            if bool(results) is True:
                if isinstance(results, dict) is True:
                    # print results
                    if results['exists'] is True:
                        log_message = (
                            'Successfully retrieved test data for agent ID %s'
                            '') % (id_agent)
                        log.log2see(1132, log_message)
                        print('\nOK\n')
                    else:
                        log_message = (
                            'WARNING: Contacted this infoset server. '
                            'The data for the test agent ID %s is not present '
                            'in the database. Ingester has not added agent to '
                            'the database'
                            '') % (id_agent)
                        log.log2see(1133, log_message)
                        print("""\
    OK, but Ingester has not updated the database yet. \
    Run test in a minute and this message should change. \
    If not, the Ingester may not be running.
    """)
                else:
                    log_message = (
                        'Failed to retrieve posted data to the local infoset '
                        'server. Review the installation steps '
                        'and verify whether the API is running.')
                    log.log2die(1140, log_message)
                    print('\nFail\n')

            else:
                log_message = (
                    'Failed to retrieve posted data to the local infoset '
                    'server. Review the installation steps '
                    'and verify whether the API is running.')
                log.log2die(1141, log_message)
                print('\nFail\n')

        else:
            log_message = ('Failed to post data to the local infoset server. '
                           'Review the installation steps '
                           'and verify whether the API is running.')
            log.log2die(1142, log_message)
            print('\nFail\n')

            # Exit OK
            sys.exit(0)
    else:
        # Show help if there are no matches
        general.cli_help()