Implement 'inteval' config parameter -> number of seconds between checks
This commit is contained in:
@@ -12,17 +12,21 @@ const timeout = time.Duration(time.Second)
|
||||
|
||||
// Monitor data model
|
||||
type Monitor struct {
|
||||
Name string `json:"name"`
|
||||
URL string `json:"url"`
|
||||
MetricID int `json:"metric_id"`
|
||||
Threshold float32 `json:"threshold"`
|
||||
ComponentID *int `json:"component_id"`
|
||||
ExpectedStatusCode int `json:"expected_status_code"`
|
||||
StrictTLS *bool `json:"strict_tls"`
|
||||
Name string `json:"name"`
|
||||
URL string `json:"url"`
|
||||
MetricID int `json:"metric_id"`
|
||||
Threshold float32 `json:"threshold"`
|
||||
ComponentID *int `json:"component_id"`
|
||||
ExpectedStatusCode int `json:"expected_status_code"`
|
||||
StrictTLS *bool `json:"strict_tls"`
|
||||
Interval time.Duration `json:"interval"`
|
||||
|
||||
History []bool `json:"-"`
|
||||
LastFailReason *string `json:"-"`
|
||||
Incident *Incident `json:"-"`
|
||||
|
||||
// Closed when mon.Stop() is called
|
||||
stopC chan struct{} `json:"-"`
|
||||
}
|
||||
|
||||
// Run loop
|
||||
@@ -42,6 +46,26 @@ func (monitor *Monitor) Run() {
|
||||
}
|
||||
}
|
||||
|
||||
func (monitor *Monitor) Stop() {
|
||||
if monitor.Stopped() {
|
||||
return
|
||||
}
|
||||
close(monitor.stopC)
|
||||
}
|
||||
|
||||
func (monitor *Monitor) StopC() <-chan struct{} {
|
||||
return monitor.stopC
|
||||
}
|
||||
|
||||
func (monitor *Monitor) Stopped() bool {
|
||||
select {
|
||||
case <-monitor.stopC:
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
func (monitor *Monitor) doRequest() bool {
|
||||
client := &http.Client{
|
||||
Timeout: timeout,
|
||||
@@ -115,8 +139,8 @@ func (monitor *Monitor) AnalyseData() {
|
||||
|
||||
component_id := json.Number(strconv.Itoa(*monitor.ComponentID))
|
||||
monitor.Incident = &Incident{
|
||||
Name: monitor.Incident.Name,
|
||||
Message: monitor.Name + " check succeeded",
|
||||
Name: monitor.Incident.Name,
|
||||
Message: monitor.Name + " check succeeded",
|
||||
ComponentID: &component_id,
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user