Browse Source

update upgrade cli

tags/v6.0.0-ga12
ning 3 years ago
parent
commit
1180f1fcfd
5 changed files with 74 additions and 7 deletions
  1. +17
    -2
      models/alert_cur_event.go
  2. +16
    -2
      models/alert_his_event.go
  3. +13
    -1
      models/alert_mute.go
  4. +15
    -1
      models/alert_rule.go
  5. +13
    -1
      models/alert_subscribe.go

+ 17
- 2
models/alert_cur_event.go View File

@@ -7,6 +7,7 @@ import (
"strconv"
"strings"
"text/template"
"time"

"github.com/ccfos/nightingale/v6/pkg/ctx"
"github.com/ccfos/nightingale/v6/pkg/tplx"
@@ -492,7 +493,7 @@ func (m *AlertCurEvent) UpdateFieldsMap(ctx *ctx.Context, fields map[string]inte

func AlertCurEventUpgradeToV6(ctx *ctx.Context, dsm map[string]Datasource) error {
var lst []*AlertCurEvent
err := DB(ctx).Find(&lst).Error
err := DB(ctx).Where("trigger_time > ?", time.Now().Unix()-3600*24*30).Find(&lst).Error
if err != nil {
return err
}
@@ -515,7 +516,21 @@ func AlertCurEventUpgradeToV6(ctx *ctx.Context, dsm map[string]Datasource) error
b, _ := json.Marshal(ruleConfig)
lst[i].RuleConfig = string(b)

err = lst[i].UpdateFieldsMap(ctx, map[string]interface{}{"datasource_id": lst[i].DatasourceId, "rule_config": lst[i].RuleConfig})
if lst[i].RuleProd == "" {
lst[i].RuleProd = METRIC
}

if lst[i].Cate == "" {
lst[i].Cate = PROMETHEUS
}

err = lst[i].UpdateFieldsMap(ctx, map[string]interface{}{
"datasource_id": lst[i].DatasourceId,
"rule_config": lst[i].RuleConfig,
"rule_prod": lst[i].RuleProd,
"cate": lst[i].Cate,
})

if err != nil {
logger.Errorf("update alert rule:%d datasource ids failed, %v", lst[i].Id, err)
}


+ 16
- 2
models/alert_his_event.go View File

@@ -4,6 +4,7 @@ import (
"encoding/json"
"strconv"
"strings"
"time"

"github.com/ccfos/nightingale/v6/pkg/ctx"
"github.com/toolkits/pkg/logger"
@@ -215,7 +216,7 @@ func (m *AlertHisEvent) UpdateFieldsMap(ctx *ctx.Context, fields map[string]inte

func AlertHisEventUpgradeToV6(ctx *ctx.Context, dsm map[string]Datasource) error {
var lst []*AlertHisEvent
err := DB(ctx).Find(&lst).Error
err := DB(ctx).Where("trigger_time > ?", time.Now().Unix()-3600*24*30).Find(&lst).Error
if err != nil {
return err
}
@@ -238,7 +239,20 @@ func AlertHisEventUpgradeToV6(ctx *ctx.Context, dsm map[string]Datasource) error
b, _ := json.Marshal(ruleConfig)
lst[i].RuleConfig = string(b)

err = lst[i].UpdateFieldsMap(ctx, map[string]interface{}{"datasource_id": lst[i].DatasourceId, "rule_config": lst[i].RuleConfig})
if lst[i].RuleProd == "" {
lst[i].RuleProd = METRIC
}

if lst[i].Cate == "" {
lst[i].Cate = PROMETHEUS
}

err = lst[i].UpdateFieldsMap(ctx, map[string]interface{}{
"datasource_id": lst[i].DatasourceId,
"rule_config": lst[i].RuleConfig,
"rule_prod": lst[i].RuleProd,
"cate": lst[i].Cate,
})
if err != nil {
logger.Errorf("update alert rule:%d datasource ids failed, %v", lst[i].Id, err)
}


+ 13
- 1
models/alert_mute.go View File

@@ -281,7 +281,19 @@ func AlertMuteUpgradeToV6(ctx *ctx.Context, dsm map[string]Datasource) error {
}
lst[i].DatasourceIds = string(b)

err = lst[i].UpdateFieldsMap(ctx, map[string]interface{}{"datasource_ids": lst[i].DatasourceIds})
if lst[i].Prod == "" {
lst[i].Prod = METRIC
}

if lst[i].Cate == "" {
lst[i].Cate = PROMETHEUS
}

err = lst[i].UpdateFieldsMap(ctx, map[string]interface{}{
"datasource_ids": lst[i].DatasourceIds,
"rule_prod": lst[i].Prod,
"cate": lst[i].Cate,
})
if err != nil {
logger.Errorf("update alert rule:%d datasource ids failed, %v", lst[i].Id, err)
}


+ 15
- 1
models/alert_rule.go View File

@@ -716,7 +716,21 @@ func AlertRuleUpgradeToV6(ctx *ctx.Context, dsm map[string]Datasource) error {
lst[i].Annotations = string(b)
}

err = lst[i].UpdateFieldsMap(ctx, map[string]interface{}{"datasource_ids": lst[i].DatasourceIds, "annotations": lst[i].Annotations, "rule_config": lst[i].RuleConfig})
if lst[i].Prod == "" {
lst[i].Prod = METRIC
}

if lst[i].Cate == "" {
lst[i].Cate = PROMETHEUS
}

err = lst[i].UpdateFieldsMap(ctx, map[string]interface{}{
"datasource_ids": lst[i].DatasourceIds,
"annotations": lst[i].Annotations,
"rule_config": lst[i].RuleConfig,
"prod": lst[i].Prod,
"cate": PROMETHEUS,
})
if err != nil {
logger.Errorf("update alert rule:%d datasource ids failed, %v", lst[i].Id, err)
}


+ 13
- 1
models/alert_subscribe.go View File

@@ -345,7 +345,19 @@ func AlertSubscribeUpgradeToV6(ctx *ctx.Context, dsm map[string]Datasource) erro
}
lst[i].DatasourceIds = string(b)

err = lst[i].UpdateFieldsMap(ctx, map[string]interface{}{"datasource_ids": lst[i].DatasourceIds})
if lst[i].Prod == "" {
lst[i].Prod = METRIC
}

if lst[i].Cate == "" {
lst[i].Cate = PROMETHEUS
}

err = lst[i].UpdateFieldsMap(ctx, map[string]interface{}{
"datasource_ids": lst[i].DatasourceIds,
"prod": lst[i].Prod,
"cate": PROMETHEUS,
})
if err != nil {
logger.Errorf("update alert rule:%d datasource ids failed, %v", lst[i].Id, err)
}


Loading…
Cancel
Save