go fmt
This commit is contained in:
committed by
Alexander Trost
parent
3c343fb0a2
commit
33bb722e06
@@ -38,6 +38,7 @@ Options:
|
|||||||
-h --help Show this screen.
|
-h --help Show this screen.
|
||||||
--version Show version
|
--version Show version
|
||||||
--immediate Tick immediately (by default waits for first defined interval)
|
--immediate Tick immediately (by default waits for first defined interval)
|
||||||
|
--restarted Get open incidents before start monitoring (if monitor died or restarted)
|
||||||
|
|
||||||
Environment varaibles:
|
Environment varaibles:
|
||||||
CACHET_API override API url from configuration
|
CACHET_API override API url from configuration
|
||||||
@@ -58,6 +59,10 @@ func main() {
|
|||||||
cfg.Immediate = immediate.(bool)
|
cfg.Immediate = immediate.(bool)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if restarted, ok := arguments["--restarted"]; ok {
|
||||||
|
cfg.Restarted = restarted.(bool)
|
||||||
|
}
|
||||||
|
|
||||||
if name := arguments["--name"]; name != nil {
|
if name := arguments["--name"]; name != nil {
|
||||||
cfg.SystemName = name.(string)
|
cfg.SystemName = name.(string)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ type CachetMonitor struct {
|
|||||||
|
|
||||||
Monitors []MonitorInterface `json:"-" yaml:"-"`
|
Monitors []MonitorInterface `json:"-" yaml:"-"`
|
||||||
Immediate bool `json:"-" yaml:"-"`
|
Immediate bool `json:"-" yaml:"-"`
|
||||||
|
Restarted bool `json:"-" yaml:"-"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate configuration
|
// Validate configuration
|
||||||
|
|||||||
26
incident.go
26
incident.go
@@ -21,6 +21,32 @@ type Incident struct {
|
|||||||
ComponentStatus int `json:"component_status"`
|
ComponentStatus int `json:"component_status"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Get the last still open incident
|
||||||
|
func (mon *AbstractMonitor) Get(cfg *CachetMonitor) (*Incident, error) {
|
||||||
|
requestType := "GET"
|
||||||
|
requestURL := fmt.Sprintf("/incidents?component_id=%d", mon.ComponentID)
|
||||||
|
_, body, err := cfg.API.NewRequest(requestType, requestURL, nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
data := make([]Incident, 0)
|
||||||
|
if err := json.Unmarshal(body.Data, &data); err != nil {
|
||||||
|
return nil, fmt.Errorf("Cannot parse incident body: %v, %v", err, string(body.Data))
|
||||||
|
}
|
||||||
|
//filter out resolved incidents
|
||||||
|
openIncidents := make([]Incident, 0)
|
||||||
|
for _, i := range data {
|
||||||
|
if i.Status < 4 {
|
||||||
|
openIncidents = append(openIncidents, i)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if len(openIncidents) == 0 {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
return &openIncidents[0], nil
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
// Send - Create or Update incident
|
// Send - Create or Update incident
|
||||||
func (incident *Incident) Send(cfg *CachetMonitor) error {
|
func (incident *Incident) Send(cfg *CachetMonitor) error {
|
||||||
switch incident.Status {
|
switch incident.Status {
|
||||||
|
|||||||
10
monitor.go
10
monitor.go
@@ -118,6 +118,16 @@ func (mon *AbstractMonitor) ClockStart(cfg *CachetMonitor, iface MonitorInterfac
|
|||||||
mon.tick(iface)
|
mon.tick(iface)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if cfg.Restarted {
|
||||||
|
initialIncident, err := mon.Get(cfg)
|
||||||
|
if err != nil {
|
||||||
|
logrus.Warn("could not fetch initial incident: %v", err)
|
||||||
|
}
|
||||||
|
if initialIncident != nil {
|
||||||
|
mon.incident = initialIncident
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ticker := time.NewTicker(mon.Interval * time.Second)
|
ticker := time.NewTicker(mon.Interval * time.Second)
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
|
|||||||
@@ -111,6 +111,7 @@ Options:
|
|||||||
-h --help Show this screen.
|
-h --help Show this screen.
|
||||||
--version Show version
|
--version Show version
|
||||||
--immediate Tick immediately (by default waits for first defined interval)
|
--immediate Tick immediately (by default waits for first defined interval)
|
||||||
|
--restarted Get open incidents before start monitoring (if monitor died or restarted)
|
||||||
|
|
||||||
Environment varaibles:
|
Environment varaibles:
|
||||||
CACHET_API override API url from configuration
|
CACHET_API override API url from configuration
|
||||||
|
|||||||
Reference in New Issue
Block a user