From 295a14b37b46e95559c98ce433ba552cf21268a0 Mon Sep 17 00:00:00 2001 From: Julien Lebot Date: Fri, 22 Mar 2024 16:30:14 +0100 Subject: [PATCH] Add `winregistry` module to the check subcommand (#23303) * Add `winregistry` and `agentcrashdetect` modules to the check subcommand * [skip-ci] Add release note * Remove the crash detect module * Update release notes * Renamed release note * Update command_not_windows.go * Update command_not_windows.go * Rename not_windows into notwindows * Ensure unit test pass by creating the config --- pkg/cli/subcommands/check/command.go | 2 ++ .../subcommands/check/command_notwindows.go | 14 +++++++++++++ pkg/cli/subcommands/check/command_test.go | 11 +++++++++- pkg/cli/subcommands/check/command_windows.go | 21 +++++++++++++++++++ ...the-check-subcommand-45abb1b101f11316.yaml | 4 ++++ 5 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 pkg/cli/subcommands/check/command_notwindows.go create mode 100644 pkg/cli/subcommands/check/command_windows.go create mode 100644 releasenotes/notes/add-winregistry-module-to-the-check-subcommand-45abb1b101f11316.yaml diff --git a/pkg/cli/subcommands/check/command.go b/pkg/cli/subcommands/check/command.go index a1ca0423e8187..b4ebdfa7e20e0 100644 --- a/pkg/cli/subcommands/check/command.go +++ b/pkg/cli/subcommands/check/command.go @@ -215,6 +215,8 @@ func MakeCommand(globalParamsGetter func() GlobalParams) *cobra.Command { fx.Provide(func() packagesigning.Component { return nil }), fx.Provide(func() optional.Option[rcservice.Component] { return optional.NewNoneOption[rcservice.Component]() }), fx.Provide(func() optional.Option[rcserviceha.Component] { return optional.NewNoneOption[rcserviceha.Component]() }), + + getPlatformModules(), ) }, } diff --git a/pkg/cli/subcommands/check/command_notwindows.go b/pkg/cli/subcommands/check/command_notwindows.go new file mode 100644 index 0000000000000..8d50d865983e3 --- /dev/null +++ b/pkg/cli/subcommands/check/command_notwindows.go @@ -0,0 +1,14 @@ +// Unless explicitly stated otherwise all files in this repository are licensed +// under the Apache License Version 2.0. +// This product includes software developed at Datadog (https://www.datadoghq.com/). +// Copyright 2016-present Datadog, Inc. + +//go:build !windows + +package check + +import "go.uber.org/fx" + +func getPlatformModules() fx.Option { + return fx.Options() +} diff --git a/pkg/cli/subcommands/check/command_test.go b/pkg/cli/subcommands/check/command_test.go index 9a23ba21071d4..73ab52c29a656 100644 --- a/pkg/cli/subcommands/check/command_test.go +++ b/pkg/cli/subcommands/check/command_test.go @@ -6,6 +6,8 @@ package check import ( + "os" + "path" "testing" "github.com/spf13/cobra" @@ -19,7 +21,14 @@ import ( func TestCommand(t *testing.T) { commands := []*cobra.Command{ MakeCommand(func() GlobalParams { - return GlobalParams{} + // the config needs an existing config file when initializing + config := path.Join(t.TempDir(), "datadog.yaml") + err := os.WriteFile(config, []byte("hostname: test"), 0644) + require.NoError(t, err) + + return GlobalParams{ + ConfFilePath: config, + } }), } diff --git a/pkg/cli/subcommands/check/command_windows.go b/pkg/cli/subcommands/check/command_windows.go new file mode 100644 index 0000000000000..fa36422ca1848 --- /dev/null +++ b/pkg/cli/subcommands/check/command_windows.go @@ -0,0 +1,21 @@ +// Unless explicitly stated otherwise all files in this repository are licensed +// under the Apache License Version 2.0. +// This product includes software developed at Datadog (https://www.datadoghq.com/). +// Copyright 2016-present Datadog, Inc. + +//go:build windows + +package check + +import ( + "github.com/DataDog/datadog-agent/comp/checks/winregistry" + winregistryimpl "github.com/DataDog/datadog-agent/comp/checks/winregistry/impl" + "go.uber.org/fx" +) + +func getPlatformModules() fx.Option { + return fx.Options( + winregistryimpl.Module(), + fx.Invoke(func(_ winregistry.Component) {}), + ) +} diff --git a/releasenotes/notes/add-winregistry-module-to-the-check-subcommand-45abb1b101f11316.yaml b/releasenotes/notes/add-winregistry-module-to-the-check-subcommand-45abb1b101f11316.yaml new file mode 100644 index 0000000000000..6f4f084c2a255 --- /dev/null +++ b/releasenotes/notes/add-winregistry-module-to-the-check-subcommand-45abb1b101f11316.yaml @@ -0,0 +1,4 @@ +--- +fixes: + - | + The `windows_registry` check can be run with the `check` sub-command.