goplum

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2020 License: MIT Imports: 9 Imported by: 0

README

= Goplum

image::logo.png?raw=true[Goplum logo,role="right"]

Goplum is an extensible monitoring and alerting daemon designed for
personal infrastructure and small businesses. It can monitor
websites and APIs, and send alerts by text message if they go down.

== Getting started

The easiest way to run Goplum is via Docker. It doesn't require any
special privileges or settings, you just need to provide a config file
to it at `/goplum.conf`.

Running it via the command line:

[source]
----
docker run -d --restart always -v /path/to/my/goplum.conf:/goplum.conf csmith/goplum
----

Or using Docker Compose:

[source,yaml]
----
version: "3.8"

services:
  goplum:
    image: csmith/goplum
    volumes:
      - ./goplum.conf:/goplum.conf
    restart: always
----

For alternative installation methods see link:docs/install.adoc[the installation documentation].

== Configuration

Goplum's configuration contains an optional defaults section, a list of alerts, and
a list of checks. A simple example might look like this:

[source,goplum]
----
defaults {
  # Change the default interval for all checks to 10 second, rather than
  # Goplum's normal default of 30 seconds:
  interval = 10s
}

alert twilio.sms "text" {
  sid = "sid"
  token = "token"
  from = "+01 867 5309"
  to = "+01 867 5309"
}

check http.get "Example" {
  url = "https://www.example.com/"
}
----

This defines one check - of type `http.get` that will run every 30 seconds (the default
interval specified in the "defaults" block). If the check starts failing, all the
defined alerts will be triggered -- in this case sending a text message via Twilio.

Each check and alert has a name, which is used to refer to it in the config and in messages,
and a type. The type consists of the name of a plugin, a period, and then the type of check
or alert from that plugin. Some checks and alerts take parameters, which are specified as
`key = value` assignments within the block, one per line.

Checks have four additional settings. These can be changed globally by putting them in the
"defaults" section. If they're not specified then Goplum's built-in defaults will be used:

interval::
The time after which the check is repeated, for example `20s` for 20 seconds, `10m` for
10 minutes, or `7h` for 7 hours. Global default: 30 seconds.

alerts::
A list of alert names which should be triggered when the service changes state. The wildcard
'\*' may be used anywhere to match any number of characters. Note that an empty array is treated
the same as a missing option, so default settings will be used; to disable alerts use
`["-"]`. Global default: `["*"]` (all alerts).

failing_threshold::
The number of times a check must fail in a row before the service is considered failing.
This allows you to ignore brief, transient problems that may occur between your monitoring
location and the service itself, or very brief outages such as webserver restarts.
Global default: 2.

good_threshold::
The number of times a check must pass in a row before the service is considered up. This
prevents alert noise if a check occasionally passes for some reason. Global default: 2.

More information on the syntax for configuration files is found in the
link:docs/syntax.adoc[syntax guide].

== Bundled plugins

All checks and alerts in Goplum are implemented as plugins. The following are maintained in
this repository and are available by default in the Docker image:

* link:plugins/http[http] - checks for HTTP services, and alerting via webhooks
* link:plugins/network[network] - low level checks for network services
* link:plugins/pushover[pushover] - sends alerts via Pushover
* link:plugins/slack[slack] - sends alerts via Slack
* link:plugins/twilio[twilio] - sends SMS alerts via Twilio
* link:plugins/debug[debug] - provides tools for building and testing Goplum
* link:plugins/exec[exec] - allows executing arbitrary commands

== Plugin API

Goplum is designed to be easily extensible. Plugins must have a main package which contains
a function named "Plum" that returns an implementation of `goplum.Plugin`. They are then
compiled with the `-buildtype=plugin` flag to create a shared library.

The Docker image loads plugins recursively from the `/plugins` directory, allowing you to
mount custom folders if you wish to supply your own plugins.

Note that the Go plugin loader does not work on Windows. For Windows-based development,
the `goplumdev` command hardcodes plugins, skipping the loader.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultSettings = CheckSettings{
	Alerts:           []string{"*"},
	Interval:         time.Second * 30,
	GoodThreshold:    2,
	FailingThreshold: 2,
}

Functions

This section is empty.

Types

type Alert

type Alert interface {
	// Send dispatches an alert in relation to the given check event.
	Send(details AlertDetails) error

	// Validate checks the configuration of this alert and returns any errors.
	Validate() error
}

Alert defines the method to inform the user of a change to a service - e.g. when it comes up or goes down.

type AlertDetails

