Exemplo n.º 1
0
    def query(self):
        """Query all remote devices for data.

        Args:
            None

        Returns:
            None

        """
        # Initialize key variables
        config = self.config

        # Check for lock and pid files
        if os.path.exists(self.lockfile_parent) is True:
            log_message = (
                'Lock file %s exists. Multiple API daemons running '
                'API may have died '
                'catastrophically in the past, in which case the lockfile '
                'should be deleted. '
                '') % (self.lockfile_parent)
            log.log2see(1083, log_message)

        if os.path.exists(self.pidfile_parent) is True:
            log_message = (
                'PID file: %s already exists. Daemon already running? '
                'If not, it may have died catastrophically in the past '
                'in which case you should use --stop --force to fix.'
                '') % (self.pidfile_parent)
            log.log2see(1084, log_message)

        ######################################################################
        #
        # Assign options in format that the Gunicorn WSGI will accept
        #
        # NOTE! to get a full set of valid options pprint(self.cfg.settings)
        # in the instantiation of StandaloneApplication. The option names
        # do not exactly match the CLI options found at
        # http://docs.gunicorn.org/en/stable/settings.html
        #
        ######################################################################
        options = {
            'bind': '%s:%s' % (config.listen_address(), config.bind_port()),
            'accesslog': config.web_log_file(),
            'errorlog': config.web_log_file(),
            'capture_output': True,
            'pidfile': self.pidfile_child,
            'loglevel': config.log_level(),
            'workers': _number_of_workers(),
        }

        # Log so that user running the script from the CLI knows that something
        # is happening
        log_message = ('Infoset API running on %s:%s and logging to file %s.'
                       '') % (config.listen_address(), config.bind_port(),
                              config.web_log_file())
        log.log2info(1022, log_message)

        # Run
        StandaloneApplication(API, options).run()
Exemplo n.º 2
0
def main():
    """Process agent data.

    Args:
        None

    Returns:
        None

    """
    # 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 = ('db/agent/getidagent/%s') % (id_agent)
        results = api.get(uri)

        # print results
        if results['exists'] is True:
            log_message = ('Successfully retrieved test data for agent ID %s'
                           '') % (id_agent)
            log.log2see(1034, 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(1035, log_message)
            print('\nOK - Ingester not running\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(1039, log_message)
        print('\nFail\n')
Exemplo n.º 3
0
def main():
    """Process agent data.

    Args:
        None

    Returns:
        None

    """
    # 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')