sched

package
Version: v0.0.0-...-0df215e Latest Latest
Warning

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

Go to latest
Published: Jan 7, 2016 License: MIT Imports: 47 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultSched = &Schedule{}

Functions

func Autostyle

func Autostyle(i int) chart.Style

Autostyle styles a chart series.

func Close

func Close()

func Load

func Load(c *conf.Conf) error

Load loads a configuration into the default schedule.

func Run

func Run() error

Run runs the default schedule.

Types

type Action

type Action struct {
	User    string
	Message string
	Time    time.Time
	Type    ActionType
}

type ActionType

type ActionType int
const (
	ActionNone ActionType = iota
	ActionAcknowledge
	ActionClose
	ActionForget
)

func (ActionType) MarshalJSON

func (a ActionType) MarshalJSON() ([]byte, error)

func (ActionType) String

func (a ActionType) String() string

type Battery

type Battery struct {
	Status            string
	StatusLastUpdated int64
}

type BoardPowerReading

type BoardPowerReading struct {
	Watts            int64
	WattsLastUpdated int64
}

type CDPCacheEntries

type CDPCacheEntries []CDPCacheEntry

type CDPCacheEntry

type CDPCacheEntry struct {
	DeviceID   string
	DevicePort string
}

Cisco Discovery Protocol

type ChassisComponent

type ChassisComponent struct {
	Status            string
	StatusLastUpdated int64
}

type Context

type Context struct {
	*State
	Alert   *conf.Alert
	IsEmail bool

	Attachments []*conf.Attachment
	// contains filtered or unexported fields
}

func (*Context) Ack

func (c *Context) Ack() string

Ack returns the URL to acknowledge an alert.

func (*Context) Eval

func (c *Context) Eval(v interface{}) (interface{}, error)

Eval takes a result or an expression which it evaluates to a result. It returns a value with tags corresponding to the context's tags. If no such result is found, the first result with nil tags is returned. If no such result is found, nil is returned.

func (*Context) EvalAll

func (c *Context) EvalAll(v interface{}) (interface{}, error)

EvalAll returns the executed expression (or the given result as is).

func (*Context) Expr

func (c *Context) Expr(v string) string

Expr takes an expression in the form of a string, changes the tags to match the context of the alert, and returns a link to the expression page.

func (*Context) GetMeta

func (c *Context) GetMeta(metric, name string, v interface{}) (interface{}, error)

func (*Context) Graph

func (c *Context) Graph(v interface{}, args ...string) (interface{}, error)

Graph returns an SVG for the given result (or expression, for which it gets the result) with same tags as the context's tags.

func (*Context) GraphAll

func (c *Context) GraphAll(v interface{}, args ...string) (interface{}, error)

GraphAll returns an SVG for the given result (or expression, for which it gets the result).

func (c *Context) GraphLink(v string) string

GraphLink takes an expression in the form of a string, and returns a link to the expression page's graph tab with the time set.

func (*Context) HTTPGet

func (c *Context) HTTPGet(url string) string

func (*Context) HTTPGetJSON

func (c *Context) HTTPGetJSON(url string) (*jsonq.JsonQuery, error)

func (*Context) HTTPPost

func (c *Context) HTTPPost(url, bodyType, data string) string

func (*Context) HostView

func (c *Context) HostView(host string) string

HostView returns the URL to the host view page.

func (*Context) Incident

func (c *Context) Incident() string

func (*Context) LSQuery

func (c *Context) LSQuery(index_root, filter, sduration, eduration string, size int) (interface{}, error)

func (*Context) LSQueryAll

func (c *Context) LSQueryAll(index_root, keystring, filter, sduration, eduration string, size int) (interface{}, error)

func (*Context) LeftJoin

func (c *Context) LeftJoin(v ...interface{}) (interface{}, error)

LeftJoin takes slices of results and expressions for which it gets the slices of results. Then it joins the 2nd and higher slice of results onto the first slice of results. Joining is performed by group: a group that includes all tags (with same values) of the first group is a match.

func (*Context) Lookup

func (c *Context) Lookup(table, key string) (string, error)

Lookup returns the value for a key in the lookup table for the context's tagset.

func (*Context) LookupAll

