fz

package
v0.0.21 Latest Latest
Warning

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

Go to latest
Published: May 14, 2024 License: BSD-2-Clause Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	STATE_UNKNOWN = State(iota)
	STATE_FAIL
	STATE_OK
)
View Source
const DEFAULT_FREQUENCY_SECONDS = 300
View Source
const DEFAULT_PRIORITY = 5
View Source
const DEFAULT_RETRIES = 5
View Source
const DEFAULT_TIMEOUT_SECONDS = 5
View Source
const GRACE_TIME = time.Duration(500) * time.Millisecond

Variables

View Source
var DAEMON_START_TIME = time.Now()
View Source
var Logger *slog.Logger
View Source
var NotifyCh = make(chan Notification, 100)

Functions

func Fatal added in v0.0.20

func Fatal(ss ...string)

func ProcessNotifications

func ProcessNotifications()

func StartLogger

func StartLogger(l string)

Types

type Config

type Config struct {
	Defaults      Defaults
	LogLevel      string     `toml:"log_level"`
	Notifiers     []Notifier `toml:"notifier"`
	Tasks         []Task     `toml:"task"`
	Gates         []Gate     `toml:"gate"`
	ListenAddress string     `toml:"listen_address"`
	Directory     string     `toml:"directory"`
}

func ReadConfig

func ReadConfig() Config

func (Config) Listen

func (c Config) Listen() bool

type Defaults

type Defaults struct {
	FrequencySeconds      int      `toml:"frequency"`
	NotifierNames         []string `toml:"notifiers"`
	Retries               int      `toml:"retries"`
	RetryFrequencySeconds int      `toml:"retry_frequency"`
	TimeoutSeconds        int      `toml:"timeout"` // better to put the timeout into the commmand
	Priority              int      `toml:"priority"`
}

type Gate

type Gate struct {
	Name    string   `toml:"name"`    // friendly name
	Command string   `toml:"command"` // command
	Args    []string `toml:"args"`    // command arguments
}

func GateByName added in v0.0.20

func GateByName(name string) (*Gate, error)

func (Gate) IsOpen

func (g Gate) IsOpen(t *Task, n *Notifier) bool

type Notification

type Notification struct {
	Notifier *Notifier
	Task     *Task
}

type Notifier

type Notifier struct {
	Name           string
	Command        string
	Args           []string
	GateSets       [][]string `toml:"gates"`
	TimeoutSeconds int        `toml:"timeout"`
	// contains filtered or unexported fields
}

func NotifierByName added in v0.0.20

func NotifierByName(name string) *Notifier

func (Notifier) Gates added in v0.0.20

func (n Notifier) Gates() [][]*Gate

type State

type State int8

func (State) String

func (s State) String() string

type Task

type Task struct {
	Name                  string   `toml:"name"`            // friendly name
	Command               string   `toml:"command"`         // command
	Args                  []string `toml:"args"`            // command arguments
	FrequencySeconds      int      `toml:"frequency"`       // how often to run
	RetryFrequencySeconds int      `toml:"retry_frequency"` // how quickly to retry when state unknown
	TimeoutSeconds        int      `toml:"timeout"`         // how long an execution may run
	Retries               int      `toml:"retries"`         // number of retries before changing the state
	NotifierNames         []string `toml:"notifiers"`       // notifiers to trigger upon state change
	Priority              int      `toml:"priority"`        // the priority of the notifications
	ErrorBody             string   `toml:"error_body"`      // the body of the notification when entering an error state
	RecoverBody           string   `toml:"recover_body"`    // the body of the notification when recovering from an error state

	// public, but not configurable
	ErrorCount       int       // task failed to executed
	ExecutionCount   int       // task was executed
	FailCount        int       // task failed
	History          uint32    // represented in binary. Successes are high
	HistoryMask      uint32    // the bits in the history with a recorded value. Needed to understand a history of 0
	LastFail         time.Time // the time of the last failed execution
	LastOk           time.Time // the time of the last successfull execution
	LastResultOutput string    // the result output of the last execution
	LastRun          time.Time // the time of the last execution
	OKCount          int       // task passed
	// contains filtered or unexported fields
}

func (Task) ExpandArgs

func (t Task) ExpandArgs() []string

return the arguments after interpolating the values

func (Task) Frequency

func (t Task) Frequency() time.Duration

how often to run

func (Task) GetLastNotification added in v0.0.20

func (t Task) GetLastNotification(name string) time.Time

func (Task) Hash

func (t Task) Hash() uint32

func (Task) LastNotification added in v0.0.21

func (t Task) LastNotification() time.Time

get the last notification of all notifiers.

func (Task) LastState

func (t Task) LastState() State

step back though the data to find the previous state

func (Task) NotifierIndex added in v0.0.20

func (t Task) NotifierIndex(name string) (int, error)

func (Task) Ready

func (t Task) Ready(ts time.Time) bool

func (*Task) RecordStatus

func (t *Task) RecordStatus(b bool)

func (*Task) Run

func (t *Task) Run() bool

func (*Task) SetLastNotification added in v0.0.20

func (t *Task) SetLastNotification(name string, ts time.Time) error

func (Task) State

func (t Task) State() State

extract the current state from the history

func (Task) StateChanged

func (t Task) StateChanged() bool

if the state changed

Jump to

Keyboard shortcuts

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