support reference channel
This commit is contained in:
parent
35b5706767
commit
7f36831998
|
@ -4,7 +4,9 @@
|
|||
|
||||
package alerting
|
||||
|
||||
import "infini.sh/framework/core/orm"
|
||||
import (
|
||||
"infini.sh/framework/core/orm"
|
||||
)
|
||||
|
||||
type Channel struct {
|
||||
orm.ORMObjectBase
|
||||
|
|
|
@ -6,6 +6,7 @@ package alerting
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"infini.sh/console/model/insight"
|
||||
"infini.sh/framework/core/util"
|
||||
"net/http"
|
||||
"testing"
|
||||
|
@ -60,18 +61,21 @@ func TestCreateRule( t *testing.T) {
|
|||
//},
|
||||
|
||||
Metrics: Metric{
|
||||
PeriodInterval: "1m",
|
||||
Items: []MetricItem{
|
||||
{Name: "a", Field: "payload.elasticsearch.node_stats.fs.total.free_in_bytes", Statistic: "min", Group: []string{"metadata.labels.cluster_id", "metadata.labels.node_id"}},
|
||||
{Name: "b", Field: "payload.elasticsearch.node_stats.fs.total.total_in_bytes", Statistic: "max", Group: []string{"metadata.labels.cluster_id", "metadata.labels.node_id"}},
|
||||
Metric: insight.Metric{
|
||||
Groups: []insight.MetricGroupItem{{"metadata.labels.cluster_id", 10}, {"metadata.labels.node_id", 10}},
|
||||
Items: []insight.MetricItem{
|
||||
{Name: "a", Field: "payload.elasticsearch.node_stats.fs.total.free_in_bytes", Statistic: "min" },
|
||||
{Name: "b", Field: "payload.elasticsearch.node_stats.fs.total.total_in_bytes", Statistic: "max"},
|
||||
},
|
||||
BucketSize: "1m",
|
||||
Formula: "a/b*100",
|
||||
},
|
||||
Formula: "a/b*100",
|
||||
//Expression: "min(fs.free_in_bytes)/max(fs.total_in_bytes)*100",
|
||||
},
|
||||
Conditions: Condition{
|
||||
Operator: "any",
|
||||
Items: []ConditionItem{
|
||||
{MinimumPeriodMatch: 1, Operator: "lte", Values: []string{"76"}, Priority: "error", Message: "磁盘可用率小于10%"},
|
||||
{MinimumPeriodMatch: 1, Operator: "lte", Values: []string{"76"}, Priority: "error"},
|
||||
},
|
||||
},
|
||||
|
||||
|
|
|
@ -203,6 +203,7 @@ func (h *EmailAPI) searchEmailServer(w http.ResponseWriter, req *http.Request, p
|
|||
var (
|
||||
strSize = h.GetParameterOrDefault(req, "size", "20")
|
||||
strFrom = h.GetParameterOrDefault(req, "from", "0")
|
||||
strEnabled = h.GetParameterOrDefault(req, "enabled", "true")
|
||||
)
|
||||
size, _ := strconv.Atoi(strSize)
|
||||
if size <= 0 {
|
||||
|
@ -217,7 +218,11 @@ func (h *EmailAPI) searchEmailServer(w http.ResponseWriter, req *http.Request, p
|
|||
From: from,
|
||||
Size: size,
|
||||
}
|
||||
q.Conds = orm.And(orm.Eq("enabled", true))
|
||||
if strEnabled == "true" {
|
||||
q.Conds = orm.And(orm.Eq("enabled", true))
|
||||
}else if strEnabled == "false" {
|
||||
q.Conds = orm.And(orm.Eq("enabled", false))
|
||||
}
|
||||
|
||||
err, res := orm.Search(&model.EmailServer{}, &q)
|
||||
if err != nil {
|
||||
|
|
|
@ -999,6 +999,10 @@ func performChannel(channel *alerting.Channel, ctx map[string]interface{}) ([]by
|
|||
message []byte
|
||||
err error
|
||||
)
|
||||
channel, err = RetrieveChannel(channel)
|
||||
if err != nil {
|
||||
return nil, err, nil
|
||||
}
|
||||
switch channel.Type {
|
||||
|
||||
case alerting.ChannelWebhook:
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
/* Copyright © INFINI Ltd. All rights reserved.
|
||||
* Web: https://infinilabs.com
|
||||
* Email: hello#infini.ltd */
|
||||
|
||||
package elasticsearch
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"infini.sh/console/model/alerting"
|
||||
"infini.sh/framework/core/orm"
|
||||
)
|
||||
|
||||
func RetrieveChannel(ch *alerting.Channel) (*alerting.Channel, error) {
|
||||
if ch == nil {
|
||||
return nil, fmt.Errorf("empty channel")
|
||||
}
|
||||
if ch.ID != "" {
|
||||
_, err := orm.Get(ch)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return ch, nil
|
||||
}
|
Loading…
Reference in New Issue