Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: slack, tcp, http:data and response md5sum and length check #126

Open
wants to merge 24 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
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
Prev Previous commit
Next Next commit
go fmt
A. Feldmann authored and galexrt committed Jan 8, 2020

Verified

This commit was signed with the committer’s verified signature.
galexrt Alexander Trost
commit 33bb722e06fe22b9853377a3fc62e6aec542807b
5 changes: 5 additions & 0 deletions cli/main.go
Original file line number Diff line number Diff line change
@@ -38,6 +38,7 @@ Options:
-h --help Show this screen.
--version Show version
--immediate Tick immediately (by default waits for first defined interval)
--restarted Get open incidents before start monitoring (if monitor died or restarted)
Environment varaibles:
CACHET_API override API url from configuration
@@ -58,6 +59,10 @@ func main() {
cfg.Immediate = immediate.(bool)
}

if restarted, ok := arguments["--restarted"]; ok {
cfg.Restarted = restarted.(bool)
}

if name := arguments["--name"]; name != nil {
cfg.SystemName = name.(string)
}
1 change: 1 addition & 0 deletions config.go
Original file line number Diff line number Diff line change
@@ -17,6 +17,7 @@ type CachetMonitor struct {

Monitors []MonitorInterface `json:"-" yaml:"-"`
Immediate bool `json:"-" yaml:"-"`
Restarted bool `json:"-" yaml:"-"`
}

// Validate configuration
26 changes: 26 additions & 0 deletions incident.go
Original file line number Diff line number Diff line change
@@ -21,6 +21,32 @@ type Incident struct {
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
func (incident *Incident) Send(cfg *CachetMonitor) error {
switch incident.Status {
10 changes: 10 additions & 0 deletions monitor.go
Original file line number Diff line number Diff line change
@@ -118,6 +118,16 @@ func (mon *AbstractMonitor) ClockStart(cfg *CachetMonitor, iface MonitorInterfac
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)
for {
select {
1 change: 1 addition & 0 deletions readme.md
Original file line number Diff line number Diff line change
@@ -111,6 +111,7 @@ Options:
-h --help Show this screen.
--version Show version
--immediate Tick immediately (by default waits for first defined interval)
--restarted Get open incidents before start monitoring (if monitor died or restarted)
Environment varaibles:
CACHET_API override API url from configuration