Compare commits
4 commits
Author | SHA1 | Date | |
---|---|---|---|
|
82d3ba61e4 | ||
|
dbec5b7c9c | ||
|
64b793c3da | ||
|
26faf6fb13 |
5 changed files with 35 additions and 38 deletions
|
@ -91,10 +91,7 @@ func truncate(values []string, contextValueLen int) (string, error) {
|
||||||
return "", fmt.Errorf("unable to dump metas: %s", err)
|
return "", fmt.Errorf("unable to dump metas: %s", err)
|
||||||
}
|
}
|
||||||
ret = string(valueByte)
|
ret = string(valueByte)
|
||||||
for {
|
for len(ret) > contextValueLen {
|
||||||
if len(ret) <= contextValueLen {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
// if there is only 1 value left and that the size is too big, truncate it
|
// if there is only 1 value left and that the size is too big, truncate it
|
||||||
if len(values) == 1 {
|
if len(values) == 1 {
|
||||||
valueToTruncate := values[0]
|
valueToTruncate := values[0]
|
||||||
|
|
|
@ -911,12 +911,17 @@ func (a *apic) UpdateBlocklists(links *modelscapi.GetDecisionsStreamResponseLink
|
||||||
}
|
}
|
||||||
|
|
||||||
func setAlertScenario(alert *models.Alert, addCounters map[string]map[string]int, deleteCounters map[string]map[string]int) {
|
func setAlertScenario(alert *models.Alert, addCounters map[string]map[string]int, deleteCounters map[string]map[string]int) {
|
||||||
if *alert.Source.Scope == types.CAPIOrigin {
|
switch *alert.Source.Scope {
|
||||||
|
case types.CAPIOrigin:
|
||||||
*alert.Source.Scope = types.CommunityBlocklistPullSourceScope
|
*alert.Source.Scope = types.CommunityBlocklistPullSourceScope
|
||||||
alert.Scenario = ptr.Of(fmt.Sprintf("update : +%d/-%d IPs", addCounters[types.CAPIOrigin]["all"], deleteCounters[types.CAPIOrigin]["all"]))
|
alert.Scenario = ptr.Of(fmt.Sprintf("update : +%d/-%d IPs",
|
||||||
} else if *alert.Source.Scope == types.ListOrigin {
|
addCounters[types.CAPIOrigin]["all"],
|
||||||
|
deleteCounters[types.CAPIOrigin]["all"]))
|
||||||
|
case types.ListOrigin:
|
||||||
*alert.Source.Scope = fmt.Sprintf("%s:%s", types.ListOrigin, *alert.Scenario)
|
*alert.Source.Scope = fmt.Sprintf("%s:%s", types.ListOrigin, *alert.Scenario)
|
||||||
alert.Scenario = ptr.Of(fmt.Sprintf("update : +%d/-%d IPs", addCounters[types.ListOrigin][*alert.Scenario], deleteCounters[types.ListOrigin][*alert.Scenario]))
|
alert.Scenario = ptr.Of(fmt.Sprintf("update : +%d/-%d IPs",
|
||||||
|
addCounters[types.ListOrigin][*alert.Scenario],
|
||||||
|
deleteCounters[types.ListOrigin][*alert.Scenario]))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -988,11 +993,12 @@ func makeAddAndDeleteCounters() (map[string]map[string]int, map[string]map[strin
|
||||||
}
|
}
|
||||||
|
|
||||||
func updateCounterForDecision(counter map[string]map[string]int, origin *string, scenario *string, totalDecisions int) {
|
func updateCounterForDecision(counter map[string]map[string]int, origin *string, scenario *string, totalDecisions int) {
|
||||||
if *origin == types.CAPIOrigin {
|
switch *origin {
|
||||||
|
case types.CAPIOrigin:
|
||||||
counter[*origin]["all"] += totalDecisions
|
counter[*origin]["all"] += totalDecisions
|
||||||
} else if *origin == types.ListOrigin {
|
case types.ListOrigin:
|
||||||
counter[*origin][*scenario] += totalDecisions
|
counter[*origin][*scenario] += totalDecisions
|
||||||
} else {
|
default:
|
||||||
log.Warningf("Unknown origin %s", *origin)
|
log.Warningf("Unknown origin %s", *origin)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,20 +49,17 @@ func LastAddress(n *net.IPNet) net.IP {
|
||||||
ip[3]|^n.Mask[3])
|
ip[3]|^n.Mask[3])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetIpsFromIpRange takes a CIDR range and returns the start and end IP
|
||||||
func GetIpsFromIpRange(host string) (int64, int64, error) {
|
func GetIpsFromIpRange(host string) (int64, int64, error) {
|
||||||
var ipStart int64
|
_, parsedRange, err := net.ParseCIDR(host)
|
||||||
var ipEnd int64
|
if err != nil {
|
||||||
var err error
|
return 0, 0, fmt.Errorf("'%s' is not a valid CIDR", host)
|
||||||
var parsedRange *net.IPNet
|
|
||||||
|
|
||||||
if _, parsedRange, err = net.ParseCIDR(host); err != nil {
|
|
||||||
return ipStart, ipEnd, fmt.Errorf("'%s' is not a valid CIDR", host)
|
|
||||||
}
|
}
|
||||||
if parsedRange == nil {
|
if parsedRange == nil {
|
||||||
return ipStart, ipEnd, fmt.Errorf("unable to parse network : %s", err)
|
return 0, 0, fmt.Errorf("unable to parse network : %s", err)
|
||||||
}
|
}
|
||||||
ipStart = int64(IP2Int(parsedRange.IP))
|
ipStart := int64(IP2Int(parsedRange.IP))
|
||||||
ipEnd = int64(IP2Int(LastAddress(parsedRange)))
|
ipEnd := int64(IP2Int(LastAddress(parsedRange)))
|
||||||
|
|
||||||
return ipStart, ipEnd, nil
|
return ipStart, ipEnd, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -380,7 +380,6 @@ func LoadBucket(bucketFactory *BucketFactory, tomb *tomb.Tomb) error {
|
||||||
bucketFactory.processors = append(bucketFactory.processors, &BayesianBucket{})
|
bucketFactory.processors = append(bucketFactory.processors, &BayesianBucket{})
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(bucketFactory.Data) > 0 {
|
|
||||||
for _, data := range bucketFactory.Data {
|
for _, data := range bucketFactory.Data {
|
||||||
if data.DestPath == "" {
|
if data.DestPath == "" {
|
||||||
bucketFactory.logger.Errorf("no dest_file provided for '%s'", bucketFactory.Name)
|
bucketFactory.logger.Errorf("no dest_file provided for '%s'", bucketFactory.Name)
|
||||||
|
@ -394,7 +393,6 @@ func LoadBucket(bucketFactory *BucketFactory, tomb *tomb.Tomb) error {
|
||||||
exprhelpers.RegexpCacheInit(data.DestPath, *data)
|
exprhelpers.RegexpCacheInit(data.DestPath, *data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
bucketFactory.output = false
|
bucketFactory.output = false
|
||||||
if err := ValidateFactory(bucketFactory); err != nil {
|
if err := ValidateFactory(bucketFactory); err != nil {
|
||||||
|
|
|
@ -97,13 +97,12 @@ func IP2Ints(pip net.IP) (int, int64, int64, error) {
|
||||||
|
|
||||||
if pip4 != nil {
|
if pip4 != nil {
|
||||||
ip_nw32 := binary.BigEndian.Uint32(pip4)
|
ip_nw32 := binary.BigEndian.Uint32(pip4)
|
||||||
|
|
||||||
return 4, uint2int(uint64(ip_nw32)), uint2int(ip_sfx), nil
|
return 4, uint2int(uint64(ip_nw32)), uint2int(ip_sfx), nil
|
||||||
} else if pip16 != nil {
|
}
|
||||||
|
if pip16 != nil {
|
||||||
ip_nw = binary.BigEndian.Uint64(pip16[0:8])
|
ip_nw = binary.BigEndian.Uint64(pip16[0:8])
|
||||||
ip_sfx = binary.BigEndian.Uint64(pip16[8:16])
|
ip_sfx = binary.BigEndian.Uint64(pip16[8:16])
|
||||||
return 16, uint2int(ip_nw), uint2int(ip_sfx), nil
|
return 16, uint2int(ip_nw), uint2int(ip_sfx), nil
|
||||||
} else {
|
}
|
||||||
return -1, 0, 0, fmt.Errorf("unexpected len %d for %s", len(pip), pip)
|
return -1, 0, 0, fmt.Errorf("unexpected len %d for %s", len(pip), pip)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in a new issue