types

package
v0.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 5, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultInterval         = 30 * time.Second
	DefaultTimeout          = 60 * time.Second
	DefaultMaxConn          = 128
	DefaultSuccessThreshold = 1
	DefaultFailureThreshold = 2
	DefaultCooldown         = 5 * time.Minute
)
View Source
const (
	Unknown  StatusType = "unknown"
	UP       StatusType = "up"
	DEGRADED StatusType = "degraded"
	DOWN     StatusType = "down"

	HttpType     HostType = "http"
	MongoType    HostType = "mongo"
	ICMPType     HostType = "icmp"
	TCPType      HostType = "tcp"
	DNSType      HostType = "dns"
	RedisType    HostType = "redis"
	PostgresType HostType = "postgres"
	MySQLType    HostType = "mysql"
)

Variables

View Source
var ErrHostNotFound = errors.New("host not found")

Functions

This section is empty.

Types

type Aggregation

type Aggregation struct {
	ResponseTime time.Duration `json:"responseTime"`
	Count        int           `json:"count"`
	Uptime       float64       `json:"uptime"`
	TS           time.Time     `json:"timestamp"`
}

Aggregation - aggregation structure for the history per day

type BasicAuth

type BasicAuth struct {
	Username string `json:"username" yaml:"username"`
	Password string `json:"password" yaml:"password"`
}

type BotComm

type BotComm struct {
	ClientID     string   `json:"clientID" yaml:"clientID"`
	ClientSecret string   `json:"clientSecret" yaml:"clientSecret"`
	SessionIDs   []string `json:"sessionIDs" yaml:"sessionIDs"` // omit to broadcast to everyone connected to the bot
}

BotComm - messages via botcomm.app.

type Cfg

type Cfg struct {
	Interval     time.Duration  `json:"interval,omitempty" yaml:"interval,omitempty"`
	Timeout      time.Duration  `json:"timeout,omitempty" yaml:"timeout,omitempty"`
	InitialDelay *time.Duration `json:"initialDelay,omitempty" yaml:"initialDelay,omitempty"`
	MaxConn      int            `json:"maxConn,omitempty" yaml:"maxConn,omitempty"` // maximum concurrent dial connections

	SuccessThreshold int `json:"successThreshold" yaml:"successThreshold,omitempty"`
	FailureThreshold int `json:"failureThreshold" yaml:"failureThreshold,omitempty"`

	Conditions *Success          `json:"success" yaml:"success,omitempty"`
	Headers    map[string]string `json:"headers" yaml:"headers,omitempty"`

	UI            UI            `json:"ui" yaml:"ui"`
	Connectivity  *Connectivity `json:"connectivity" yaml:"connectivity,omitempty"`
	Notifications Notifications `json:"notifications" yaml:"notifications,omitempty"`
	FileHosts     []*Host       `json:"hosts" yaml:"hosts"`
	Hosts         []*Host       `json:"-" yaml:"-"`

	// DefaultSMTP - SMTP settings provided via CLI flags/env. Used when the
	// configuration file does not define notifications.smtp.
	DefaultSMTP *SMTP `json:"-" yaml:"-"`

	FW chan bool `yaml:"-"`

	// DEPRECATED: use Notifications instead of Alerts
	Alerts *Notifications `json:"alerts,omitempty" yaml:"alerts,omitempty"`
	// contains filtered or unexported fields
}

func NewConfig

func NewConfig(ctx context.Context, path string) (*Cfg, error)

func (*Cfg) GetUI

func (c *Cfg) GetUI() UI

GetUI - returns a copy of the UI settings. Safe to call concurrently with a reload.

func (*Cfg) Parse

func (c *Cfg) Parse() error

Parse - reads the configuration file (json or yaml) into a fresh structure and, only if it was decoded successfully, replaces the current configuration with it. Parsing into a fresh structure guarantees that sections removed from the file are removed from the running configuration too (decoding into the existing structure would only merge new values on top of the old ones).

func (*Cfg) Validate

func (c *Cfg) Validate() error

