command

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ResultStrings = map[Result]string{
		CmdOk:      "Ok",
		CmdFail:    "Fail",
		CmdSigOk:   "SigOk",
		CmdSigFail: "SigFail",
		CmdSkipSig: "SkipSig",
	}
)

Functions

func IsDigit

func IsDigit(s string) bool

IsDigit returns true if all of the string consists of digits

Types

type Command

type Command struct {
	Cmd  string   `yaml:"cmd"`
	Args []string `yaml:"args"`
	// Only execute this command when all of the given labels match.
	// The CommonLabels field of prometheus alert data is used for comparison.
	MatchLabels map[string]string `yaml:"match_labels"`
	// How many instances of this command can run at the same time.
	// A zero or negative value is interpreted as 'no limit'.
	Max int `yaml:"max"`
	// Whether we should let the caller know if a command failed.
	// Defaults to true.
	// The value is a pointer to bool with the 'omitempty' tag,
	// so we can tell when the value was not defined,
	// meaning we'll provide the default value.
	NotifyOnFailure *bool `yaml:"notify_on_failure,omitempty"`
	// Whether command will ignore a 'resolved' notification for a matching command,
	// and continue running to completion.
	// Defaults to false.
	IgnoreResolved *bool  `yaml:"ignore_resolved,omitempty"`
	ResolvedSig    string `yaml:"resolved_signal"`
	// Evaluate if terraform destroy should be run
	DestroyOnResolved *bool `yaml:"destroy_on_resolved,omitempty"`
	// Available scheduling modes based on alert status
	// Regular, firing -> apply, resolved -> destroy
	// Sawtooth, firing -> apply, resolved -> ignore
	TerraformScheduling string `yaml:"terraform_scheduling,omitempty"`
}

Command represents a command that could be run based on what labels match

func (Command) Equal

func (c Command) Equal(other *Command) bool

Equal returns true if the Command is identical to another Command

func (Command) Fingerprint

func (c Command) Fingerprint(alert *template.Alert) (string, bool)

Fingerprint returns the fingerprint of the first alarm that matches the command's labels. The first fingerprint found is returned if we have no MatchLabels defined.

func (Command) Matches

func (c Command) Matches(alert *template.Alert) bool

Matches returns true if the specified labels in MatchLabels are present and match their values in the prometheus alert message. If MatchLabels is empty, it returns true.

func (Command) ParseSignal

func (c Command) ParseSignal() (os.Signal, error)

ParseSignal returns the signal that is meant to be used for notifying the command that its triggering condition has resolved, and any error encountered while parsing.

func (Command) Run

func (c Command) Run(out chan<- CommandResult, quit chan struct{}, done chan struct{}, env ...string)

Run executes the command, potentially signalling it if alarm that triggered command resolves. out channel is used to indicate the result of running or killing the program. May indicate errors. quit channel is used to determine if execution should quit early done channel is used to indicate to caller when execution has completed

func (Command) ShouldIgnoreResolved

func (c Command) ShouldIgnoreResolved() bool

ShouldIgnoreResolved returns the interpreted value of c.IgnoreResolved. This method is used to work around ambiguity of unmarshalling yaml boolean values, due to the default value of a bool being false.

func (Command) ShouldNotify

func (c Command) ShouldNotify() bool

ShouldNotify returns the interpreted value of c.NotifyOnFailure. This method is used to work around ambiguity of unmarshalling yaml boolean values, due to the default value of a bool being false.

func (Command) String

func (c Command) String() string

String returns a string representation of the command

func (Command) WithEnv

func (c Command) WithEnv(env ...string) *exec.Cmd

WithEnv returns a runnable command with the given environment variables added. Command STDOUT and STDERR is attached to the logger.

type CommandResult

type CommandResult struct {
	Kind Result
	Err  error
}

type Result

type Result int
const (
	// Enum mask for kinds of results
	CmdOk      Result = 1 << iota
	CmdFail    Result = 1 << iota
	CmdSigOk   Result = 1 << iota
	CmdSigFail Result = 1 << iota
	CmdSkipSig Result = 1 << iota
)

func (Result) Has

func (r Result) Has(flag Result) bool

Has returns true if the result has the given flag set

func (Result) String

func (r Result) String() string

Return a string representing the result state

Jump to

Keyboard shortcuts

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