Пример #1
0
def configcheck():
    all_valid = True
    for conf_path in glob.glob(os.path.join(get_confd_path(), "*.yaml")):
        basename = os.path.basename(conf_path)
        try:
            check_yaml(conf_path)
        except Exception, e:
            all_valid = False
            print "%s contains errors:\n    %s" % (basename, e)
        else:
            print "%s is valid" % basename
Пример #2
0
def configcheck():
    all_valid = True
    for conf_path in glob.glob(os.path.join(get_confd_path(), "*.yaml")):
        basename = os.path.basename(conf_path)
        try:
            check_yaml(conf_path)
        except Exception, e:
            all_valid = False
            print "%s contains errors:\n    %s" % (basename, e)
        else:
            print "%s is valid" % basename
Пример #3
0
def get_hostname():
    """Return the `Name` param from `docker info` to use as the hostname"""
    from config import get_confd_path, check_yaml, PathNotFound

    confd_path = ""

    try:
        confd_path = get_confd_path()
    except PathNotFound:
        log.error("Couldn't find the check configuration folder, not using the docker hostname.")
        return None

    conf_path = os.path.join(confd_path, "%s.yaml" % CHECK_NAME)
    if not os.path.exists(conf_path):
        default_conf_path = os.path.join(confd_path, "%s.yaml.default" % CHECK_NAME)
        if not os.path.exists(default_conf_path):
            log.error("Couldn't find any configuration file for the docker check." " Not using the docker hostname.")
            return None
        else:
            conf_path = default_conf_path

    check_config = check_yaml(conf_path)
    init_config, instances = check_config.get("init_config", {}), check_config["instances"]
    init_config = {} if init_config is None else init_config
    if len(instances) > 0:
        set_docker_settings(init_config, instances[0])
        return get_client().info().get("Name")
    return None
Пример #4
0
def get_hostname():
    """Return the `Name` param from `docker info` to use as the hostname"""
    from config import get_confd_path, check_yaml, PathNotFound

    confd_path = ''

    try:
        confd_path = get_confd_path()
    except PathNotFound:
        log.error(
            "Couldn't find the check configuration folder, not using the docker hostname."
        )
        return None

    conf_path = os.path.join(confd_path, '%s.yaml' % CHECK_NAME)
    if not os.path.exists(conf_path):
        default_conf_path = os.path.join(confd_path,
                                         '%s.yaml.default' % CHECK_NAME)
        if not os.path.exists(default_conf_path):
            log.error(
                "Couldn't find any configuration file for the docker check."
                " Not using the docker hostname.")
            return None
        else:
            conf_path = default_conf_path

    check_config = check_yaml(conf_path)
    init_config, instances = check_config.get('init_config',
                                              {}), check_config['instances']
    init_config = {} if init_config is None else init_config
    if len(instances) > 0:
        set_docker_settings(init_config, instances[0])
        return get_client().info().get("Name")
    return None
Пример #5
0
def configcheck():
    all_valid = True
    for conf_path in glob.glob(os.path.join(get_confd_path(), "*.yaml")):
        basename = os.path.basename(conf_path)
        try:
            check_yaml(conf_path)
        except Exception as e:
            all_valid = False
            print "%s contains errors:\n    %s" % (basename, e)
        else:
            print "%s is valid" % basename
    if all_valid:
        print "All yaml files passed. You can now run the StackState agent."
        return 0
    else:
        print("Fix the invalid yaml files above in order to start the StackState agent. "
              "A useful external tool for yaml parsing can be found at "
              "http://yaml-online-parser.appspot.com/")
        return 1
Пример #6
0
def set_user_ntp_settings(instance=None):
    global user_ntp_settings
    if instance is None:
        try:
            ntp_check_config = check_yaml(os.path.join(get_confd_path(), "ntp.yaml"))
            instance = ntp_check_config["instances"][0]
        except Exception:
            instance = {}

    user_ntp_settings = instance