type AlertDetails struct {
	// Text is a short, pre-generated message describing the alert.
	Text string `json:"text"`
	// Name is the name of the check that transitioned.
	Name string `json:"name"`
	// Type is the type of check involved.
	Type string `json:"type"`
	// Config is the user-supplied parameters to the check.
	Config interface{} `json:"config"`
	// LastResult is the most recent result that caused the transition.
	LastResult *Result `json:"last_result"`
	// PreviousState is the state this check was previously in.
	PreviousState CheckState `json:"previous_state"`
	// NewState is the state this check is now in.
	NewState CheckState `json:"new_state"`
}

AlertDetails contains information about a triggered alert

type Check

type Check interface {
	// Execute performs the actual check to see if the service is up or not.
	// It should block until a result is available.
	Execute() Result

	// Validate checks the configuration of this check and returns any errors.
	Validate() error
}

Check defines the method to see if a service is up or not. The check is persistent - its Execute method will be called repeatedly over the lifetime of the application.

type CheckSettings

type CheckSettings struct {
	Alerts           []string
	Interval         time.Duration
	GoodThreshold    int `config:"good_threshold"`
	FailingThreshold int `config:"failing_threshold"`
}

func (CheckSettings) Copy added in v0.2.0

func (c CheckSettings) Copy() CheckSettings

type CheckState

type CheckState int

CheckState describes the state of a check.

const (
	// StateIndeterminate indicates that it's not clear if the check passed or failed, e.g. it hasn't run yet.
	StateIndeterminate CheckState = iota
	// StateGood indicates the service is operating correctly.
	StateGood
	// StateFailing indicates a problem with the service.
	StateFailing
)

func (CheckState) MarshalJSON

func (c CheckState) MarshalJSON() ([]byte, error)

func (CheckState) String

func (c CheckState) String() string

String returns an english, lowercase name for the state.

type Plugin

type Plugin interface {
	Check(kind string) Check
	Alert(kind string) Alert
}

Plugin is the API between plugins and the core. Plugins must provide an exported "Plum()" method in the main package which returns an instance of Plugin.

The Check and Alert funcs should provide new instances of the named type, or nil if such a type does not exist. Exported fields of the checks and alerts will then be populated according to the user's config, and the Validate() func will be called.

type PluginLoader added in v0.2.0

type PluginLoader func() (Plugin, error)

type Plum

type Plum struct {
	Alerts map[string]Alert
	Checks []*ScheduledCheck
	// contains filtered or unexported fields
}

func NewPlum added in v0.2.0

func NewPlum() *Plum

func (*Plum) AlertsMatching

func (p *Plum) AlertsMatching(names []string) []Alert

func (*Plum) RaiseAlerts

func (p *Plum) RaiseAlerts(c *ScheduledCheck, previousState CheckState)

func (*Plum) ReadConfig added in v0.2.0

func (p *Plum) ReadConfig(path string) error

func (*Plum) RegisterPlugin added in v0.2.0

func (p *Plum) RegisterPlugin(name string, loader PluginLoader)

func (*Plum) RegisterPlugins added in v0.2.0

func (p *Plum) RegisterPlugins(plugins map[string]PluginLoader)

func (*Plum) Run

func (p *Plum) Run()

func (*Plum) RunCheck

func (p *Plum) RunCheck(c *ScheduledCheck)

type Result

type Result struct {
	// State gives the current state of the service.
	State CheckState `json:"state"`
	// Time is the time the check was performed.
	Time time.Time `json:"time"`
	// Detail is an short, optional explanation of the current state.
	Detail string `json:"detail,omitempty"`
}

Result contains information about a check that was performed.

func FailingResult

func FailingResult(format string, a ...interface{}) Result

FailingResult creates a new result indicating the service is in a bad state.

func GoodResult

func GoodResult() Result

GoodResult creates a new result indicating the service is in a good state.

type ResultHistory

type ResultHistory [10]*Result

func (ResultHistory) State

func (h ResultHistory) State(thresholds map[CheckState]int) CheckState

type ScheduledCheck

type ScheduledCheck struct {
	Name      string
	Type      string
	Config    *CheckSettings
	Check     Check
	LastRun   time.Time
	Scheduled bool
	Settled   bool
	State     CheckState
	// contains filtered or unexported fields
}

func (*ScheduledCheck) AddResult

func (c *ScheduledCheck) AddResult(result *Result) ResultHistory

func (*ScheduledCheck) History

func (c *ScheduledCheck) History() ResultHistory

func (*ScheduledCheck) LastResult

func (c *ScheduledCheck) LastResult() *Result

func (*ScheduledCheck) Remaining

func (c *ScheduledCheck) Remaining() time.Duration

Directories

Path Synopsis
cmd
goplum command
goplumdev command
plugins
debug/cmd command
exec/cmd command
http/cmd command
network/cmd command
pushover/cmd command
slack/cmd command
twilio/cmd command

Jump to

Keyboard shortcuts

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