Esempio n. 1
0
def render_dashboard_progress():
    valid_integrations = sorted(get_valid_integrations())
    total_integrations = len(valid_integrations)
    integrations_with_dashboard = 0

    lines = [
        '## Dashboards',
        '',
        '!!! note',
        '    This is not representative of _all_ dashboards, as many exist in legacy locations.',
        '',
        None,
        '',
        '??? check "Completed"',
    ]

    for integration in valid_integrations:
        dashboards_path = os.path.join(get_root(), integration, 'assets',
                                       'dashboards')
        if os.path.isdir(dashboards_path) and len(
                os.listdir(dashboards_path)) > 0:
            integrations_with_dashboard += 1
            status = 'X'
        else:
            status = ' '

        lines.append(f'    - [{status}] {integration}')

    percent = integrations_with_dashboard / total_integrations * 100
    formatted_percent = f'{percent:.2f}'
    lines[5] = f'[={formatted_percent}% "{formatted_percent}%"]'
    return lines
def setup_route():
    # We want to change the path before and after running each individual test
    root = Path(os.path.realpath(
        __file__)).parent.parent.parent.parent.parent.absolute()
    current_root = get_root()
    set_root(str(root))
    yield root
    set_root(current_root)
Esempio n. 3
0
def validate_readme(integration, repo, manifest, display_queue, files_failed,
                    readme_counter):
    readme_path = get_readme_file(integration)
    read_readme = read_readme_file(integration)
    if not read_readme.isascii():
        display_queue.append(lambda **kwargs: echo_failure(
            "     readme contains non-ascii character(s)", **kwargs))
    html = markdown.markdown(read_readme)
    soup = BeautifulSoup(html, features="html.parser")
    readme_counter.add(readme_path)

    # Check all required headers are present
    h2s = [h2.text for h2 in soup.find_all("h2")]
    if "Overview" not in h2s or "Setup" not in h2s:
        files_failed[readme_path] = True
        display_queue.append(lambda **kwargs: echo_failure(
            "     readme is missing either an Overview or Setup H2 (##) section",
            **kwargs))

    if "Support" not in h2s and manifest.get("support") == "partner":
        files_failed[readme_path] = True
        display_queue.append(lambda **kwargs: echo_failure(
            "     readme is missing a Support H2 (##) section", **kwargs))

    # Check all referenced images are in the `images` folder and that
    # they use the `raw.githubusercontent` format or relative paths to the `images` folder
    allow_relative = False
    if manifest.get("support") == "partner":
        allow_relative = True
    img_srcs = [img.attrs.get("src") for img in soup.find_all("img")]
    for img_src in img_srcs:
        image_name = os.path.split(img_src)[-1]
        file_path = os.path.join(get_root(), integration, "images", image_name)
        if img_src.startswith("https://raw.githubusercontent") or (
                img_src.startswith("images/") and allow_relative):
            if not os.path.exists(file_path):
                files_failed[readme_path] = True
                display_queue.append(
                    lambda img_src=img_src, **kwargs: echo_failure(
                        f"     image: {img_src} is linked in its readme but does not exist",
                        **kwargs))
        else:
            error_msg = (
                f"     All images must be checked into the repo under the `{integration}/images` folder. "
                f"This image path must be in the form: "
                f"https://raw.githubusercontent.com/DataDog/{repo}/master/{integration}/images/<IMAGE_NAME>"
            )
            if allow_relative:
                error_msg += "or be a relative path to the `images/` folder (without a `/` prefix)."
            error_msg += f" Image currently is: {img_src}"

            display_queue.append(lambda repo=repo, integration=integration, **
                                 kwargs: echo_failure(error_msg, **kwargs))
def test_manifest_ok():
    manifest = {
        "categories": ["os & system", "log collection"],
        "creates_events": False,
        "description": "Collect and graph Microsoft Active Directory metrics",
        "display_name": "Active Directory",
        "guid": "ba667ff3-cf6a-458c-aa4b-1172f33de562",
        "is_public": True,
        "maintainer": "*****@*****.**",
        "manifest_version": "1.0.0",
        "metric_prefix": "active_directory.",
        "metric_to_check": "active_directory.dra.inbound.objects.persec",
        "name": "active_directory",
        "public_title": "Datadog-Active Directory Integration",
        "short_description":
        "Collect and graph Microsoft Active Directory metrics",
        "support": "core",
        "supported_os": ["windows"],
        "type": "check",
        "integration_id": "active-directory",
        "assets": {
            "configuration": {
                "spec": "assets/configuration/spec.yaml"
            },
            "monitors": {},
            "dashboards": {
                "Active Directory": "assets/dashboards/active_directory.json"
            },
            "service_checks": "assets/service_checks.json",
            "logs": {
                "source": "ruby"
            },
            "metrics_metadata": "metadata.csv",
        },
    }
    root = Path(os.path.realpath(
        __file__)).parent.parent.parent.parent.parent.absolute()
    current_root = get_root()
    set_root(str(root))
    try:
        validators = get_all_validators(False, False)
        for validator in validators:
            validator.validate('active_directory', manifest, False)
            assert not validator.result.failed, validator.result
            assert not validator.result.fixed
    finally:
        set_root(current_root)
Esempio n. 5
0
def patch(lines):
    """This ensures the root directory is set for subsequent scripts using ddev tooling."""
    if not get_root():
        set_root(os.getcwd())
 def __init__(self, *args, **kwargs):
     super(ManifestVersionValidator, self).__init__(*args, **kwargs)
     self.root = get_root()
Esempio n. 7
0
def test_get_root():
    assert get_root() == ''
    set_root('foo')
    assert get_root() == 'foo'
Esempio n. 8
0
def test_get_root():
    assert get_root() == ''
    set_root('my-root')
    assert get_root() == 'my-root'

    set_root('')  # cleanup