mirror of
https://github.com/wearepixel/pulsewise-collector.git
synced 2026-11-14 22:12:01 +00:00
feat: add 'dump' command to print payload JSON without sending
This commit is contained in:
@@ -184,6 +184,9 @@ func main() {
|
||||
case "uninstall":
|
||||
runUninstallCommand()
|
||||
return
|
||||
case "dump":
|
||||
runDumpCommand()
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
@@ -277,6 +280,29 @@ func runUpdateCommand() {
|
||||
fmt.Printf(" Successfully updated to %sv%s%s.\n\n", ansiCyan, latest, ansiReset)
|
||||
}
|
||||
|
||||
func runDumpCommand() {
|
||||
if os.Getuid() != 0 {
|
||||
reexecWithSudo()
|
||||
return
|
||||
}
|
||||
|
||||
config := loadConfig()
|
||||
|
||||
metrics, err := collectMetrics(config)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "%sError collecting metrics: %v%s\n", ansiRed, err, ansiReset)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
out, err := json.MarshalIndent(metrics, "", " ")
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "%sError marshalling metrics: %v%s\n", ansiRed, err, ansiReset)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
fmt.Println(string(out))
|
||||
}
|
||||
|
||||
func reexecWithSudo() {
|
||||
self, err := os.Executable()
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user