Validate - fills the defaults, validates the values and builds the list of hosts for monitoring. Hosts are always rebuilt from scratch: the previous list is left untouched (watchers may still be using it) and replaced only on success.

type Chart

type Chart struct {
	Points    []*Point
	Intervals []string
}

Chart is a struct that contains the points and intervals of a host.

type Connectivity

type Connectivity struct {
	Disabled bool          `json:"disabled" yaml:"disabled"` // disables the connectivity check (enabled by default)
	Targets  []string      `json:"targets" yaml:"targets"`   // host:port endpoints to probe over TCP
	Interval time.Duration `json:"interval" yaml:"interval"` // how long a connectivity result is cached
	Timeout  time.Duration `json:"timeout" yaml:"timeout"`   // timeout for a single connectivity probe
}

Connectivity - configures the self connectivity check. When the monitor loses its own internet connection, failed host checks are skipped instead of being reported as DOWN, avoiding false positives (e.g. home internet outage).

type DNSCheck

type DNSCheck struct {
	Type     string   `json:"type,omitempty" yaml:"type,omitempty"`         // A, AAAA, CNAME, MX, NS, TXT (default: A)
	Expect   []string `json:"expect,omitempty" yaml:"expect,omitempty"`     // values that must be present in the answer (optional)
	Resolver string   `json:"resolver,omitempty" yaml:"resolver,omitempty"` // host:port of the dns server (default: system resolver)
}