func (c *Context) LookupAll(table, key string, group interface{}) (string, error)

func (*Context) Rule

func (c *Context) Rule() (string, error)

type Controller

type Controller struct {
	Status            string
	StatusLastUpdated int64
	metadata.HWControllerMeta
}

type Disk

type Disk struct {
	UsedBytes        int64
	TotalBytes       int64
	Label            string `json:",omitempty"`
	StatsLastUpdated int64
}

type Event

type Event struct {
	Warn, Crit  *Result
	Status      Status
	Time        time.Time
	Unevaluated bool
	IncidentId  uint64
}

type Hardware

type Hardware struct {
	Memory            map[string]*MemoryModule     `json:",omitempty"`
	ChassisComponents map[string]*ChassisComponent `json:",omitempty"`
	Storage           struct {
		Controllers   map[string]*Controller   `json:",omitempty"`
		PhysicalDisks map[string]*PhysicalDisk `json:",omitempty"`
		VirtualDisks  map[string]*VirtualDisk  `json:",omitempty"`
		Batteries     map[string]*Battery
	}
	Temps             map[string]*Temp
	PowerSupplies     map[string]*PowerSupply `json:",omitempty"`
	BoardPowerReading *BoardPowerReading
}

type HostData

type HostData struct {
	CPU struct {
		Logical          int64 `json:",omitempty"`
		Physical         int64 `json:",omitempty"`
		PercentUsed      float64
		StatsLastUpdated int64
		Processors       map[string]string `json:",omitempty"`
	}
	ICMPData      map[string]*ICMPData
	Disks         map[string]*Disk
	OpenIncidents []IncidentStatus
	Interfaces    map[string]*HostInterface
	UptimeSeconds int64     `json:",omitempty"`
	Manufacturer  string    `json:",omitempty"`
	Hardware      *Hardware `json:",omitempty"`
	Memory        struct {
		TotalBytes       float64
		UsedBytes        float64
		StatsLastUpdated int64
	}
	Processes map[string]*Process       `json:",omitempty"`
	Services  map[string]*ServiceStatus `json:",omitempty"`
	Model     string                    `json:",omitempty"`
	Name      string                    `json:",omitempty"`
	OS        struct {
		Caption string `json:",omitempty"`
		Version string `json:",omitempty"`
	}
	SerialNumber string   `json:",omitempty"`
	VM           *VM      `json:",omitempty"`
	Guests       []string `json:",omitempty"`
}

func (*HostData) Clean

func (hd *HostData) Clean()

Clean sets certain maps to nil so they don't get marshalled in JSON The logic is to remove ones that monitored devices might lack, such as hardware information

type HostInterface

type HostInterface struct {
	Description      string          `json:",omitempty"`
	IPAddresses      []string        `json:",omitempty"`
	RemoteMacs       []string        `json:",omitempty"`
	CDPCacheEntries  CDPCacheEntries `json:",omitempty"`
	Inbps            int64
	LinkSpeed        int64  `json:",omitempty"`
	MAC              string `json:",omitempty"`
	Master           string `json:",omitempty"`
	Name             string `json:",omitempty"`
	Outbps           int64
	StatsLastUpdated int64
	Type             string
}

type ICMPData

type ICMPData struct {
	TimedOut               bool
	TimedOutLastUpdated    int64
	DNSResolved            bool
	DNSResolvedLastUpdated int64
	RTTMS                  float64
	RTTLastUpdated         int64
}

type IncidentStatus

type IncidentStatus struct {
	IncidentID         uint64
	Active             bool
	AlertKey           models.AlertKey
	Status             Status
	StatusTime         int64
	Subject            string
	Silenced           bool
	LastAbnormalStatus Status
	LastAbnormalTime   int64
	NeedsAck           bool
}

type MemoryModule

type MemoryModule struct {
	// Maybe this should be a bool but that might be limiting
	Status            string
	StatusLastUpdated int64
	Size              string
}

type PhysicalDisk

type PhysicalDisk struct {
	Status            string
	StatusLastUpdated int64
	metadata.HWDiskMeta
}

type PowerSupply

