Documentation
¶
Index ¶
- Constants
- Variables
- func CheckDefault(value string, defaultValue string) string
- func CheckSendDetails() error
- func FormatOutput(outputFormat string, textTemplate string, output interface{}) (string, error)
- func FormatTemplate(tmpl string, intr any) (string, error)
- func GetFieldsByLabel(labels []string, a any) []string
- 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 HandlerPingHelp(w http.ResponseWriter, req *http.Request)
- func HandlerStatus(w http.ResponseWriter, req *http.Request)
- func NewRouter() *mux.Router
- func NotificationFunc(heartbeatName string, success bool) func()
- func ProcessServiceSettings() error
- func ReadConfigFile(configPath string) error
- func RedactServices(services []interface{}) ([]interface{}, error)
- func ResetTimerIfRunning(previousHeartbeats *[]Heartbeat)
- func Send(heartbeatName string, serviceName string, notifier notify.Notifier, ...) error
- func SubstituteFieldsWithEnv(prefix string, a any) map[string]reflect.Value
- func WriteOutput(w http.ResponseWriter, statusCode int, outputFormat string, output interface{}, ...)
- type Ago
- type Config
- type Defaults
- type FormatPeriod
- type Heartbeat
- type HeartbeatStatus
- type HeartbeatsConfig
- type Metrics
- type Notifications
- type ResponseStatus
- type SendDetails
- type Server
- type Timer
Constants ¶
const ( Day time.Duration = time.Hour * 24 Month time.Duration = Day * 30 Year time.Duration = Day * 365 )
const (
EnvPrefix = "env:"
)
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 CheckSendDetails ¶
func CheckSendDetails() error
CheckSendDetails checks if the send details are set and parsing is possible
func FormatOutput ¶
FormatOutput formats the output according to outputFormat
func FormatTemplate ¶
FormatTemplate format template with intr as input
func GetFieldsByLabel ¶
GetRedactedFields search in a struct for fields with the tag "redacted" and returns a list with the field names
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 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 processes the list with notifications
func ReadConfigFile ¶
ReadConfigFile reads the notifications config file
func RedactServices ¶
func RedactServices(services []interface{}) ([]interface{}, error)
RedactNotifications redacts the fields with the tag "redacted" in the notifications struct
func ResetTimerIfRunning ¶
func ResetTimerIfRunning(previousHeartbeats *[]Heartbeat)
ResetTimerIfRunning resets existing timers if they are running
func Send ¶
func Send(heartbeatName string, serviceName string, notifier notify.Notifier, subject string, message string) error
Send sends a notification
func SubstituteFieldsWithEnv ¶
SubstituteFieldsWithEnv searches in env for the given key and replaces the value with the value from env
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" default:"Heartbeat"`
Message string `mapstructure:"message" default:"Heartbeat is missing"`
SendResolve *bool `mapstructure:"sendResolve" default:"true"`
}
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 GetHeartbeatByName ¶
GetHeartbeatByName search heartbeat in HeartbeatsConfig.Heartbeats by name and returns it
type HeartbeatStatus ¶
type HeartbeatStatus struct {
Name string `json:"name"`
Status string `json:"status"`
LastPing time.Time `json:"lastPing"`
}
HeartbeatStatus represents a heartbeat status
type HeartbeatsConfig ¶
type HeartbeatsConfig struct {
Version string `mapstructure:"version"`
Config Config `mapstructure:"config"`
Server Server `mapstructure:"server"`
Heartbeats []Heartbeat `mapstructure:"heartbeats"`
Notifications Notifications `mapstructure:"notifications"`
}
HeartbeatsConfig is the main configuration struct
var HeartbeatsServer HeartbeatsConfig
func (*HeartbeatsConfig) GetServiceByName ¶
func (h *HeartbeatsConfig) GetServiceByName(notificationType string) (interface{}, 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 Notifications ¶
type Notifications struct {
Defaults Defaults `mapstructure:"defaults"`
Services []interface{} `mapstructure:"services"`
}
NotifyConfig holds the configuration for the notifications
type ResponseStatus ¶
ResponseStatus represents a response
type SendDetails ¶
SendDetails holds prepared subject & message
func PrepareSend ¶
func PrepareSend(subject string, message string, defaults *Defaults, values interface{}) (SendDetails, error)
PrepareSend prepares subject & message to be sent
type Server ¶
type Server struct {
Hostname string `mapstructure:"hostname"`
Port int `mapstructure:"port"`
SiteRoot string `mapstructure:"siteRoot"`
}
Server is the holds HTTP server settings