From 20aff38458b946486b52abc8acc5af35e16044ef Mon Sep 17 00:00:00 2001 From: Simon Larsen Date: Fri, 3 Jan 2025 15:08:57 +0000 Subject: [PATCH] feat: enhance agent configuration logging and save proxy URL --- InfrastructureAgent/agent.go | 2 +- InfrastructureAgent/config.go | 3 +++ InfrastructureAgent/main.go | 8 +++++++- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/InfrastructureAgent/agent.go b/InfrastructureAgent/agent.go index 3913c5637b..5e6e0174e5 100644 --- a/InfrastructureAgent/agent.go +++ b/InfrastructureAgent/agent.go @@ -32,7 +32,7 @@ func NewAgent(secretKey string, oneuptimeUrl string, proxyUrl string) *Agent { OneUptimeURL: oneuptimeUrl, ProxyURL: proxyUrl, } - utils.SetDefaultLogger() + slog.Info("Starting agent...") slog.Info("Agent configuration:") slog.Info("Secret key: " + ag.SecretKey) diff --git a/InfrastructureAgent/config.go b/InfrastructureAgent/config.go index 00f4948a74..6df9683165 100644 --- a/InfrastructureAgent/config.go +++ b/InfrastructureAgent/config.go @@ -39,6 +39,7 @@ func (c *ConfigFile) loadConfig() error { } c.SecretKey = cfg.SecretKey c.OneUptimeURL = cfg.OneUptimeURL + c.ProxyURL = cfg.ProxyURL return nil } @@ -63,6 +64,7 @@ func (c *ConfigFile) save(secretKey string, oneuptimeUrl string, proxyUrl string // Open the file with os.Create, which truncates the file if it already exists, // and creates it if it doesn't. + slog.Info("Saving configuration to file to path: " + c.configPath()) file, err := os.Create(c.configPath()) if err != nil { return err @@ -72,6 +74,7 @@ func (c *ConfigFile) save(secretKey string, oneuptimeUrl string, proxyUrl string // which will write the map to the file in JSON format. encoder := json.NewEncoder(file) encoder.SetIndent("", " ") // Optional: makes the output more readable + slog.Info("Configuration File Saved") return encoder.Encode(config.Data()) } diff --git a/InfrastructureAgent/main.go b/InfrastructureAgent/main.go index 1653105464..f76bd46471 100644 --- a/InfrastructureAgent/main.go +++ b/InfrastructureAgent/main.go @@ -115,6 +115,12 @@ func main() { slog.Error("The --secret-key and --oneuptime-url flags are required for the 'configure' command") os.Exit(2) } + + slog.Info("Configuring service...") + slog.Info("Secret key: " + *secretKey) + slog.Info("OneUptime URL: " + *oneuptimeURL) + slog.Info("Proxy URL: " + *proxyURL) + // save configuration err = prg.config.save(prg.config.SecretKey, prg.config.OneUptimeURL, prg.config.ProxyURL) @@ -124,7 +130,7 @@ func main() { } // Install the service if err := s.Install(); err != nil { - slog.Error("Failed to configure service: ", err) + slog.Error("Failed to configure service. Please consider uninstalling the service by running 'oneuptime-infrastructure-agent uninstall' and run configure again. \n", err) os.Exit(2) } fmt.Println("Service installed. Run the service using 'oneuptime-infrastructure-agent start'")