type PowerSupply struct {
	Status                     string
	StatusLastUpdated          int64
	Amps                       float64
	AmpsLastUpdated            int64
	Volts                      float64
	VoltsLastUpdated           int64
	metadata.HWPowerSupplyMeta //Should be renamed to Meta
}

type Process

type Process struct {
	CPUPercentUsed              float64
	CPUPercentLastUpdated       int64
	UsedRealBytes               int64
	UsedRealBytesLastUpdated    int64
	UsedVirtualBytes            int64
	UsedVirtualBytesLastUpdated int64
	Count                       int64
	CountLastUpdated            int64
}

type Result

type Result struct {
	*expr.Result
	Expr string
}

func (*Result) Copy

func (r *Result) Copy() *Result

type RunHistory

type RunHistory struct {
	Cache           *cache.Cache
	Start           time.Time
	Context         opentsdb.Context
	GraphiteContext graphite.Context
	InfluxConfig    client.Config
	Logstash        expr.LogstashElasticHosts
	Events          map[models.AlertKey]*Event
	// contains filtered or unexported fields
}

func (*RunHistory) AtTime

func (rh *RunHistory) AtTime(t time.Time) *RunHistory

AtTime creates a new RunHistory starting at t with the same context and events as rh.

func (*RunHistory) GetUnknownAndUnevaluatedAlertKeys

func (r *RunHistory) GetUnknownAndUnevaluatedAlertKeys(alert string) (unknown, uneval []models.AlertKey)

type Schedule

type Schedule struct {
	Conf *conf.Conf

	Group map[time.Time]models.AlertKeys

	Search *search.Search

	//notifications we are currently tracking, potentially with future or repeated actions.
	Notifications map[models.AlertKey]map[string]time.Time

	LastCheck time.Time

	DataAccess database.DataAccess
	// contains filtered or unexported fields
}

func (*Schedule) Action

func (s *Schedule) Action(user, message string, t ActionType, ak models.AlertKey) error

func (*Schedule) ActionNotify

func (s *Schedule) ActionNotify(at ActionType, user, message string, aks []models.AlertKey)

func (*Schedule) AddNotification

func (s *Schedule) AddNotification(ak models.AlertKey, n *conf.Notification, started time.Time)

func (*Schedule) AddSilence

func (s *Schedule) AddSilence(start, end time.Time, alert, tagList string, forget, confirm bool, edit, user, message string) (map[models.AlertKey]bool, error)

func (*Schedule) AlertSuccessful

func (s *Schedule) AlertSuccessful(name string) bool

func (*Schedule) CheckAlert

func (s *Schedule) CheckAlert(T miniprofiler.Timer, r *RunHistory, a *conf.Alert)

func (*Schedule) CheckExpr

func (s *Schedule) CheckExpr(T miniprofiler.Timer, rh *RunHistory, a *conf.Alert, e *expr.Expr, checkStatus Status, ignore models.AlertKeys) (alerts models.AlertKeys, err error)

func (*Schedule) CheckNotifications

func (s *Schedule) CheckNotifications() time.Duration

CheckNotifications processes past notification events. It returns the duration until the soonest notification triggers.

func (*Schedule) ClearErrors

func (s *Schedule) ClearErrors(alert string) error

func (*Schedule) ClearSilence

func (s *Schedule) ClearSilence(id string) error

func (*Schedule) Close

func (s *Schedule) Close()

func (*Schedule) CollectStates

func (s *Schedule) CollectStates()

CollectStates sends various state information to bosun with collect.

func (*Schedule) Data

func (s *Schedule) Data(rh *RunHistory, st *State, a *conf.Alert, isEmail bool) *Context

func (*Schedule) DeleteMetadata

func (s *Schedule) DeleteMetadata(tags opentsdb.TagSet, name string) error

func (*Schedule) ExecuteBadTemplate

func (s *Schedule) ExecuteBadTemplate(errs []error, rh *RunHistory, a *conf.Alert, st *State) (subject, body []byte, err error)

func (*Schedule) ExecuteBody

func (s *Schedule) ExecuteBody(rh *RunHistory, a *conf.Alert, st *State, isEmail bool) ([]byte, []*conf.Attachment, error)

func (*Schedule) ExecuteSubject

func (s *Schedule) ExecuteSubject(rh *RunHistory, a *conf.Alert, st *State, isEmail bool) ([]byte, error)

