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.

healthcheck.go 1.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. // Command healthcheck reads a file containing a UNIX UTC timestamp and exits
  2. // nonzero after printing a message to stderr if the allotted time has elapsed
  3. // since a value was last recorded. Config value irc.health_period specifies
  4. // the max allotted time plus a small cushion for lag. It defaults to fifteen
  5. // minutes, which is go-ircevent's default PING frequency (as of
  6. // github.com/thoj/go-ircevent@v0.0.0-20210723090443-73e444401d64). Optional
  7. // config item irc.health_file designates the path to the timestamp file. If
  8. // unset, the program says so (to stderr) and exits zero.
  9. package main
  10. import (
  11. "log"
  12. "time"
  13. "github.com/irccloud/irccat/util"
  14. "github.com/spf13/viper"
  15. )
  16. var lagInterval = 10 * time.Second // for testing
  17. var defaultPeriod = 15 * time.Minute
  18. func main() {
  19. viper.SetConfigName("irccat")
  20. viper.AddConfigPath("/etc")
  21. viper.AddConfigPath(".")
  22. viper.SetDefault("irc.health_period", defaultPeriod)
  23. if err := viper.ReadInConfig(); err != nil {
  24. log.Fatalln("Error reading config file. Exiting.")
  25. }
  26. healthFile := viper.GetString("irc.health_file")
  27. if healthFile == "" {
  28. log.Println("Config option irc.health_file unset; exiting.")
  29. return
  30. }
  31. freq := lagInterval + viper.GetDuration("irc.health_period")
  32. if err := util.CheckTimestamp(healthFile, freq); err != nil {
  33. log.Fatalln(err.Error())
  34. }
  35. }