这是indexloc提供的服务,不要输入任何密码
Skip to content
This repository was archived by the owner on Feb 13, 2025. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 45 additions & 6 deletions cmd/bosun/sched/sched.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,18 @@ func (states States) Copy() States {
return newStates
}

func (s *Schedule) GetOpenStates() States {
s.Lock("GetOpenStates")
defer s.Unlock()
states := s.status.Copy()
for k, state := range states {
if !state.Open {
delete(states, k)
}
}
return states
}

type StateGroup struct {
Active bool `json:",omitempty"`
Status Status
Expand Down Expand Up @@ -358,7 +370,6 @@ func (s *Schedule) MarshalGroups(T miniprofiler.Timer, filter string) (*StateGro
s.Lock("MarshallGroups")
defer s.Unlock()
T.Step("Setup", func(miniprofiler.Timer) {

matches, err2 := makeFilter(filter)
if err2 != nil {
err = err2
Expand Down Expand Up @@ -961,6 +972,14 @@ func (s *Schedule) GetIncidentEvents(id uint64) (*Incident, []Event, []Action, e
return incident, list, actions, nil
}

type IncidentStatus struct {
IncidentID uint64
AlertKey expr.AlertKey
Status Status
Subject string
Silenced bool
}

func (s *Schedule) Host(filter string) (map[string]*HostData, error) {
hosts := make(map[string]*HostData)
allHosts, err := s.Search.TagValuesByTagKey("host", time.Hour*7*24)
Expand All @@ -970,8 +989,26 @@ func (s *Schedule) Host(filter string) (map[string]*HostData, error) {
for _, h := range allHosts {
hosts[h] = newHostData()
}
states := s.GetOpenStates()
silences := s.Silenced()
for name, host := range hosts {
host.Name = name
for ak, state := range states {
if stateHost, ok := state.Group["host"]; !ok {
continue
} else if stateHost != host.Name {
continue
}
_, silenced := silences[ak]
is := IncidentStatus{
IncidentID: state.Last().IncidentId,
AlertKey: state.AlertKey(),
Status: state.Status(),
Subject: state.Subject,
Silenced: silenced,
}
host.OpenIncidentIDs = append(host.OpenIncidentIDs, is)
}
md, err := s.GetMetadata("", opentsdb.TagSet{"host": name})
if err != nil {
slog.Error(err)
Expand Down Expand Up @@ -1058,6 +1095,7 @@ func newHostData() *HostData {
hd.CPU.Processors = make(map[string]string)
hd.Interfaces = make(map[string]*HostInterface)
hd.Memory.Modules = make(map[string]string)
hd.OpenIncidentIDs = make([]IncidentStatus, 0)
return hd
}

Expand All @@ -1068,11 +1106,12 @@ type HostData struct {
Used float64 `json:",omitempty"`
Processors map[string]string `json:",omitempty"`
}
Interfaces map[string]*HostInterface
LastBoot int64 `json:",omitempty"`
LastUpdate int64 `json:",omitempty"`
Manufacturer string `json:",omitempty"`
Memory struct {
OpenIncidentIDs []IncidentStatus
Interfaces map[string]*HostInterface
LastBoot int64 `json:",omitempty"`
LastUpdate int64 `json:",omitempty"`
Manufacturer string `json:",omitempty"`
Memory struct {
Modules map[string]string `json:",omitempty"`
Total int64 `json:",omitempty"`
Used int64 `json:",omitempty"`
Expand Down