From 4a00f258da6c0123fa30aa7656d9ed349c771109 Mon Sep 17 00:00:00 2001 From: "Lee E. Hinman" Date: Thu, 19 Dec 2024 09:41:14 -0600 Subject: [PATCH] Add logging to EventLog for error, install, uninstall --- ...Logging-to-install,-uninstall,-enroll.yaml | 32 +++++++++++++++++++ internal/pkg/agent/cmd/enroll.go | 1 + internal/pkg/agent/cmd/install.go | 1 + internal/pkg/agent/cmd/uninstall.go | 1 + 4 files changed, 35 insertions(+) create mode 100644 changelog/fragments/1734626964-Windows-add-Event-Logging-to-install,-uninstall,-enroll.yaml diff --git a/changelog/fragments/1734626964-Windows-add-Event-Logging-to-install,-uninstall,-enroll.yaml b/changelog/fragments/1734626964-Windows-add-Event-Logging-to-install,-uninstall,-enroll.yaml new file mode 100644 index 00000000000..b64393d748f --- /dev/null +++ b/changelog/fragments/1734626964-Windows-add-Event-Logging-to-install,-uninstall,-enroll.yaml @@ -0,0 +1,32 @@ +# Kind can be one of: +# - breaking-change: a change to previously-documented behavior +# - deprecation: functionality that is being removed in a later release +# - bug-fix: fixes a problem in a previous version +# - enhancement: extends functionality but does not break or fix existing behavior +# - feature: new functionality +# - known-issue: problems that we are aware of in a given version +# - security: impacts on the security of a product or a user’s deployment. +# - upgrade: important information for someone upgrading from a prior version +# - other: does not fit into any of the other categories +kind: enhancement + +# Change summary; a 80ish characters long description of the change. +summary: Windows add Event Logging to install, uninstall, enroll failures + +# Long description; in case the summary is not enough to describe the change +# this field accommodate a description without length limits. +# NOTE: This field will be rendered only for breaking-change and known-issue kinds at the moment. +#description: + +# Affected component; a word indicating the component this changeset affects. +component: elastic-agent + +# PR URL; optional; the PR number that added the changeset. +# If not present is automatically filled by the tooling finding the PR where this changelog fragment has been added. +# NOTE: the tooling supports backports, so it's able to fill the original PR number instead of the backport PR number. +# Please provide it if you are adding a fragment for a different PR. +pr: https://github.com/elastic/elastic-agent/6410 + +# Issue URL; optional; the GitHub issue related to this changeset (either closes or is part of). +# If not present is automatically filled by the tooling with the issue linked to the PR number. +issue: https://github.com/elastic/elastic-agent/6338 diff --git a/internal/pkg/agent/cmd/enroll.go b/internal/pkg/agent/cmd/enroll.go index b1f82e6989e..534f89503f6 100644 --- a/internal/pkg/agent/cmd/enroll.go +++ b/internal/pkg/agent/cmd/enroll.go @@ -42,6 +42,7 @@ func newEnrollCommandWithArgs(_ []string, streams *cli.IOStreams) *cobra.Command Run: func(c *cobra.Command, args []string) { if err := enroll(streams, c); err != nil { fmt.Fprintf(streams.Err, "Error: %v\n%s\n", err, troubleshootMessage()) + logExternal(fmt.Sprintf("%s enroll failed: %s", paths.BinaryName, err)) os.Exit(1) } }, diff --git a/internal/pkg/agent/cmd/install.go b/internal/pkg/agent/cmd/install.go index b6f8447b779..8d70c2bd3c0 100644 --- a/internal/pkg/agent/cmd/install.go +++ b/internal/pkg/agent/cmd/install.go @@ -47,6 +47,7 @@ would like the Agent to operate. Run: func(c *cobra.Command, _ []string) { if err := installCmd(streams, c); err != nil { fmt.Fprintf(streams.Err, "Error: %v\n%s\n", err, troubleshootMessage()) + logExternal(fmt.Sprintf("%s install failed: %s", paths.BinaryName, err)) os.Exit(1) } }, diff --git a/internal/pkg/agent/cmd/uninstall.go b/internal/pkg/agent/cmd/uninstall.go index 0fb69157082..0a5c39b2467 100644 --- a/internal/pkg/agent/cmd/uninstall.go +++ b/internal/pkg/agent/cmd/uninstall.go @@ -29,6 +29,7 @@ Unless -f is used this command will ask confirmation before performing removal. Run: func(c *cobra.Command, _ []string) { if err := uninstallCmd(streams, c); err != nil { fmt.Fprintf(streams.Err, "Error: %v\n%s\n", err, troubleshootMessage()) + logExternal(fmt.Sprintf("%s uninstall failed: %s", paths.BinaryName, err)) os.Exit(1) } },