Пример #7
0
def configcheck():
    all_valid = True
    for conf_path in glob.glob(os.path.join(get_confd_path(), "*.yaml")):
        basename = os.path.basename(conf_path)
        try:
            check_yaml(conf_path)
        except Exception as e:
            all_valid = False
            print "%s contains errors:\n    %s" % (basename, e)
        else:
            print "%s is valid" % basename
    if all_valid:
        print "All yaml files passed. You can now run the Datadog agent."
        return 0
    else:
        print("Fix the invalid yaml files above in order to start the Datadog agent. "
              "A useful external tool for yaml parsing can be found at "
              "http://yaml-online-parser.appspot.com/")
        return 1
Пример #8
0
def set_user_ntp_settings(instance=None):
    global user_ntp_settings
    if instance is None:
        try:
            ntp_check_config = check_yaml(
                os.path.join(get_confd_path(), 'ntp.yaml'))
            instance = ntp_check_config['instances'][0]
        except Exception:
            instance = {}

    user_ntp_settings = instance
Пример #9
0
def main():
    options, args = get_parsed_args()
    agent_config = get_config(options=options)

    try:
        confd_path = get_confd_path()
        conf_path = os.path.join(confd_path, '%s.yaml' % "net_collector")
        config = check_yaml(conf_path)
        log.debug("Net scan config: %s" % config)
    except PathNotFound as e:
        log.warn(
            "Not starting net_collector_process: path conf.d does not exist %s."
            % e)
        time.sleep(6)
        return 0
    except IOError:
        log.info(
            "Not starting net_collector_process: no valid configuration found")
        time.sleep(6)
        return 0
    else:
        net_collector_process = NetCollectorProcess(agent_config, config)
        net_collector_process.run()
Пример #10
0
def main():
    options, args = get_parsed_args()
    agentConfig = get_config(options=options)
    autorestart = agentConfig.get('autorestart', False)

    COMMANDS = [
        'start',
        'stop',
        'restart',
        'foreground',
        'status',
        'info',
        'check',
        'configcheck',
        'jmx',
    ]

    if len(args) < 1:
        sys.stderr.write("Usage: %s %s\n" % (sys.argv[0], "|".join(COMMANDS)))
        return 2

    command = args[0]
    if command not in COMMANDS:
        sys.stderr.write("Unknown command: %s\n" % command)
        return 3

    pid_file = PidFile('dd-agent')

    if options.clean:
        pid_file.clean()

    agent = Agent(pid_file.get_path(), autorestart)

    if command in START_COMMANDS:
        log.info('Agent version %s' % get_version())

    if 'start' == command:
        log.info('Start daemon')
        agent.start()

    elif 'stop' == command:
        log.info('Stop daemon')
        agent.stop()

    elif 'restart' == command:
        log.info('Restart daemon')
        agent.restart()

    elif 'status' == command:
        agent.status()

    elif 'info' == command:
        return agent.info(verbose=options.verbose)

    elif 'foreground' == command:
        logging.info('Running in foreground')
        if autorestart:
            # Set-up the supervisor callbacks and fork it.
            logging.info('Running Agent with auto-restart ON')

            def child_func():
                agent.run()

            def parent_func():
                agent.start_event = False

            AgentSupervisor.start(parent_func, child_func)
        else:
            # Run in the standard foreground.
            agent.run(config=agentConfig)

    elif 'check' == command:
        check_name = args[1]
        try:
            import checks.collector
            # Try the old-style check first
            print getattr(checks.collector, check_name)(log).check(agentConfig)
        except Exception:
            # If not an old-style check, try checks.d
            checks = load_check_directory(agentConfig)
            for check in checks['initialized_checks']:
                if check.name == check_name:
                    check.run()
                    print check.get_metrics()
                    print check.get_events()
                    if len(args) == 3 and args[2] == 'check_rate':
                        print "Running 2nd iteration to capture rate metrics"
                        time.sleep(1)
                        check.run()
                        print check.get_metrics()
                        print check.get_events()

    elif 'configcheck' == command or 'configtest' == command:
        osname = get_os()
        all_valid = True
        for conf_path in glob.glob(
                os.path.join(get_confd_path(osname), "*.yaml")):
            basename = os.path.basename(conf_path)
            try:
                check_yaml(conf_path)
            except Exception, e:
                all_valid = False
                print "%s contains errors:\n    %s" % (basename, e)
            else:
                print "%s is valid" % basename
        if all_valid:
            print "All yaml files passed. You can now run the Datadog agent."
            return 0
        else:
            print(
                "Fix the invalid yaml files above in order to start the Datadog agent. "
                "A useful external tool for yaml parsing can be found at "
                "http://yaml-online-parser.appspot.com/")
            return 1