DNSCheck - options of a dns host (url: dns://name)

type Details

type Details struct {
	Uptime       string
	ResponseTime string
	SSL          *SSLDetails
	LastOutage   *LastOutageDetails
}

Details is a struct that contains the uptime and response time of a host.

type Discord

type Discord struct {
	WebhookURL string `json:"webhookURL" yaml:"webhookURL"`
	Username   string `json:"username" yaml:"username"` // overrides the webhook name (optional)
}

Discord - incoming webhook.

type Host

type Host struct {
	ID   string   `json:"id" yaml:"-"`
	Type HostType `json:"type" yaml:"type"`

	Name        *string `json:"name,omitempty" yaml:"name,omitempty"`
	Description *string `json:"description,omitempty" yaml:"description,omitempty"`
	Group       *string `json:"group,omitempty" yaml:"group,omitempty"`

	Method string `json:"method,omitempty" yaml:"method,omitempty"`
	URL    string `json:"url" yaml:"url"`

	Interval        *time.Duration `json:"interval" yaml:"interval,omitempty"` // minimum 1s
	TimeoutInterval *time.Duration `json:"timeout" yaml:"timeout,omitempty"`
	InitialDelay    *time.Duration `json:"initialDelay" yaml:"initialDelay,omitempty"`

	SuccessThreshold int `json:"successThreshold,omitempty" yaml:"successThreshold,omitempty"`
	FailureThreshold int `json:"failureThreshold,omitempty" yaml:"failureThreshold,omitempty"`

	Conditions *Success          `json:"conditions,omitempty" yaml:"conditions,omitempty"`
	Headers    map[string]string `json:"headers,omitempty" yaml:"headers,omitempty"`

	Alerts []string `json:"alerts,omitempty" yaml:"alerts,omitempty"`

	DNS *DNSCheck `json:"dns,omitempty" yaml:"dns,omitempty"` // dns check options

	Hidden bool `json:"hidden" yaml:"hidden"` // acceptable only if group is defined

	Index int `json:"-" yaml:"-"`
}

Host - host structure

func (*Host) Changed

func (h *Host) Changed(other *Host) bool

Changed - reports whether the monitoring-relevant configuration of the host differs from the other one. The position in the list (Index) is ignored.

func (*Host) GenerateID

func (h *Host) GenerateID() string

GenerateID - returns a host id based on the url hash

func (*Host) GetType

func (h *Host) GetType() HostType

GetType - return a host type based on url

func (*Host) SecureURL

func (h *Host) SecureURL() string

SecureURL - returns a secure url that can be used in logs or alerts. It will hide the password if present.

func (*Host) Status

func (h *Host) Status(code int, b []byte) bool

Status - checking if provided code present in the success code list and body is equal

func (*Host) String

func (h *Host) String() string

String - returns a name if available, otherwise returns the url. Credentials in the url are masked: the value is used in logs and notifications.

type HostType

type HostType string

type HttpResponse

type HttpResponse struct {
	Timestamp time.Time     `json:"timestamp"`
	Time      time.Duration `json:"time"`
	Code      int           `json:"code,omitempty"`
	Body      string        `json:"body,omitempty"`

	OK         bool       `json:"-"`
	Bytes      []byte     `json:"-"`
	Status     bool       `json:"status,omitempty"`
	StatusType StatusType `json:"statusType,omitempty"`

	DNS           time.Duration `json:"DNS,omitempty"`
	TLSHandshake  time.Duration `json:"TLSHandshake,omitempty"`
	Connect       time.Duration `json:"connect,omitempty"`
	TTFB          time.Duration `json:"TTFB,omitempty"`
	SSLCertExpiry *time.Time    `json:"SSLExpiry,omitempty"`
	SSLIssuer     string        `json:"SSLIssuer,omitempty"`
	TLSVersion    string        `json:"TLSVersion,omitempty"`

	IsAggregated bool    `json:"isAggregated"`
	Uptime       float64 `json:"uptime,omitempty"` // aggregation uptime
	Count        int     `json:"count,omitempty"`  // aggregation count
}

HttpResponse - response from the http dial

type Incident

type Incident struct {
	ID       int             `json:"id"`
	Text     string          `json:"-"`
	Details  IncidentDetails `json:"details"`
	Start    string          `json:"-"`
	End      string          `json:"-"`
	Duration string          `json:"-"`
	StartTS  time.Time       `json:"startTS"`
	EndTS    *time.Time      `json:"endTS,omitempty"`
}

Incident - host incident structure

type IncidentDetails

type IncidentDetails struct {
	StatusCode int       `json:"statusCode"`
	StatusText string    `json:"-"`
	Response   string    `json:"response,omitempty"`
	TS         time.Time `json:"ts"`
}

type LastOutageDetails

type LastOutageDetails struct {
	Duration string
	Since    string
	TS       string
}

type Mattermost

type Mattermost struct {
	WebhookURL string `json:"webhookURL" yaml:"webhookURL"`
	Channel    string `json:"channel" yaml:"channel"`   // overrides the webhook channel (optional)
	Username   string `json:"username" yaml:"username"` // overrides the webhook username (optional)
}

Mattermost - Slack-compatible incoming webhook (Mattermost, Rocket.Chat, ...).

type Notifications

type Notifications struct {
	Slack      *Slack      `json:"slack" yaml:"slack"`
	Telegram   *Telegram   `json:"telegram" yaml:"telegram"`
	SMTP       *SMTP       `json:"smtp" yaml:"smtp"`
	Webhook    *Webhook    `json:"webhook" yaml:"webhook"`
	Discord    *Discord    `json:"discord" yaml:"discord"`
	Teams      *Teams      `json:"teams" yaml:"teams"`
	Mattermost *Mattermost `json:"mattermost" yaml:"mattermost"`
	Pushover   *Pushover   `json:"pushover" yaml:"pushover"`
	Ntfy       *Ntfy       `json:"ntfy" yaml:"ntfy"`
	Twilio     *Twilio     `json:"twilio" yaml:"twilio"`
	BotComm    *BotComm    `json:"botcomm" yaml:"botcomm"`

	InitializationMessage *bool `json:"initializationMessage" yaml:"initializationMessage"`
	ShutdownMessage       bool  `json:"shutdownMessage" yaml:"shutdownMessage"`

	// Cooldown - minimal time between two identical notifications (same host, same status, same channel).
	// Prevents spamming when a host flaps. Default: 5m. Set to 0 to disable.
	Cooldown *time.Duration `json:"cooldown,omitempty" yaml:"cooldown,omitempty"`
}

type Ntfy

type Ntfy struct {
	URL      string `json:"url" yaml:"url"`           // server url, default: https://ntfy.sh
	Topic    string `json:"topic" yaml:"topic"`       // topic name
	Token    string `json:"token" yaml:"token"`       // access token (optional)
	Priority int    `json:"priority" yaml:"priority"` // 1..5, default: 3
}

Ntfy - push notifications via ntfy.sh or a self-hosted ntfy server.

type Point

type Point struct {
	Status    StatusType
	Tooltip   *string
	Timestamp string
	TS        time.Time
}

Point is a struct that contains the timestamp, status, and tooltip of a host. Used for the chart.

type Pushover

type Pushover struct {
	Token    string `json:"token" yaml:"token"`       // application token
	User     string `json:"user" yaml:"user"`         // user or group key
	Priority int    `json:"priority" yaml:"priority"` // -2..2, 2 = emergency (repeats until acknowledged)
}

Pushover - push notifications via pushover.net.

type SMTP

type SMTP struct {
	Host     string   `json:"host" yaml:"host"`
	Port     int      `json:"port" yaml:"port"`
	Username string   `json:"username" yaml:"username"`
	Password string   `json:"password" yaml:"password"`
	From     string   `json:"from" yaml:"from"`
	To       []string `json:"to" yaml:"to"`

	// InsecureSkipVerify disables TLS certificate verification for the SMTP connection.
	InsecureSkipVerify bool `json:"insecureSkipVerify" yaml:"insecureSkipVerify"`
}

type SSLDetails

type SSLDetails struct {
	ExpireInDays int
	ExpireTS     string
	Issuer       string
	TLSVersion   string
}

SSLDetails is a struct that contains the expiration date of the SSL certificate. LastOutageDetails is a struct that contains the duration of the last outage.

type Slack

type Slack struct {
	Channel string `json:"channel" yaml:"channel"`
	Token   string `json:"token" yaml:"token"`
}

type Stat

type Stat struct {
	ID           string
	Name         *string
	Description  *string
	Host         string
	Status       StatusType
	Uptime       int
	ResponseTime string
	Chart        Chart
	Hosts        []Stat
	Details      *Details

	Index int
}

Stat is a struct that contains the stats of a host.

type Stats

type Stats struct {
	IsHost    bool
	Status    StatusType
	Hosts     []Stat
	Incidents []*Incident
}

Stats is a struct that contains the stats of all hosts.

type Status

type Status struct {
	Value     StatusType `json:"value"`
	Timestamp time.Time  `json:"timestamp"`
}

Status - status structure for Service

type StatusType

type StatusType string

StatusType - host status type HostType - host type

type Success

type Success struct {
	Code []int   `json:"code" yaml:"code"`
	Body *string `json:"body" yaml:"body"`
}

type Tag

type Tag struct {
	Name  string `json:"name"`
	Color string `json:"color"`
}

Tag - color tag structure for Service

type Teams

type Teams struct {
	WebhookURL string `json:"webhookURL" yaml:"webhookURL"`
}

Teams - Microsoft Teams incoming webhook (Workflows or legacy connector).

type Telegram

type Telegram struct {
	Token   string   `json:"token" yaml:"token"`
	ChatIDs []string `json:"chatIDs" yaml:"chatIDs"`
}

type Twilio

type Twilio struct {
	AccountSID string   `json:"accountSID" yaml:"accountSID"`
	AuthToken  string   `json:"authToken" yaml:"authToken"`
	From       string   `json:"from" yaml:"from"` // sender number or messaging service sid
	To         []string `json:"to" yaml:"to"`     // recipient numbers
}

Twilio - SMS via Twilio.

type UI

type UI struct {
	Title     string     `json:"title" yaml:"title"`         // web page title
	HideURL   bool       `json:"hideURL" yaml:"hideURL"`     // allows to hide URL of the host in the UI
	BasicAuth *BasicAuth `json:"basicAuth" yaml:"basicAuth"` // enables basic authentication for the web UI
}

type Webhook

type Webhook struct {
	URL     string            `json:"url" yaml:"url"`
	Method  string            `json:"method" yaml:"method"`   // default: POST
	Headers map[string]string `json:"headers" yaml:"headers"` // extra headers (e.g. Authorization)
}

Webhook - generic HTTP webhook, receives a JSON payload with the event details.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL