Only add stateChangesOnly to new rules

- New rules default to a blank id
- Check for blank id before adding stateChangesOnly
pull/10616/head
Brandon Farmer 2018-04-04 14:26:16 -07:00
parent 58ad7fe3cd
commit c2b8b9c51c
3 changed files with 11 additions and 3 deletions

View File

@ -1306,7 +1306,7 @@ func TestClient_Create(t *testing.T) {
args: args{
ctx: context.Background(),
rule: chronograf.AlertRule{
ID: "howdy",
ID: "",
Name: "myname's",
Query: &chronograf.QueryConfig{
Database: "db",
@ -1456,7 +1456,7 @@ trigger
args: args{
ctx: context.Background(),
rule: chronograf.AlertRule{
ID: "howdy",
ID: "",
Name: "myname's",
Query: &chronograf.QueryConfig{
Database: "db",

View File

@ -23,7 +23,6 @@ const (
// AllAlerts are properties all alert types will have
var AllAlerts = `
.stateChangesOnly()
.message(message)
.id(idVar)
.idTag(idTag)
@ -113,7 +112,15 @@ func Trigger(rule chronograf.AlertRule) (string, error) {
return "", err
}
// Only add stateChangesOnly to new rules
if rule.ID == "" {
trigger += `
.stateChangesOnly()
`
}
trigger += AllAlerts
if rule.Details != "" {
trigger += Details
}

View File

@ -339,6 +339,7 @@ func (s *Service) KapacitorRulesPost(w http.ResponseWriter, r *http.Request) {
}
*/
req.ID = ""
task, err := c.Create(ctx, req)
if err != nil {
invalidData(w, err, s.Logger)