Documentation
¶
Index ¶
- Constants
- Variables
- func CheckDefault(value string, defaultValue string) string
- func FormatOutput(outputFormat string, textTemplate string, output interface{}) (string, error)
- func FormatTemplate(tmpl string, intr any) (string, error)
- func GetOutputFormat(req *http.Request) string
- func HandlerConfig(w http.ResponseWriter, req *http.Request)
- func HandlerHealthz(w http.ResponseWriter, req *http.Request)
- func HandlerHome(w http.ResponseWriter, req *http.Request)
- func HandlerPing(w http.ResponseWriter, req *http.Request)
- func HandlerPingFail(w http.ResponseWriter, req *http.Request)
- func HandlerPingHelp(w http.ResponseWriter, req *http.Request)
- func HandlerStatus(w http.ResponseWriter, req *http.Request)
- func NewRouter() *mux.Router
- func NotificationFunc(heartbeatName string, status Status) func()
- func ProcessServiceSettings() error
- func ReadConfigFile(configPath string, init bool) error
- func ResetTimerIfRunning(previousHeartbeats *[]Heartbeat)
- func WriteOutput(w http.ResponseWriter, statusCode int, outputFormat string, output interface{}, ...)
- type Ago
- type Config
- type Defaults
- type FormatPeriod
- type Heartbeat
- type HeartbeatStatus
- type Heartbeats
- type Metrics
- type Notification
- type Notifications
- type ResponseStatus
- type Server
- type Status
- type Timer
Constants ¶
Variables ¶
var CalculateAgo = Ago{ PastPrefix: "", PastSuffix: " ago", FuturePrefix: "in ", FutureSuffix: "", Periods: []FormatPeriod{ {time.Second, "about a second", "%d seconds"}, {time.Minute, "about a minute", "%d minutes"}, {time.Hour, "about an hour", "%d hours"}, {Day, "one day", "%d days"}, {Month, "one month", "%d months"}, {Year, "one year", "%d years"}, }, Zero: "about a second", Max: 73 * time.Hour, DefaultLayout: "2006-01-02", }
Predefined english configuration
Functions ¶
func CheckDefault ¶
CheckDefault checks if value is empty and returns default value
func FormatOutput ¶
FormatOutput formats the output according to outputFormat
func FormatTemplate ¶
FormatTemplate format template with intr as input
func GetOutputFormat ¶
CheckOutput checks if the output format is supported
func HandlerConfig ¶
func HandlerConfig(w http.ResponseWriter, req *http.Request)
HandlerConfig is the handler for the /config endpoint
func HandlerHealthz ¶
func HandlerHealthz(w http.ResponseWriter, req *http.Request)
HeartbeatsServer is the handler for the /healthz endpoint
func HandlerHome ¶
func HandlerHome(w http.ResponseWriter, req *http.Request)
HandlerHome is the handler for the / endpoint
func HandlerPing ¶
func HandlerPing(w http.ResponseWriter, req *http.Request)
HandlerPing is the handler for the /ping/<heartbeat> endpoint
func HandlerPingFail ¶ added in v0.2.5
func HandlerPingFail(w http.ResponseWriter, req *http.Request)
HandlerPingFail is the handler for the /ping/<heartbeat>/fail endpoint
func HandlerPingHelp ¶
func HandlerPingHelp(w http.ResponseWriter, req *http.Request)
HandlerPingHelp is the handler for the /ping endpoint
func HandlerStatus ¶
func HandlerStatus(w http.ResponseWriter, req *http.Request)
HandlerState is the handler for the /status endpoint
func NotificationFunc ¶
NotificationFunc returns a function that can be used to send notifications
func ProcessServiceSettings ¶
func ProcessServiceSettings() error
ProcessNotificationSettings checks if all services are valid and can be parsed
func ReadConfigFile ¶
ReadConfigFile reads the notifications config file configPath is the path to the config file init is true if the config file is read on startup. this will skip the comparison of the previous config
func ResetTimerIfRunning ¶
func ResetTimerIfRunning(previousHeartbeats *[]Heartbeat)
ResetTimerIfRunning resets existing timers if they are running
func WriteOutput ¶
func WriteOutput(w http.ResponseWriter, statusCode int, outputFormat string, output interface{}, textTemplate string)
WriteOutput writes the output to the response writer
- w is the response writer - statusCode is the HTTP status code - outputFormat is the format of the output (json, yaml, yml, txt, text) - output is the data to render the template with - textTmpl is the template to use for the text output
Types ¶
type Ago ¶
type Ago struct {
PastPrefix string
PastSuffix string
FuturePrefix string
FutureSuffix string
Periods []FormatPeriod
Zero string
Max time.Duration // Maximum duration for using the special formatting.
//DefaultLayout is used if delta is greater than the minimum of last period
//in Periods and Max. It is the desired representation of the date 2nd of
// January 2006.
DefaultLayout string
}
Config allows the customization of timeago. You may configure string items (language, plurals, ...) and maximum allowed duration value for fuzzy formatting.
func WithMax ¶
WithMax creates an new config with special formatting limited to durations less than max. Values greater than max will be formatted by the standard time package using the defaultLayout.
func (Ago) Format ¶
Format returns a textual representation of the time value formatted according to the layout defined in the Config. The time is compared to time.Now() and is then formatted as a fuzzy timestamp (eg. "4 days ago")
func (Ago) FormatReference ¶
FormatReference is the same as Format, but the reference has to be defined by the caller
type Config ¶
type Config struct {
Path string `mapstructure:"path"`
PrintVersion bool `mapstructure:"printVersion"`
Logging string `mapstructure:"logging"`
}
Config config holds general configuration
type Defaults ¶
type Defaults struct {
Subject string `mapstructure:"subject"`
Message string `mapstructure:"message"`
SendResolved *bool `mapstructure:"sendResolved"`
}
Details details holds defaults for notifications
type Heartbeat ¶
type Heartbeat struct {
Name string `mapstructure:"name"`
Description string `mapstructure:"description"`
Interval time.Duration `mapstructure:"interval"`
Grace time.Duration `mapstructure:"grace"`
LastPing time.Time `mapstructure:"lastPing"`
Status string `mapstructure:"status"`
Notifications []string `mapstructure:"notifications"`
IntervalTimer *Timer `mapstructure:"-,omitempty" deepcopier:"skip"`
GraceTimer *Timer `mapstructure:"-,omitempty" deepcopier:"skip"`
}
Heartbeat is a struct for a heartbeat
func (*Heartbeat) GotPing ¶
func (h *Heartbeat) GotPing()
GotPing starts the timer for the heartbeat (heartbeatName)
func (*Heartbeat) GotPingFail ¶ added in v0.2.5
func (h *Heartbeat) GotPingFail()
type HeartbeatStatus ¶
type HeartbeatStatus struct {
Name string `json:"name"`
Status string `json:"status"`
LastPing time.Time `json:"lastPing"`
}
HeartbeatStatus represents a heartbeat status
type Heartbeats ¶ added in v0.3.0
type Heartbeats struct {
Version string `mapstructure:"version"`
Config Config `mapstructure:"config"`
Server Server `mapstructure:"server"`
Heartbeats []Heartbeat `mapstructure:"heartbeats"`
Notifications Notifications `mapstructure:"notifications"`
}
Heartbeats is the main configuration struct
var HeartbeatsServer Heartbeats
func (*Heartbeats) GetHeartbeatByName ¶ added in v0.3.0
func (h *Heartbeats) GetHeartbeatByName(name string) (*Heartbeat, error)
GetHeartbeatByName search heartbeat in HeartbeatsConfig.Heartbeats by name and returns it
func (*Heartbeats) GetServiceByName ¶ added in v0.3.0
func (h *Heartbeats) GetServiceByName(notificationType string) (*Notification, error)
GetServiceByType returns notification settings by type
type Metrics ¶
type Metrics struct {
HeartbeatStatus *prometheus.GaugeVec
TotalHeartbeats *prometheus.CounterVec
}
Metrics holds all prometheus metrics
var PromMetrics Metrics
func NewMetrics ¶
func NewMetrics(reg prometheus.Registerer) *Metrics
NewMetrics registers all prometheus metrics
type Notification ¶ added in v0.3.0
type Notifications ¶
type Notifications struct {
Defaults Defaults `mapstructure:"defaults"`
Services []Notification `mapstructure:"services"`
}
NotifyConfig holds the configuration for the notifications
type ResponseStatus ¶
ResponseStatus represents a response
type Server ¶
type Server struct {
Hostname string `mapstructure:"hostname"`
Port int `mapstructure:"port"`
SiteRoot string `mapstructure:"siteRoot"`
}
Server is the holds HTTP server settings