update
This commit is contained in:
parent
ab525fff6a
commit
ac16db5f21
|
@ -305,7 +305,7 @@ Disable given information push to the central API.`,
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("unable to show labels status: %s", err)
|
log.Fatalf("unable to show labels status: %s", err)
|
||||||
}
|
}
|
||||||
fmt.Println(dump)
|
fmt.Println(string(dump))
|
||||||
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -159,6 +159,9 @@ func (a *apic) Push() error {
|
||||||
if ok := shouldShareAlert(alert, a.consoleConfig); ok {
|
if ok := shouldShareAlert(alert, a.consoleConfig); ok {
|
||||||
signals = append(signals, alertToSignal(alert, getScenarioTrustOfAlert(alert)))
|
signals = append(signals, alertToSignal(alert, getScenarioTrustOfAlert(alert)))
|
||||||
}
|
}
|
||||||
|
if !*a.consoleConfig.ShareLabel {
|
||||||
|
alert.Meta = models.Meta{}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
a.mu.Lock()
|
a.mu.Lock()
|
||||||
cache = append(cache, signals...)
|
cache = append(cache, signals...)
|
||||||
|
|
|
@ -235,13 +235,13 @@ func alertFormatSource(leaky *Leaky, queue *Queue) (map[string]models.Source, st
|
||||||
}
|
}
|
||||||
|
|
||||||
func EventToLabel(labels map[string][]*vm.Program, queue *Queue) models.Meta {
|
func EventToLabel(labels map[string][]*vm.Program, queue *Queue) models.Meta {
|
||||||
meta := make([]*models.MetaItems0, 0)
|
metas := make([]*models.MetaItems0, 0)
|
||||||
|
tmpLabels := make(map[string][]string)
|
||||||
for _, evt := range queue.Queue {
|
for _, evt := range queue.Queue {
|
||||||
for key, values := range labels {
|
for key, values := range labels {
|
||||||
tmpMeta := models.MetaItems0{}
|
if _, ok := tmpLabels[key]; !ok {
|
||||||
tmpMeta.Key = key
|
tmpLabels[key] = make([]string, 0)
|
||||||
tmpValue := make([]string, 0)
|
}
|
||||||
|
|
||||||
for _, value := range values {
|
for _, value := range values {
|
||||||
var val string
|
var val string
|
||||||
output, err := expr.Run(value, exprhelpers.GetExprEnv(map[string]interface{}{"evt": evt}))
|
output, err := expr.Run(value, exprhelpers.GetExprEnv(map[string]interface{}{"evt": evt}))
|
||||||
|
@ -258,17 +258,29 @@ func EventToLabel(labels map[string][]*vm.Program, queue *Queue) models.Meta {
|
||||||
log.Warningf("unexpected return type for label to send : %T", output)
|
log.Warningf("unexpected return type for label to send : %T", output)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
tmpValue = append(tmpValue, val)
|
if val != "" && !types.InSlice(val, tmpLabels[key]) {
|
||||||
|
tmpLabels[key] = append(tmpLabels[key], val)
|
||||||
}
|
}
|
||||||
valueBytes, err := json.Marshal(tmpValue)
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for key, values := range tmpLabels {
|
||||||
|
if len(values) == 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
valueByte, err := json.Marshal(values)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warningf("unable to marshall label values to send: %s", err)
|
log.Warningf("unable to dump metas: %s", err)
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
tmpMeta.Value = string(valueBytes)
|
meta := models.MetaItems0{
|
||||||
meta = append(meta, &tmpMeta)
|
Key: key,
|
||||||
|
Value: string(valueByte),
|
||||||
}
|
}
|
||||||
|
metas = append(metas, &meta)
|
||||||
}
|
}
|
||||||
ret := models.Meta(meta)
|
|
||||||
|
ret := models.Meta(metas)
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue