feat: enhance agent configuration logging and save proxy URL

This commit is contained in:
Simon Larsen
2025-01-03 15:08:57 +00:00
parent 16a1051280
commit 20aff38458
3 changed files with 11 additions and 2 deletions

View File

@@ -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)

View File

@@ -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())
}

View File

@@ -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'")