4
0

sosreport.go 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. package installationinfo
  2. import (
  3. "fmt"
  4. "time"
  5. config "github.com/OliveTin/OliveTin/internal/config"
  6. "gopkg.in/yaml.v3"
  7. )
  8. var (
  9. Config *config.Config
  10. )
  11. type sosReportConfig struct {
  12. CountOfActions int
  13. CountOfDashboards int
  14. LogLevel string
  15. ListenAddressSingleHTTPFrontend string
  16. ListenAddressWebUI string
  17. ListenAddressRestActions string
  18. Timezone string
  19. TimeNow string
  20. ConfigDirectory string
  21. WebuiDirectory string
  22. }
  23. func configToSosreport(cfg *config.Config) *sosReportConfig {
  24. return &sosReportConfig{
  25. CountOfActions: len(cfg.Actions),
  26. CountOfDashboards: len(cfg.Dashboards),
  27. LogLevel: cfg.LogLevel,
  28. ListenAddressSingleHTTPFrontend: cfg.ListenAddressSingleHTTPFrontend,
  29. ListenAddressWebUI: cfg.ListenAddressWebUI,
  30. ListenAddressRestActions: cfg.ListenAddressRestActions,
  31. Timezone: time.Now().Location().String(),
  32. TimeNow: time.Now().String(),
  33. ConfigDirectory: cfg.GetDir(),
  34. WebuiDirectory: cfg.WebUIDir,
  35. }
  36. }
  37. func GetSosReport(redactVersion bool) string {
  38. ret := ""
  39. ret += "### SOSREPORT START (copy all text to SOSREPORT END)\n"
  40. buildForReport := *Build
  41. if redactVersion {
  42. buildForReport.Version = "[redacted]"
  43. }
  44. out, _ := yaml.Marshal(&buildForReport)
  45. ret += fmt.Sprintf("# Build: \n%+v\n", string(out))
  46. runtimeForReport := *Runtime
  47. if redactVersion {
  48. runtimeForReport.AvailableVersion = "[redacted]"
  49. }
  50. out, _ = yaml.Marshal(&runtimeForReport)
  51. ret += fmt.Sprintf("# Runtime:\n%+v\n", string(out))
  52. out, _ = yaml.Marshal(configToSosreport(Config))
  53. ret += fmt.Sprintf("# Config:\n%+v\n", string(out))
  54. ret += "### SOSREPORT END (copy all text from SOSREPORT START)\n"
  55. return ret
  56. }