コード例 #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 = ('Switchmap 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()
コード例 #2
0
ファイル: test.py プロジェクト: brett-miller/switchmap-ng
def run(args):
    """Process 'test' command.

    Args:
        parser: Argparse parser
        args: Argparse arguments

    Returns:
        None

    """
    # Process the config
    snmp_config = CONFIG_SNMP
    config = CONFIG

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

    # Test a single host
    if bool(args.hostname) is True:
        hostname = args.hostname
        test_hostname(hostname, snmp_config)
        sys.exit(0)

    # Test all hosts
    elif bool(args.all) is True:
        hosts = config.hostnames()
        if isinstance(hosts, list) is True:
            if len(hosts) > 0:
                for host in hosts:
                    test_hostname(host, snmp_config)
                sys.exit(0)
            else:
                # No hosts found
                log_message = 'No hosts found in configuration'
                log.log2see(1038, log_message)

        else:
            # No hosts found
            log_message = 'No hosts found in configuration'
            log.log2see(1039, log_message)

    # Show help if there are no matches
    general.cli_help()
コード例 #3
0
def test_hostname(hostname, snmp_config):
    """Process 'test poller --hostname' commands.

    Args:
        args: Argparse arguments

    Returns:
        None

    """
    # Show host information
    validate = snmp_manager.Validate(hostname, snmp_config.snmp_auth())
    snmp_params = validate.credentials()

    if bool(snmp_params) is True:
        print('OK - Valid credentials found, successfully contacted: {}'
              ''.format(hostname))
    else:
        # Error, host problems
        log_message = ('Uncontactable host %s or no valid SNMP '
                       'credentials found for it.') % (hostname)
        log.log2see(1040, log_message)