Пример #11
0
def main():
    options, args = get_parsed_args()
    agentConfig = get_config(options=options)
    autorestart = agentConfig.get('autorestart', False)
    hostname = get_hostname(agentConfig)

    COMMANDS = [
        'start',
        'stop',
        'restart',
        'foreground',
        'status',
        'info',
        'check',
        'configcheck',
        'jmx',
    ]

    if len(args) < 1:
        sys.stderr.write("Usage: %s %s\n" % (sys.argv[0], "|".join(COMMANDS)))
        return 2

    command = args[0]
    if command not in COMMANDS:
        sys.stderr.write("Unknown command: %s\n" % command)
        return 3

    pid_file = PidFile('dd-agent')

    if options.clean:
        pid_file.clean()

    agent = Agent(pid_file.get_path(), autorestart)

    if command in START_COMMANDS:
        log.info('Agent version %s' % get_version())

    if 'start' == command:
        log.info('Start daemon')
        agent.start()

    elif 'stop' == command:
        log.info('Stop daemon')
        agent.stop()

    elif 'restart' == command:
        log.info('Restart daemon')
        agent.restart()

    elif 'status' == command:
        agent.status()

    elif 'info' == command:
        return agent.info(verbose=options.verbose)

    elif 'foreground' == command:
        logging.info('Running in foreground')
        if autorestart:
            # Set-up the supervisor callbacks and fork it.
            logging.info('Running Agent with auto-restart ON')
            def child_func(): agent.run()
            def parent_func(): agent.start_event = False
            AgentSupervisor.start(parent_func, child_func)
        else:
            # Run in the standard foreground.
            agent.run(config=agentConfig)

    elif 'check' == command:
        check_name = args[1]
        try:
            import checks.collector
            # Try the old-style check first
            print getattr(checks.collector, check_name)(log).check(agentConfig)
        except Exception:
            # If not an old-style check, try checks.d
            checks = load_check_directory(agentConfig, hostname)
            for check in checks['initialized_checks']:
                if check.name == check_name:
                    check.run()
                    print check.get_metrics()
                    print check.get_events()
                    if len(args) == 3 and args[2] == 'check_rate':
                        print "Running 2nd iteration to capture rate metrics"
                        time.sleep(1)
                        check.run()
                        print check.get_metrics()
                        print check.get_events()

    elif 'configcheck' == command or 'configtest' == command:
        osname = get_os()
        all_valid = True
        for conf_path in glob.glob(os.path.join(get_confd_path(osname), "*.yaml")):
            basename = os.path.basename(conf_path)
            try:
                check_yaml(conf_path)
            except Exception, e:
                all_valid = False
                print "%s contains errors:\n    %s" % (basename, e)
            else:
                print "%s is valid" % basename
        if all_valid:
            print "All yaml files passed. You can now run the Datadog agent."
            return 0
        else:
            print("Fix the invalid yaml files above in order to start the Datadog agent. "
                    "A useful external tool for yaml parsing can be found at "
                    "http://yaml-online-parser.appspot.com/")
            return 1