Commit 51511dd6 by bergquist

feat(alerting): save alert state

parent 1686d86c
...@@ -18,14 +18,16 @@ func (this AlertRuleReader) Fetch() []m.AlertRule { ...@@ -18,14 +18,16 @@ func (this AlertRuleReader) Fetch() []m.AlertRule {
//{Id: 4, Title: "alert rule 4", Interval: "10s", Frequency: 5}, //{Id: 4, Title: "alert rule 4", Interval: "10s", Frequency: 5},
//{Id: 5, Title: "alert rule 5", Interval: "10s", Frequency: 5}, //{Id: 5, Title: "alert rule 5", Interval: "10s", Frequency: 5},
{ {
Id: 6, Id: 1,
OrgId: 1, OrgId: 1,
Title: "alert rule 6", Title: "alert rule 1",
Interval: "10s", Interval: "10s",
Frequency: 3, Frequency: 3,
DatasourceId: 1, DatasourceId: 1,
WarnOperator: ">", WarnOperator: "<",
WarnLevel: 100, WarnLevel: 3,
CritOperator: "<",
CritLevel: 4,
Aggregator: "avg", Aggregator: "avg",
Query: `{"refId":"A","target":"statsd.fakesite.counters.session_start.*.count","textEditor":true}"`, Query: `{"refId":"A","target":"statsd.fakesite.counters.session_start.*.count","textEditor":true}"`,
QueryRange: "1h", QueryRange: "1h",
......
...@@ -6,6 +6,7 @@ import ( ...@@ -6,6 +6,7 @@ import (
"time" "time"
//"github.com/grafana/grafana/pkg/bus" //"github.com/grafana/grafana/pkg/bus"
"github.com/grafana/grafana/pkg/bus"
"github.com/grafana/grafana/pkg/log" "github.com/grafana/grafana/pkg/log"
m "github.com/grafana/grafana/pkg/models" m "github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/setting" "github.com/grafana/grafana/pkg/setting"
...@@ -132,6 +133,14 @@ func (this *Scheduler) HandleResponses() { ...@@ -132,6 +133,14 @@ func (this *Scheduler) HandleResponses() {
if this.jobs[response.Id] != nil { if this.jobs[response.Id] != nil {
this.jobs[response.Id].running = false 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 ...@@ -34,7 +34,7 @@ func (this *ExecutorImpl) Execute(rule m.AlertRule, responseQueue chan *AlertRes
response, err := graphite.GraphiteClient{}.GetSeries(rule) response, err := graphite.GraphiteClient{}.GetSeries(rule)
if err != nil { if err != nil {
responseQueue <- &AlertResult{State: "CRITICAL", Id: rule.Id} responseQueue <- &AlertResult{State: "PENDING", Id: rule.Id}
} }
responseQueue <- this.ValidateRule(rule, response) responseQueue <- this.ValidateRule(rule, response)
......
...@@ -48,7 +48,7 @@ func (this GraphiteClient) GetSeries(rule m.AlertRule) (m.TimeSeriesSlice, error ...@@ -48,7 +48,7 @@ func (this GraphiteClient) GetSeries(rule m.AlertRule) (m.TimeSeriesSlice, error
} }
if res.StatusCode != http.StatusOK { 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) timeSeries := make([]*m.TimeSeries, 0)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment