monzero

package module
v0.0.0-...-efa2f5b Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2023 License: MIT Imports: 8 Imported by: 0

README

monzero

Monzero is a collection of tools with the purpose of running monitoring checks and triggering notifications.

requirements

runtime requirements:

  • PostgreSQL >= 10.0

build requirements:

  • Go >= 1.11

components

The following components exist:

moncheck

Moncheck is the daemon that runs the checks and generates notifications in the database. It is possible to run multiple instances of moncheck, as it uses PostgreSQL as a coordinator through the PostgreSQL internal locking mechanism.

Moncheck uses the table active_checks to detect which checks to run.

monfront

Monfront is a webfrontend to view the current state of all checks, configure hosts, groups, checks and view current notifications. It is possible to run multiple instances.

monwork

Monwork is a small server that does all the maintenance work in the background. It is responsible to cleanup the history and generate the configuration.

The configuration is generated into active_checks when an entry in nodes, command or checks was changed (detected through the updated column).

configuration

To get the system working, first install the database. After that, create an alarm mapping:

insert into mappings(name, description) values ('default', 'The default mapping');
insert into mapping_level values (1, 0, 0, 'okay', 'green');
insert into mapping_level values (1, 1, 1, 'okay', 'orange');
insert into mapping_level values (1, 2, 2, 'okay', 'red');
insert into mapping_level values (1, 3, 3, 'okay', 'gray');

Next is to create a notifier. This feature doesn't work 100% yet and needs some work and may look different later:

insert into notifier(name) values ('default');

After that create a check command:

insert into commands(name, command, message) values ('ping', 'ping -n -c 1 {{ .ip }}', 'Ping a target');

This command can contain variables that are set in the check. It will be executed by moncheck and the result stored.

After that, create a node which will get the checks attached:

insert into nodes(name, message) values ('localhost', 'My localhost is my castle');

With that prepared, create the first check:

insert into checks(node_id, command_id, notifier_id, message, options)
values (1, 1, 1, 'This is my localhost ping check!', '{"ip": "127.0.0.1"}');

Now start the daemons moncheck, monfront and monwork.

monwork will transform the configured check into an active check, while moncheck will run the actual checks. Through monfront one can view the current status.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoCheck = fmt.Errorf("no check found to run")
)

Functions

This section is empty.

Types

type Check

type Check struct {
	// Command is the command to run as stored in the database.
	Command []string
	// ExitCodes contains the list of exit codes of past runs.
	ExitCodes []int
	// contains filtered or unexported fields
}

Check is contains the metadata to run a check and its current state.

type CheckResult

type CheckResult struct {
	ExitCode int
	Message  string // Message will be shown in the frontend for context
}

CheckResult is the result of a check. It may contain a message and must contain an exit code. The exit code should conform to the nagios specification of 0 - okay 1 - error 2 - warning 3 - unknown or executor errors Other codes are also okay and may be mapped to different values, but need further configuration in the system.

func CheckExec

func CheckExec(check Check, ctx context.Context) CheckResult

CheckExec runs a command line string. The output is recorded completely and returned as one message.

type Checker

type Checker struct {
	// contains filtered or unexported fields
}

Checker maintains the state of checks that need to be run.

func NewChecker

func NewChecker(cfg CheckerConfig) (*Checker, error)

func (*Checker) Next

func (c *Checker) Next() error

Next pulls the next check in line and runs the set executor. The result is then updated in the database and a notification generated.

type CheckerConfig

type CheckerConfig struct {
	// CheckerID is used to find the checks that need to be run by this
	// instance.
	CheckerID int

	// DB is the connection to the database to use.
	DB *sql.DB

	// Timeout is the duration a check has time to run.
	// Set this to a reasonable value for all checks to avoid long running
	// checks blocking the execution.
	Timeout time.Duration

	// Executor receives a check and must run the requested command in the
	// time of the context.
	// At the end it must return a CheckResult.
	Executor func(Check, context.Context) CheckResult

	// HostIdentifier is used in notifications to point to the source of the
	// notification.
	HostIdentifier string

	// Checker will send debug details to the logger for each command executed.
	Logger *slog.Logger
}

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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