The smallest watchdog on earth. Tiny, monitoring-plugins compatible monitoring with a status page. https://cloud.docker.com/repository/docker/momar/chihuahua/general
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

print.go 944B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package chihuahua
  2. import (
  3. "fmt"
  4. "strconv"
  5. "strings"
  6. "codeberg.org/momar/chihuahua/types"
  7. )
  8. func Print(servers map[string]*types.Server) {
  9. first := true
  10. for serverName, server := range servers {
  11. if first {
  12. first = false
  13. } else {
  14. fmt.Print("\n")
  15. }
  16. fmt.Printf("\033[1m%s\033[0m\n", serverName)
  17. for checkName, check := range server.Checks {
  18. color := "\033[1;47m"
  19. switch check.Status {
  20. case types.StatusOk:
  21. color = "\033[1;42m"
  22. case types.StatusWarning:
  23. color = "\033[1;43m"
  24. case types.StatusCritical:
  25. color = "\033[1;41m"
  26. }
  27. info := check.Details
  28. if check.Error != "" {
  29. if info == "" {
  30. info = "\033[31m" + check.Error + "\033[0m"
  31. } else {
  32. info += "\n\033[31m" + check.Error + "\033[0m"
  33. }
  34. }
  35. info = strings.ReplaceAll(info, "\n", fmt.Sprintf("\n%"+strconv.Itoa(3+len(checkName))+"s", ""))
  36. fmt.Printf("%s %s \033[0m %s\n", color, checkName, info)
  37. }
  38. }
  39. }