feat(alerting): save alert state
This commit is contained in:
@@ -18,14 +18,16 @@ func (this AlertRuleReader) Fetch() []m.AlertRule {
|
||||
//{Id: 4, Title: "alert rule 4", Interval: "10s", Frequency: 5},
|
||||
//{Id: 5, Title: "alert rule 5", Interval: "10s", Frequency: 5},
|
||||
{
|
||||
Id: 6,
|
||||
Id: 1,
|
||||
OrgId: 1,
|
||||
Title: "alert rule 6",
|
||||
Title: "alert rule 1",
|
||||
Interval: "10s",
|
||||
Frequency: 3,
|
||||
DatasourceId: 1,
|
||||
WarnOperator: ">",
|
||||
WarnLevel: 100,
|
||||
WarnOperator: "<",
|
||||
WarnLevel: 3,
|
||||
CritOperator: "<",
|
||||
CritLevel: 4,
|
||||
Aggregator: "avg",
|
||||
Query: `{"refId":"A","target":"statsd.fakesite.counters.session_start.*.count","textEditor":true}"`,
|
||||
QueryRange: "1h",
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"time"
|
||||
|
||||
//"github.com/grafana/grafana/pkg/bus"
|
||||
"github.com/grafana/grafana/pkg/bus"
|
||||
"github.com/grafana/grafana/pkg/log"
|
||||
m "github.com/grafana/grafana/pkg/models"
|
||||
"github.com/grafana/grafana/pkg/setting"
|
||||
@@ -132,6 +133,14 @@ func (this *Scheduler) HandleResponses() {
|
||||
if this.jobs[response.Id] != nil {
|
||||
this.jobs[response.Id].running = false
|
||||
}
|
||||
cmd := m.UpdateAlertStateCommand{
|
||||
AlertId: response.Id,
|
||||
NewState: response.State,
|
||||
}
|
||||
|
||||
if err := bus.Dispatch(&cmd); err != nil {
|
||||
log.Error(1, "failed to save state", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ func (this *ExecutorImpl) Execute(rule m.AlertRule, responseQueue chan *AlertRes
|
||||
response, err := graphite.GraphiteClient{}.GetSeries(rule)
|
||||
|
||||
if err != nil {
|
||||
responseQueue <- &AlertResult{State: "CRITICAL", Id: rule.Id}
|
||||
responseQueue <- &AlertResult{State: "PENDING", Id: rule.Id}
|
||||
}
|
||||
|
||||
responseQueue <- this.ValidateRule(rule, response)
|
||||
|
||||
@@ -48,7 +48,7 @@ func (this GraphiteClient) GetSeries(rule m.AlertRule) (m.TimeSeriesSlice, error
|
||||
}
|
||||
|
||||
if res.StatusCode != http.StatusOK {
|
||||
return nil, fmt.Errorf("error!")
|
||||
return nil, fmt.Errorf("expected httpstatus 200, found %d", res.StatusCode)
|
||||
}
|
||||
|
||||
timeSeries := make([]*m.TimeSeries, 0)
|
||||
|
||||
Reference in New Issue
Block a user