From 111b192e648259d9e4645cf674e7d6b354ab4379 Mon Sep 17 00:00:00 2001 From: Kylian Serrania Date: Wed, 24 Mar 2021 14:45:12 +0100 Subject: [PATCH] Add NPM support for Windows (#335) Redo of #326, with fixes to avoid undefined variable problems on Windows. Co-authored-by: Derek Brown Co-authored-by: Lee Avital Co-authored-by: ruthnaebeck <19349244+ruthnaebeck@users.noreply.github.com> Co-authored-by: Albert Vaca Cintora --- README.md | 9 ++++++--- defaults/main.yml | 7 ++++++- tasks/agent-win.yml | 6 ++++++ tasks/pkg-windows-opts.yml | 8 +++++++- tasks/pkg-windows.yml | 8 ++++++++ templates/system-probe.yaml.j2 | 14 ++++++++++++++ 6 files changed, 47 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index d2c88414..0e956c89 100644 --- a/README.md +++ b/README.md @@ -163,9 +163,11 @@ The following variables are available for live processes: #### System probe -The [Network Performance Monitoring][7] (NPM) system probe is configured under the `system_probe_config` variable. Any variables nested underneath are written to the `system-probe.yaml`. +The system probe is configured under the `network_config` variable. Any variables nested underneath are written to the `system-probe.yaml`. -**Note**: The system probe only works on Linux with the Agent v6+. +[Network Performance Monitoring][7] (NPM) is configured under the `network_config` variable. Any variables nested underneath are written to the `system-probe.yaml`, in the `network_config` section. + +**Note**: The system probe works on Linux with Agent v6+. NPM is supported on Windows with Agent v6.27+ and v7.27+. #### Example configuration @@ -176,8 +178,9 @@ datadog_config: scrub_args: true custom_sensitive_words: ['consul_token','dd_api_key'] system_probe_config: - enabled: true sysprobe_socket: /opt/datadog-agent/run/sysprobe.sock +network_config: + enabled: true ``` Once modification is complete, follow the steps below: diff --git a/defaults/main.yml b/defaults/main.yml index 66cb4fb6..99fc1445 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -1,12 +1,17 @@ --- role_version: 4.7.1 +# default system-probe.yaml options system_probe_config: enabled: false +network_config: + enabled: false + +# define if the datadog-agent services should be enabled datadog_enabled: yes -# default datadog.conf options +# default datadog.conf / datadog.yaml options datadog_config: {} # default checks enabled diff --git a/tasks/agent-win.yml b/tasks/agent-win.yml index 133e448b..359c3e7a 100644 --- a/tasks/agent-win.yml +++ b/tasks/agent-win.yml @@ -50,6 +50,12 @@ with_items: "{{ datadog_checks|list }}" notify: restart datadog-agent-win +- name: Create system-probe configuration file + win_template: + src: system-probe.yaml.j2 + dest: "{{ datadog_windows_config_root }}\\system-probe.yaml" + notify: restart datadog-agent-win + - name: Ensure datadog-agent is running win_service: name: datadogagent diff --git a/tasks/pkg-windows-opts.yml b/tasks/pkg-windows-opts.yml index cbf7773f..deeb8b93 100644 --- a/tasks/pkg-windows-opts.yml +++ b/tasks/pkg-windows-opts.yml @@ -85,4 +85,10 @@ - name: Set Test set_fact: - win_install_args: "{{ win_install_args }}" \ No newline at end of file + win_install_args: "{{ win_install_args }}" + +# Add the installation arguments to install Windows NPM. +- name: Set Windows NPM flag + set_fact: + win_install_args: "{{ win_install_args }} ADDLOCAL=MainApplication,NPM" + when: datadog_sysprobe_enabled diff --git a/tasks/pkg-windows.yml b/tasks/pkg-windows.yml index ed88679b..167a65ba 100644 --- a/tasks/pkg-windows.yml +++ b/tasks/pkg-windows.yml @@ -55,6 +55,10 @@ var: dd_download_url when: not datadog_skip_windows_install +## must be prior to `pkg-windows-opts.yml`, because the variable is used inside +- name: Set windows NPM installed + set_fact: + datadog_sysprobe_enabled: "{{ network_config is defined and 'enabled' in (network_config | default({}, true)) and network_config['enabled'] }}" - include_tasks: pkg-windows-opts.yml - name: pre-Delete temporary msi @@ -87,6 +91,10 @@ propagation: None when: datadog_windows_program_files_dir | length > 0 +- name: Show installation flags + debug: + var: win_install_args + - name: Install downloaded agent win_package: path: "{{ download_msi_result.dest }}" diff --git a/templates/system-probe.yaml.j2 b/templates/system-probe.yaml.j2 index 50138b2b..917d6523 100644 --- a/templates/system-probe.yaml.j2 +++ b/templates/system-probe.yaml.j2 @@ -13,3 +13,17 @@ system_probe_config: {{ system_probe_config | to_nice_yaml }} {% endfilter %} {% endif %} + +{% if network_config is defined and network_config | default({}, true) | length > 0 -%} +network_config: +{# The "first" option is only supported by jinja 2.10+ + which is not present on older systems (CentOS 7, Debian 8, etc.) + Using the equivalent option "indentfirst" is supported for + all jinja 2 versions up to v2.10. + TODO: when future versions of Jinja are released, check that + indentfirst is still supported. + #} +{% filter indent(width=2, indentfirst=True) %} +{{ network_config | to_nice_yaml }} +{% endfilter %} +{% endif %}