func (*Schedule) ExprGraph

func (s *Schedule) ExprGraph(t miniprofiler.Timer, unit string, res []*expr.Result) (chart.Chart, error)

func (*Schedule) ExprPNG

func (s *Schedule) ExprPNG(t miniprofiler.Timer, w io.Writer, width, height int, unit string, res []*expr.Result) error

func (*Schedule) ExprSVG

func (s *Schedule) ExprSVG(t miniprofiler.Timer, w io.Writer, width, height int, unit string, res []*expr.Result) error

func (*Schedule) GetIncident

func (s *Schedule) GetIncident(id uint64) (*models.Incident, error)

func (*Schedule) GetIncidentEvents

func (s *Schedule) GetIncidentEvents(id uint64) (*models.Incident, []Event, []Action, error)

func (*Schedule) GetIncidents

func (s *Schedule) GetIncidents(alert string, from, to time.Time) ([]*models.Incident, error)

func (*Schedule) GetLockStatus

func (s *Schedule) GetLockStatus() (holder string, since time.Time)

func (*Schedule) GetMetadata

func (s *Schedule) GetMetadata(metric string, subset opentsdb.TagSet) ([]metadata.Metasend, error)

func (*Schedule) GetOpenStates

func (s *Schedule) GetOpenStates() States

func (*Schedule) GetOrCreateStatus

func (s *Schedule) GetOrCreateStatus(ak models.AlertKey) *State

func (*Schedule) GetStateFileBackup

func (s *Schedule) GetStateFileBackup() ([]byte, error)

func (*Schedule) GetStatus

func (s *Schedule) GetStatus(ak models.AlertKey) *State

Get a copy of the status for the specified alert key

func (*Schedule) Host

func (s *Schedule) Host(filter string) (map[string]*HostData, error)

func (*Schedule) Init

func (s *Schedule) Init(c *conf.Conf) error

func (*Schedule) Load

func (s *Schedule) Load(c *conf.Conf) error

func (*Schedule) LoadTempConfig

func (s *Schedule) LoadTempConfig(hash string) (text string, err error)

Retreive the specified config text from state file.

func (*Schedule) Lock

func (s *Schedule) Lock(method string)

func (*Schedule) MarshalGroups

func (s *Schedule) MarshalGroups(T miniprofiler.Timer, filter string) (*StateGroups, error)

func (*Schedule) MetadataMetrics

func (s *Schedule) MetadataMetrics(metric string) (*database.MetricMetadata, error)

func (*Schedule) NewRunHistory

func (s *Schedule) NewRunHistory(start time.Time, cache *cache.Cache) *RunHistory

func (*Schedule) Notify

func (s *Schedule) Notify(st *State, n *conf.Notification)

func (*Schedule) PingHosts

func (s *Schedule) PingHosts()

func (*Schedule) PutMetadata

func (s *Schedule) PutMetadata(k metadata.Metakey, v interface{}) error

func (*Schedule) RestoreState

func (s *Schedule) RestoreState() error

RestoreState restores notification and alert state from the file on disk.

func (*Schedule) Run

func (s *Schedule) Run() error

Run should be called once (and only once) to start all schedule activity.

func (*Schedule) RunAlert

func (s *Schedule) RunAlert(a *conf.Alert)

func (*Schedule) RunHistory

func (s *Schedule) RunHistory(r *RunHistory)

RunHistory processes an event history and triggers notifications if needed.

func (*Schedule) SaveTempConfig

func (s *Schedule) SaveTempConfig(text string) (hash string, err error)

Saves the provided config text in state file for later access. Returns a hash of the file to be used as a retreival key.

func (*Schedule) SetStatus

func (s *Schedule) SetStatus(ak models.AlertKey, st *State)

func (*Schedule) Silenced

func (s *Schedule) Silenced() map[models.AlertKey]models.Silence

Silenced returns all currently silenced AlertKeys and the time they will be unsilenced.

func (*Schedule) Unlock

func (s *Schedule) Unlock()

type ServiceStatus

type ServiceStatus struct {
	Running            bool
	RunningLastUpdated int64
}

type State

