goplum

package module
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2020 License: MIT Imports: 13 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`, and optionally give it a persistent directory
to store data in across restarts.

Running it via the command line:

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

Or using Docker Compose:

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

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

For more information and 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
}

# An alert named 'text' that will send an SMS message via Twilio:
alert twilio.sms "text" {
  sid = "sid"
  token = "token"
  from = "+01 867 5309"
  to = "+01 867 5309"
}

# A check named 'Example' that checks a webpage is accessible:
check http.get "Example" {
  url = "https://www.example.com/"
}
----

This defines one check and one alert. You can add as many of both as you want; by default
all alerts will be triggered when a check changes status.

All checks have a number of additional settings to control how they work. These can be
specified for each check, or changed globally by putting them in the "defaults" section.
If they're not specified then Goplum's built-in defaults will be used.

|===
|Setting |Description |Default

|`interval`
|Length of time between each run of the check.
|`30s`

|`timeout`
|Maximum length of time the check can run for before it's terminated.
|`20s`

|`alerts`
|A list of alert names to trigger when the service changes state.
 Supports '*' as a wildcard.
|`["*"]`

|`failing_threshold`
|The number of checks that must fail in a row before a failure alert is raised.
|`2`

|`good_threshold`
|The number of checks that must pass in a row before a recovery alert is raised.
|`2`
|===

An link:docs/example.conf[extended example] and a
link:docs/syntax.adoc[detailed guide to configuration syntax] are available in
the docs folder.

== 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,
	Timeout:          time.Second * 20,
	GoodThreshold:    2,
	FailingThreshold: 2,
}

Functions

func Run added in v0.3.0

func Run(plugins map[string]PluginLoader, configPath string)

Run creates a new instance of Plum, registers plugins and loads configuration, and starts the main loop. Lists for interrupt and sigterm signals in order to save state and clean up. It is expected that flag.Parse has been called prior to calling this method.

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 or the passed context is cancelled.
	Execute(ctx context.Context) 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
	Timeout          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.

func (*CheckState) UnmarshalJSON added in v0.3.0

func (c *CheckState) UnmarshalJSON(val []byte) error

type CheckTombStone added in v0.3.0

type CheckTombStone struct {
	LastRun time.Time
	Settled bool
	State   CheckState
	History ResultHistory
}

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) RestoreState added in v0.3.0

func (p *Plum) RestoreState() error

func (*Plum) Run

func (p *Plum) Run()

func (*Plum) RunCheck

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

func (*Plum) SaveState added in v0.3.0

func (p *Plum) SaveState() error

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
	History   ResultHistory
}

func (*ScheduledCheck) AddResult

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

func (*ScheduledCheck) LastResult

func (c *ScheduledCheck) LastResult() *Result

func (*ScheduledCheck) Remaining

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

type TombStone added in v0.3.0

type TombStone struct {
	Time   time.Time
	Checks map[string]CheckTombStone
}

func LoadTombStone added in v0.3.0

func LoadTombStone() (*TombStone, error)

func NewTombStone added in v0.3.0

func NewTombStone(checks []*ScheduledCheck) *TombStone

func (*TombStone) Restore added in v0.3.0

func (ts *TombStone) Restore(checks []*ScheduledCheck) error

func (*TombStone) Save added in v0.3.0

func (ts *TombStone) Save() error

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