type State struct {
	*Result

	// Most recent last.
	History      []Event  `json:",omitempty"`
	Actions      []Action `json:",omitempty"`
	Touched      time.Time
	Alert        string // helper data since AlertKeys don't serialize to JSON well
	Tags         string // string representation of Group
	Group        opentsdb.TagSet
	Subject      string
	Body         string
	EmailBody    []byte             `json:"-"`
	EmailSubject []byte             `json:"-"`
	Attachments  []*conf.Attachment `json:"-"`
	NeedAck      bool
	Open         bool
	Forgotten    bool
	Unevaluated  bool
	LastLogTime  time.Time
}

func NewStatus

func NewStatus(ak models.AlertKey) *State

func (*State) AbnormalEvent

func (s *State) AbnormalEvent() *Event

AbnormalEvent returns the most recent non-normal event, or nil if none found.

func (*State) AbnormalStatus

func (s *State) AbnormalStatus() Status

AbnormalStatus returns the most recent non-normal status, or StNone if none found.

func (*State) Action

func (s *State) Action(user, message string, t ActionType, timestamp time.Time)

func (*State) AlertKey

func (s *State) AlertKey() models.AlertKey

func (*State) Append

func (s *State) Append(event *Event) Status

Append appends status to the history if the status is different than the latest status. Returns the previous status.

func (*State) Copy

func (s *State) Copy() *State

func (*State) IsActive

func (s *State) IsActive() bool

func (*State) Last

func (s *State) Last() Event

func (*State) Status

func (s *State) Status() Status

func (*State) Touch

func (s *State) Touch()

func (*State) WorstThisIncident

func (s *State) WorstThisIncident() Status

WorstThisIncident returns the highest severity event with the same IncidentId as the Last event.

type StateGroup

type StateGroup struct {
	Active        bool `json:",omitempty"`
	Status        Status
	CurrentStatus Status
	Silenced      bool
	IsError       bool            `json:",omitempty"`
	Subject       string          `json:",omitempty"`
	Alert         string          `json:",omitempty"`
	AlertKey      models.AlertKey `json:",omitempty"`
	Ago           string          `json:",omitempty"`
	State         *State          `json:",omitempty"`
	Children      []*StateGroup   `json:",omitempty"`
}

type StateGroups

type StateGroups struct {
	Groups struct {
		NeedAck      []*StateGroup `json:",omitempty"`
		Acknowledged []*StateGroup `json:",omitempty"`
	}
	TimeAndDate                   []int
	FailingAlerts, UnclosedErrors int
}

type StateTuple

type StateTuple struct {
	NeedAck       bool
	Active        bool
	Status        Status
	CurrentStatus Status
	Silenced      bool
}

type States

type States map[models.AlertKey]*State

func (States) Copy

func (states States) Copy() States

func (States) GroupSets

func (states States) GroupSets(minGroup int) map[string]models.AlertKeys

GroupSets returns slices of TagSets, grouped by most common ancestor. Those with no shared ancestor are grouped by alert name.

func (States) GroupStates

func (states States) GroupStates(silenced map[models.AlertKey]models.Silence) map[StateTuple]States

GroupStates groups by NeedAck, Active, Status, and Silenced.

type Status

type Status int
const (
	StNone Status = iota
	StNormal
	StWarning
	StCritical
	StUnknown
)

func (Status) IsCritical

func (s Status) IsCritical() bool

func (Status) IsNormal

func (s Status) IsNormal() bool

func (Status) IsUnknown

func (s Status) IsUnknown() bool

func (Status) IsWarning

func (s Status) IsWarning() bool

func (Status) MarshalJSON

func (s Status) MarshalJSON() ([]byte, error)

func (Status) String

func (s Status) String() string

func (*Status) UnmarshalJSON

func (s *Status) UnmarshalJSON(b []byte) error

type Temp

type Temp struct {
	Celsius            float64
	Status             string
	StatusLastUpdated  int64
	CelsiusLastUpdated int64
}

type VM

type VM struct {
	Host                  string `json:",omitempty"`
	PowerState            string `json:",omitempty"`
	PowerStateLastUpdated int64  `json:",omitempty"`
}

type VirtualDisk

type VirtualDisk struct {
	Status            string
	StatusLastUpdated int64
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL