local control flow cleanup (#1215)
removed redundant/unreachable returns, else branches, type declarations, unused variables
This commit is contained in:
parent
d5f17ee377
commit
ad28a979e9
|
@ -15,7 +15,6 @@ import (
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
var keyName string
|
|
||||||
var keyIP string
|
var keyIP string
|
||||||
var keyLength int
|
var keyLength int
|
||||||
var key string
|
var key string
|
||||||
|
|
|
@ -157,10 +157,8 @@ func NewCapiCmd() *cobra.Command {
|
||||||
_, err = Client.Auth.AuthenticateWatcher(context.Background(), t)
|
_, err = Client.Auth.AuthenticateWatcher(context.Background(), t)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Failed to authenticate to Central API (CAPI) : %s", err)
|
log.Fatalf("Failed to authenticate to Central API (CAPI) : %s", err)
|
||||||
} else {
|
|
||||||
log.Infof("You can successfully interact with Central API (CAPI)")
|
|
||||||
}
|
}
|
||||||
|
log.Infof("You can successfully interact with Central API (CAPI)")
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
cmdCapi.AddCommand(cmdCapiStatus)
|
cmdCapi.AddCommand(cmdCapiStatus)
|
||||||
|
|
|
@ -33,11 +33,11 @@ func NewConsoleCmd() *cobra.Command {
|
||||||
var fdErr *fs.PathError
|
var fdErr *fs.PathError
|
||||||
if errors.As(err, &fdErr) {
|
if errors.As(err, &fdErr) {
|
||||||
log.Fatalf("Unable to load Local API : %s", fdErr)
|
log.Fatalf("Unable to load Local API : %s", fdErr)
|
||||||
} else if err != nil {
|
|
||||||
log.Fatalf("Unable to load required Local API Configuration : %s", err)
|
|
||||||
} else {
|
|
||||||
log.Fatal("Local API is disabled, please run this command on the local API machine")
|
|
||||||
}
|
}
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("Unable to load required Local API Configuration : %s", err)
|
||||||
|
}
|
||||||
|
log.Fatal("Local API is disabled, please run this command on the local API machine")
|
||||||
}
|
}
|
||||||
if csConfig.DisableAPI {
|
if csConfig.DisableAPI {
|
||||||
log.Fatal("Local API is disabled, please run this command on the local API machine")
|
log.Fatal("Local API is disabled, please run this command on the local API machine")
|
||||||
|
|
|
@ -24,7 +24,6 @@ var (
|
||||||
metabaseConfigPath string
|
metabaseConfigPath string
|
||||||
metabaseConfigFolder = "metabase/"
|
metabaseConfigFolder = "metabase/"
|
||||||
metabaseConfigFile = "metabase.yaml"
|
metabaseConfigFile = "metabase.yaml"
|
||||||
metabaseImage = "metabase/metabase"
|
|
||||||
/**/
|
/**/
|
||||||
metabaseListenAddress = "127.0.0.1"
|
metabaseListenAddress = "127.0.0.1"
|
||||||
metabaseListenPort = "3000"
|
metabaseListenPort = "3000"
|
||||||
|
@ -33,7 +32,6 @@ var (
|
||||||
|
|
||||||
forceYes bool
|
forceYes bool
|
||||||
|
|
||||||
dockerGatewayIPAddr = "172.17.0.1"
|
|
||||||
/*informations needed to setup a random password on user's behalf*/
|
/*informations needed to setup a random password on user's behalf*/
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -143,10 +143,7 @@ cscli simulation disable crowdsecurity/ssh-bf`,
|
||||||
|
|
||||||
if len(args) > 0 {
|
if len(args) > 0 {
|
||||||
for _, scenario := range args {
|
for _, scenario := range args {
|
||||||
var (
|
var item = cwhub.GetItem(cwhub.SCENARIOS, scenario)
|
||||||
item *cwhub.Item
|
|
||||||
)
|
|
||||||
item = cwhub.GetItem(cwhub.SCENARIOS, scenario)
|
|
||||||
if item == nil {
|
if item == nil {
|
||||||
log.Errorf("'%s' doesn't exist or is not a scenario", scenario)
|
log.Errorf("'%s' doesn't exist or is not a scenario", scenario)
|
||||||
continue
|
continue
|
||||||
|
|
|
@ -201,7 +201,6 @@ func InstallItem(name string, obtype string, force bool) {
|
||||||
}
|
}
|
||||||
cwhub.AddItem(obtype, item)
|
cwhub.AddItem(obtype, item)
|
||||||
log.Infof("Enabled %s", item.Name)
|
log.Infof("Enabled %s", item.Name)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func RemoveMany(itemType string, name string) {
|
func RemoveMany(itemType string, name string) {
|
||||||
|
@ -557,8 +556,7 @@ func ShowParserMetric(itemName string, metrics map[string]map[string]int) {
|
||||||
|
|
||||||
//it's a rip of the cli version, but in silent-mode
|
//it's a rip of the cli version, but in silent-mode
|
||||||
func silenceInstallItem(name string, obtype string) (string, error) {
|
func silenceInstallItem(name string, obtype string) (string, error) {
|
||||||
var item *cwhub.Item
|
var item = cwhub.GetItem(obtype, name)
|
||||||
item = cwhub.GetItem(obtype, name)
|
|
||||||
if item == nil {
|
if item == nil {
|
||||||
return "", fmt.Errorf("error retrieving item")
|
return "", fmt.Errorf("error retrieving item")
|
||||||
}
|
}
|
||||||
|
|
|
@ -66,16 +66,6 @@ type Flags struct {
|
||||||
|
|
||||||
type labelsMap map[string]string
|
type labelsMap map[string]string
|
||||||
|
|
||||||
type parsers struct {
|
|
||||||
ctx *parser.UnixParserCtx
|
|
||||||
povfwctx *parser.UnixParserCtx
|
|
||||||
stageFiles []parser.Stagefile
|
|
||||||
povfwStageFiles []parser.Stagefile
|
|
||||||
nodes []parser.Node
|
|
||||||
povfwnodes []parser.Node
|
|
||||||
enricherCtx []parser.EnricherCtx
|
|
||||||
}
|
|
||||||
|
|
||||||
// Return new parsers
|
// Return new parsers
|
||||||
// nodes and povfwnodes are already initialized in parser.LoadStages
|
// nodes and povfwnodes are already initialized in parser.LoadStages
|
||||||
func newParsers() *parser.Parsers {
|
func newParsers() *parser.Parsers {
|
||||||
|
|
|
@ -218,11 +218,10 @@ func GetMetrics(sources []DataSource, aggregated bool) error {
|
||||||
}
|
}
|
||||||
for _, metric := range metrics {
|
for _, metric := range metrics {
|
||||||
if err := prometheus.Register(metric); err != nil {
|
if err := prometheus.Register(metric); err != nil {
|
||||||
if _, ok := err.(prometheus.AlreadyRegisteredError); ok {
|
if _, ok := err.(prometheus.AlreadyRegisteredError); !ok {
|
||||||
//ignore the error
|
|
||||||
} else {
|
|
||||||
return errors.Wrapf(err, "could not register metrics for datasource %s", sources[i].GetName())
|
return errors.Wrapf(err, "could not register metrics for datasource %s", sources[i].GetName())
|
||||||
}
|
}
|
||||||
|
//ignore the error
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -182,9 +182,8 @@ wowo: ajsajasjas
|
||||||
}
|
}
|
||||||
if !strings.Contains(err.Error(), test.ExpectedError) {
|
if !strings.Contains(err.Error(), test.ExpectedError) {
|
||||||
t.Fatalf("%s : expected error '%s' in '%s'", test.TestName, test.ExpectedError, err.Error())
|
t.Fatalf("%s : expected error '%s' in '%s'", test.TestName, test.ExpectedError, err.Error())
|
||||||
} else {
|
|
||||||
continue
|
|
||||||
}
|
}
|
||||||
|
continue
|
||||||
} else {
|
} else {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("%s : unexpected error '%s'", test.TestName, err)
|
t.Fatalf("%s : unexpected error '%s'", test.TestName, err)
|
||||||
|
@ -289,9 +288,8 @@ func TestLoadAcquisitionFromFile(t *testing.T) {
|
||||||
}
|
}
|
||||||
if !strings.Contains(err.Error(), test.ExpectedError) {
|
if !strings.Contains(err.Error(), test.ExpectedError) {
|
||||||
t.Fatalf("%s : expected error '%s' in '%s'", test.TestName, test.ExpectedError, err.Error())
|
t.Fatalf("%s : expected error '%s' in '%s'", test.TestName, test.ExpectedError, err.Error())
|
||||||
} else {
|
|
||||||
continue
|
|
||||||
}
|
}
|
||||||
|
continue
|
||||||
} else {
|
} else {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("%s : unexpected error '%s'", test.TestName, err)
|
t.Fatalf("%s : unexpected error '%s'", test.TestName, err)
|
||||||
|
|
|
@ -492,9 +492,8 @@ stream_name: test_stream`),
|
||||||
if test.expectedResLen != -1 {
|
if test.expectedResLen != -1 {
|
||||||
if test.expectedResLen != len(rcvd_evts) {
|
if test.expectedResLen != len(rcvd_evts) {
|
||||||
t.Fatalf("%s : expected %d results got %d -> %v", test.name, test.expectedResLen, len(rcvd_evts), rcvd_evts)
|
t.Fatalf("%s : expected %d results got %d -> %v", test.name, test.expectedResLen, len(rcvd_evts), rcvd_evts)
|
||||||
} else {
|
|
||||||
dbgLogger.Debugf("got %d expected messages", len(rcvd_evts))
|
|
||||||
}
|
}
|
||||||
|
dbgLogger.Debugf("got %d expected messages", len(rcvd_evts))
|
||||||
}
|
}
|
||||||
if len(test.expectedResMessages) != 0 {
|
if len(test.expectedResMessages) != 0 {
|
||||||
res := test.expectedResMessages
|
res := test.expectedResMessages
|
||||||
|
@ -504,9 +503,8 @@ stream_name: test_stream`),
|
||||||
}
|
}
|
||||||
if res[0] != v.Line.Raw {
|
if res[0] != v.Line.Raw {
|
||||||
t.Fatalf("result %d/%d : expected '%s', received '%s' (recvd:%d, expected:%d)", idx, len(rcvd_evts), res[0], v.Line.Raw, len(rcvd_evts), len(test.expectedResMessages))
|
t.Fatalf("result %d/%d : expected '%s', received '%s' (recvd:%d, expected:%d)", idx, len(rcvd_evts), res[0], v.Line.Raw, len(rcvd_evts), len(test.expectedResMessages))
|
||||||
} else {
|
|
||||||
dbgLogger.Debugf("got message '%s'", res[0])
|
|
||||||
}
|
}
|
||||||
|
dbgLogger.Debugf("got message '%s'", res[0])
|
||||||
res = res[1:]
|
res = res[1:]
|
||||||
}
|
}
|
||||||
if len(res) != 0 {
|
if len(res) != 0 {
|
||||||
|
@ -853,9 +851,8 @@ func TestOneShotAcquisition(t *testing.T) {
|
||||||
}
|
}
|
||||||
if res[0] != v.Line.Raw {
|
if res[0] != v.Line.Raw {
|
||||||
t.Fatalf("result %d/%d : expected '%s', received '%s' (recvd:%d, expected:%d)", idx, len(rcvd_evts), res[0], v.Line.Raw, len(rcvd_evts), len(test.expectedResMessages))
|
t.Fatalf("result %d/%d : expected '%s', received '%s' (recvd:%d, expected:%d)", idx, len(rcvd_evts), res[0], v.Line.Raw, len(rcvd_evts), len(test.expectedResMessages))
|
||||||
} else {
|
|
||||||
dbgLogger.Debugf("got message '%s'", res[0])
|
|
||||||
}
|
}
|
||||||
|
dbgLogger.Debugf("got message '%s'", res[0])
|
||||||
res = res[1:]
|
res = res[1:]
|
||||||
}
|
}
|
||||||
if len(res) != 0 {
|
if len(res) != 0 {
|
||||||
|
|
|
@ -111,8 +111,7 @@ func (t *JWTTransport) refreshJwtToken() error {
|
||||||
/*
|
/*
|
||||||
we don't use the main client, so let's build the body
|
we don't use the main client, so let's build the body
|
||||||
*/
|
*/
|
||||||
var buf io.ReadWriter
|
var buf io.ReadWriter = &bytes.Buffer{}
|
||||||
buf = &bytes.Buffer{}
|
|
||||||
enc := json.NewEncoder(buf)
|
enc := json.NewEncoder(buf)
|
||||||
enc.SetEscapeHTML(false)
|
enc.SetEscapeHTML(false)
|
||||||
err = enc.Encode(auth)
|
err = enc.Encode(auth)
|
||||||
|
|
|
@ -78,9 +78,8 @@ func (c *ApiClient) Do(ctx context.Context, req *http.Request, v interface{}) (*
|
||||||
if url, err := url.Parse(e.URL); err == nil {
|
if url, err := url.Parse(e.URL); err == nil {
|
||||||
e.URL = url.String()
|
e.URL = url.String()
|
||||||
return newResponse(resp), e
|
return newResponse(resp), e
|
||||||
} else {
|
|
||||||
return newResponse(resp), err
|
|
||||||
}
|
}
|
||||||
|
return newResponse(resp), err
|
||||||
}
|
}
|
||||||
return newResponse(resp), err
|
return newResponse(resp), err
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,12 +20,11 @@ import (
|
||||||
|
|
||||||
func FormatOneAlert(alert *ent.Alert) *models.Alert {
|
func FormatOneAlert(alert *ent.Alert) *models.Alert {
|
||||||
var outputAlert models.Alert
|
var outputAlert models.Alert
|
||||||
var machineID string
|
|
||||||
startAt := alert.StartedAt.String()
|
startAt := alert.StartedAt.String()
|
||||||
StopAt := alert.StoppedAt.String()
|
StopAt := alert.StoppedAt.String()
|
||||||
if alert.Edges.Owner == nil {
|
|
||||||
machineID = "N/A"
|
machineID := "N/A"
|
||||||
} else {
|
if alert.Edges.Owner != nil {
|
||||||
machineID = alert.Edges.Owner.MachineId
|
machineID = alert.Edges.Owner.MachineId
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -42,11 +42,10 @@ func (c *Config) LoadSimulation() error {
|
||||||
rcfg, err := ioutil.ReadFile(c.ConfigPaths.SimulationFilePath)
|
rcfg, err := ioutil.ReadFile(c.ConfigPaths.SimulationFilePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrapf(err, "while reading '%s'", c.ConfigPaths.SimulationFilePath)
|
return errors.Wrapf(err, "while reading '%s'", c.ConfigPaths.SimulationFilePath)
|
||||||
} else {
|
}
|
||||||
if err := yaml.UnmarshalStrict(rcfg, &simCfg); err != nil {
|
if err := yaml.UnmarshalStrict(rcfg, &simCfg); err != nil {
|
||||||
return fmt.Errorf("while unmarshaling simulation file '%s' : %s", c.ConfigPaths.SimulationFilePath, err)
|
return fmt.Errorf("while unmarshaling simulation file '%s' : %s", c.ConfigPaths.SimulationFilePath, err)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if simCfg.Simulation == nil {
|
if simCfg.Simulation == nil {
|
||||||
simCfg.Simulation = new(bool)
|
simCfg.Simulation = new(bool)
|
||||||
}
|
}
|
||||||
|
|
|
@ -443,7 +443,7 @@ func DumpTree(parser_results ParserResults, bucket_pour BucketPourInfo, opts Dum
|
||||||
fmt.Printf("\t├ Scenarios\n")
|
fmt.Printf("\t├ Scenarios\n")
|
||||||
}
|
}
|
||||||
bnames := make([]string, 0, len(state[tstamp]["buckets"]))
|
bnames := make([]string, 0, len(state[tstamp]["buckets"]))
|
||||||
for k, _ := range state[tstamp]["buckets"] {
|
for k := range state[tstamp]["buckets"] {
|
||||||
//there is a trick : to know if an event succesfully exit the parsers, we check if it reached the pour() phase
|
//there is a trick : to know if an event succesfully exit the parsers, we check if it reached the pour() phase
|
||||||
//we thus use a fake stage "buckets" and a fake parser "OK" to know if it entered
|
//we thus use a fake stage "buckets" and a fake parser "OK" to know if it entered
|
||||||
if k == "OK" {
|
if k == "OK" {
|
||||||
|
|
|
@ -173,15 +173,12 @@ func GetItemByPath(itemType string, itemPath string) (*Item, error) {
|
||||||
if m := GetItemMap(itemType); m != nil {
|
if m := GetItemMap(itemType); m != nil {
|
||||||
if v, ok := m[finalName]; ok {
|
if v, ok := m[finalName]; ok {
|
||||||
return &v, nil
|
return &v, nil
|
||||||
} else {
|
}
|
||||||
return nil, fmt.Errorf("%s not found in %s", finalName, itemType)
|
return nil, fmt.Errorf("%s not found in %s", finalName, itemType)
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
return nil, fmt.Errorf("item type %s doesn't exist", itemType)
|
return nil, fmt.Errorf("item type %s doesn't exist", itemType)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
func GetItem(itemType string, itemName string) *Item {
|
func GetItem(itemType string, itemName string) *Item {
|
||||||
if m, ok := GetItemMap(itemType)[itemName]; ok {
|
if m, ok := GetItemMap(itemType)[itemName]; ok {
|
||||||
return &m
|
return &m
|
||||||
|
@ -213,25 +210,21 @@ func DisplaySummary() {
|
||||||
|
|
||||||
//returns: human-text, Enabled, Warning, Unmanaged
|
//returns: human-text, Enabled, Warning, Unmanaged
|
||||||
func ItemStatus(v Item) (string, bool, bool, bool) {
|
func ItemStatus(v Item) (string, bool, bool, bool) {
|
||||||
var Ok, Warning, Managed bool
|
strret := "disabled"
|
||||||
var strret string
|
Ok := false
|
||||||
|
if v.Installed {
|
||||||
if !v.Installed {
|
|
||||||
strret = "disabled"
|
|
||||||
Ok = false
|
|
||||||
} else {
|
|
||||||
Ok = true
|
Ok = true
|
||||||
strret = "enabled"
|
strret = "enabled"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Managed := true
|
||||||
if v.Local {
|
if v.Local {
|
||||||
Managed = false
|
Managed = false
|
||||||
strret += ",local"
|
strret += ",local"
|
||||||
} else {
|
|
||||||
Managed = true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//tainted or out of date
|
//tainted or out of date
|
||||||
|
Warning := false
|
||||||
if v.Tainted {
|
if v.Tainted {
|
||||||
Warning = true
|
Warning = true
|
||||||
strret += ",tainted"
|
strret += ",tainted"
|
||||||
|
|
|
@ -22,8 +22,6 @@ import (
|
||||||
- Upgrade collection
|
- Upgrade collection
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var testDataFolder = "."
|
|
||||||
|
|
||||||
func TestItemStatus(t *testing.T) {
|
func TestItemStatus(t *testing.T) {
|
||||||
cfg := test_prepenv()
|
cfg := test_prepenv()
|
||||||
|
|
||||||
|
@ -43,7 +41,7 @@ func TestItemStatus(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
//Get item : good and bad
|
//Get item : good and bad
|
||||||
for k, _ := range x {
|
for k := range x {
|
||||||
item := GetItem(COLLECTIONS, k)
|
item := GetItem(COLLECTIONS, k)
|
||||||
if item == nil {
|
if item == nil {
|
||||||
t.Fatalf("expected item")
|
t.Fatalf("expected item")
|
||||||
|
|
|
@ -85,7 +85,11 @@ func DownloadLatest(hub *csconfig.Hub, target Item, overwrite bool, updateOnly b
|
||||||
for idx, ptr := range tmp {
|
for idx, ptr := range tmp {
|
||||||
ptrtype := ItemTypes[idx]
|
ptrtype := ItemTypes[idx]
|
||||||
for _, p := range ptr {
|
for _, p := range ptr {
|
||||||
if val, ok := hubIdx[ptrtype][p]; ok {
|
val, ok := hubIdx[ptrtype][p]
|
||||||
|
if !ok {
|
||||||
|
return target, fmt.Errorf("required %s %s of %s doesn't exist, abort", ptrtype, p, target.Name)
|
||||||
|
}
|
||||||
|
|
||||||
if !val.Installed && updateOnly {
|
if !val.Installed && updateOnly {
|
||||||
log.Debugf("skipping upgrade of %s : not installed", target.Name)
|
log.Debugf("skipping upgrade of %s : not installed", target.Name)
|
||||||
continue
|
continue
|
||||||
|
@ -112,9 +116,6 @@ func DownloadLatest(hub *csconfig.Hub, target Item, overwrite bool, updateOnly b
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
hubIdx[ptrtype][p] = item
|
hubIdx[ptrtype][p] = item
|
||||||
} else {
|
|
||||||
return target, fmt.Errorf("required %s %s of %s doesn't exist, abort", ptrtype, p, target.Name)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
target, err = DownloadItem(hub, target, overwrite)
|
target, err = DownloadItem(hub, target, overwrite)
|
||||||
|
@ -245,11 +246,10 @@ func downloadData(dataFolder string, force bool, reader io.Reader) error {
|
||||||
data := &types.DataSet{}
|
data := &types.DataSet{}
|
||||||
err = dec.Decode(data)
|
err = dec.Decode(data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err == io.EOF {
|
if err != io.EOF {
|
||||||
break
|
|
||||||
} else {
|
|
||||||
return errors.Wrap(err, "while reading file")
|
return errors.Wrap(err, "while reading file")
|
||||||
}
|
}
|
||||||
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
download := false
|
download := false
|
||||||
|
|
|
@ -21,7 +21,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
/*the walk/parser_visit function can't receive extra args*/
|
/*the walk/parser_visit function can't receive extra args*/
|
||||||
var hubdir, installdir, indexpath string
|
var hubdir, installdir string
|
||||||
|
|
||||||
func parser_visit(path string, f os.FileInfo, err error) error {
|
func parser_visit(path string, f os.FileInfo, err error) error {
|
||||||
|
|
||||||
|
@ -193,7 +193,7 @@ func parser_visit(path string, f os.FileInfo, err error) error {
|
||||||
if sha != val.Digest {
|
if sha != val.Digest {
|
||||||
//log.Printf("matching filenames, wrong hash %s != %s -- %s", sha, val.Digest, spew.Sdump(v))
|
//log.Printf("matching filenames, wrong hash %s != %s -- %s", sha, val.Digest, spew.Sdump(v))
|
||||||
continue
|
continue
|
||||||
} else {
|
}
|
||||||
/*we got an exact match, update struct*/
|
/*we got an exact match, update struct*/
|
||||||
if !inhub {
|
if !inhub {
|
||||||
log.Tracef("found exact match for %s, version is %s, latest is %s", v.Name, version, v.Version)
|
log.Tracef("found exact match for %s, version is %s, latest is %s", v.Name, version, v.Version)
|
||||||
|
@ -214,7 +214,6 @@ func parser_visit(path string, f os.FileInfo, err error) error {
|
||||||
match = true
|
match = true
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if !match {
|
if !match {
|
||||||
log.Tracef("got tainted match for %s : %s", v.Name, path)
|
log.Tracef("got tainted match for %s : %s", v.Name, path)
|
||||||
skippedTainted += 1
|
skippedTainted += 1
|
||||||
|
@ -257,7 +256,10 @@ func CollecDepsCheck(v *Item) error {
|
||||||
for idx, ptr := range tmp {
|
for idx, ptr := range tmp {
|
||||||
ptrtype := ItemTypes[idx]
|
ptrtype := ItemTypes[idx]
|
||||||
for _, p := range ptr {
|
for _, p := range ptr {
|
||||||
if val, ok := hubIdx[ptrtype][p]; ok {
|
val, ok := hubIdx[ptrtype][p]
|
||||||
|
if !ok {
|
||||||
|
log.Fatalf("Referred %s %s in collection %s doesn't exist.", ptrtype, p, v.Name)
|
||||||
|
}
|
||||||
log.Tracef("check %s installed:%t", val.Name, val.Installed)
|
log.Tracef("check %s installed:%t", val.Name, val.Installed)
|
||||||
if !v.Installed {
|
if !v.Installed {
|
||||||
continue
|
continue
|
||||||
|
@ -274,10 +276,12 @@ func CollecDepsCheck(v *Item) error {
|
||||||
if val.Tainted {
|
if val.Tainted {
|
||||||
v.Tainted = true
|
v.Tainted = true
|
||||||
return fmt.Errorf("tainted %s %s, tainted.", ptrtype, p)
|
return fmt.Errorf("tainted %s %s, tainted.", ptrtype, p)
|
||||||
} else if !val.Installed && v.Installed {
|
}
|
||||||
|
if !val.Installed && v.Installed {
|
||||||
v.Tainted = true
|
v.Tainted = true
|
||||||
return fmt.Errorf("missing %s %s, tainted.", ptrtype, p)
|
return fmt.Errorf("missing %s %s, tainted.", ptrtype, p)
|
||||||
} else if !val.UpToDate {
|
}
|
||||||
|
if !val.UpToDate {
|
||||||
v.UpToDate = false
|
v.UpToDate = false
|
||||||
return fmt.Errorf("outdated %s %s", ptrtype, p)
|
return fmt.Errorf("outdated %s %s", ptrtype, p)
|
||||||
}
|
}
|
||||||
|
@ -292,9 +296,6 @@ func CollecDepsCheck(v *Item) error {
|
||||||
}
|
}
|
||||||
hubIdx[ptrtype][p] = val
|
hubIdx[ptrtype][p] = val
|
||||||
log.Tracef("checking for %s - tainted:%t uptodate:%t", p, v.Tainted, v.UpToDate)
|
log.Tracef("checking for %s - tainted:%t uptodate:%t", p, v.Tainted, v.UpToDate)
|
||||||
} else {
|
|
||||||
log.Fatalf("Referred %s %s in collection %s doesn't exist.", ptrtype, p, v.Name)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -304,7 +305,6 @@ func CollecDepsCheck(v *Item) error {
|
||||||
func SyncDir(hub *csconfig.Hub, dir string) (error, []string) {
|
func SyncDir(hub *csconfig.Hub, dir string) (error, []string) {
|
||||||
hubdir = hub.HubDir
|
hubdir = hub.HubDir
|
||||||
installdir = hub.ConfigDir
|
installdir = hub.ConfigDir
|
||||||
indexpath = hub.HubIndexFile
|
|
||||||
warnings := []string{}
|
warnings := []string{}
|
||||||
|
|
||||||
/*For each, scan PARSERS, PARSERS_OVFLW, SCENARIOS and COLLECTIONS last*/
|
/*For each, scan PARSERS, PARSERS_OVFLW, SCENARIOS and COLLECTIONS last*/
|
||||||
|
|
|
@ -19,13 +19,10 @@ type Blackhole struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewBlackhole(bucketFactory *BucketFactory) (*Blackhole, error) {
|
func NewBlackhole(bucketFactory *BucketFactory) (*Blackhole, error) {
|
||||||
|
duration, err := time.ParseDuration(bucketFactory.Blackhole)
|
||||||
var duration time.Duration
|
if err != nil {
|
||||||
if d, err := time.ParseDuration(bucketFactory.Blackhole); err != nil {
|
|
||||||
bucketFactory.logger.Warning("Blackhole duration not valid, using 1h")
|
bucketFactory.logger.Warning("Blackhole duration not valid, using 1h")
|
||||||
return nil, fmt.Errorf("blackhole duration not valid '%s'", bucketFactory.Blackhole)
|
return nil, fmt.Errorf("blackhole duration not valid '%s'", bucketFactory.Blackhole)
|
||||||
} else {
|
|
||||||
duration = d
|
|
||||||
}
|
}
|
||||||
return &Blackhole{
|
return &Blackhole{
|
||||||
duration: duration,
|
duration: duration,
|
||||||
|
|
|
@ -154,12 +154,11 @@ func testFile(t *testing.T, file string, bs string, holders []BucketFactory, res
|
||||||
tf := TestFile{}
|
tf := TestFile{}
|
||||||
err = dec.Decode(&tf)
|
err = dec.Decode(&tf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err == io.EOF {
|
if err != io.EOF {
|
||||||
log.Warningf("end of test file")
|
|
||||||
} else {
|
|
||||||
t.Errorf("Failed to load testfile '%s' yaml error : %v", file, err)
|
t.Errorf("Failed to load testfile '%s' yaml error : %v", file, err)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
log.Warningf("end of test file")
|
||||||
}
|
}
|
||||||
var latest_ts time.Time
|
var latest_ts time.Time
|
||||||
for _, in := range tf.Lines {
|
for _, in := range tf.Lines {
|
||||||
|
@ -232,7 +231,7 @@ POLL_AGAIN:
|
||||||
log.Infof("dumped bucket to %s", tmpFile)
|
log.Infof("dumped bucket to %s", tmpFile)
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
} else {
|
}
|
||||||
log.Warningf("%d results to check against %d expected results", len(results), len(tf.Results))
|
log.Warningf("%d results to check against %d expected results", len(results), len(tf.Results))
|
||||||
if len(tf.Results) != len(results) {
|
if len(tf.Results) != len(results) {
|
||||||
if dump {
|
if dump {
|
||||||
|
@ -240,12 +239,10 @@ POLL_AGAIN:
|
||||||
t.Fatalf("Failed dumping bucket state : %s", err)
|
t.Fatalf("Failed dumping bucket state : %s", err)
|
||||||
}
|
}
|
||||||
log.Infof("dumped bucket to %s", tmpFile)
|
log.Infof("dumped bucket to %s", tmpFile)
|
||||||
|
|
||||||
}
|
}
|
||||||
log.Errorf("results / expected count doesn't match results = %d / expected = %d", len(results), len(tf.Results))
|
log.Errorf("results / expected count doesn't match results = %d / expected = %d", len(results), len(tf.Results))
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
|
||||||
checkresultsloop:
|
checkresultsloop:
|
||||||
for eidx, out := range results {
|
for eidx, out := range results {
|
||||||
for ridx, expected := range tf.Results {
|
for ridx, expected := range tf.Results {
|
||||||
|
@ -260,29 +257,27 @@ POLL_AGAIN:
|
||||||
log.Printf("Here ?")
|
log.Printf("Here ?")
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
//Scenario
|
|
||||||
|
|
||||||
|
//Scenario
|
||||||
if *out.Overflow.Alert.Scenario != *expected.Overflow.Alert.Scenario {
|
if *out.Overflow.Alert.Scenario != *expected.Overflow.Alert.Scenario {
|
||||||
log.Errorf("(scenario) %v != %v", *out.Overflow.Alert.Scenario, *expected.Overflow.Alert.Scenario)
|
log.Errorf("(scenario) %v != %v", *out.Overflow.Alert.Scenario, *expected.Overflow.Alert.Scenario)
|
||||||
continue
|
continue
|
||||||
} else {
|
|
||||||
log.Infof("(scenario) %v == %v", *out.Overflow.Alert.Scenario, *expected.Overflow.Alert.Scenario)
|
|
||||||
}
|
}
|
||||||
|
log.Infof("(scenario) %v == %v", *out.Overflow.Alert.Scenario, *expected.Overflow.Alert.Scenario)
|
||||||
|
|
||||||
//EventsCount
|
//EventsCount
|
||||||
if *out.Overflow.Alert.EventsCount != *expected.Overflow.Alert.EventsCount {
|
if *out.Overflow.Alert.EventsCount != *expected.Overflow.Alert.EventsCount {
|
||||||
log.Errorf("(EventsCount) %d != %d", *out.Overflow.Alert.EventsCount, *expected.Overflow.Alert.EventsCount)
|
log.Errorf("(EventsCount) %d != %d", *out.Overflow.Alert.EventsCount, *expected.Overflow.Alert.EventsCount)
|
||||||
continue
|
continue
|
||||||
} else {
|
|
||||||
log.Infof("(EventsCount) %d == %d", *out.Overflow.Alert.EventsCount, *expected.Overflow.Alert.EventsCount)
|
|
||||||
}
|
}
|
||||||
|
log.Infof("(EventsCount) %d == %d", *out.Overflow.Alert.EventsCount, *expected.Overflow.Alert.EventsCount)
|
||||||
|
|
||||||
//Sources
|
//Sources
|
||||||
if !reflect.DeepEqual(out.Overflow.Sources, expected.Overflow.Sources) {
|
if !reflect.DeepEqual(out.Overflow.Sources, expected.Overflow.Sources) {
|
||||||
log.Errorf("(Sources %s != %s)", spew.Sdump(out.Overflow.Sources), spew.Sdump(expected.Overflow.Sources))
|
log.Errorf("(Sources %s != %s)", spew.Sdump(out.Overflow.Sources), spew.Sdump(expected.Overflow.Sources))
|
||||||
continue
|
continue
|
||||||
} else {
|
|
||||||
log.Infof("(Sources: %s == %s)", spew.Sdump(out.Overflow.Sources), spew.Sdump(expected.Overflow.Sources))
|
|
||||||
}
|
}
|
||||||
|
log.Infof("(Sources: %s == %s)", spew.Sdump(out.Overflow.Sources), spew.Sdump(expected.Overflow.Sources))
|
||||||
}
|
}
|
||||||
//Events
|
//Events
|
||||||
// if !reflect.DeepEqual(out.Overflow.Alert.Events, expected.Overflow.Alert.Events) {
|
// if !reflect.DeepEqual(out.Overflow.Alert.Events, expected.Overflow.Alert.Events) {
|
||||||
|
@ -309,9 +304,7 @@ POLL_AGAIN:
|
||||||
log.Errorf("we got: %s", spew.Sdump(results))
|
log.Errorf("we got: %s", spew.Sdump(results))
|
||||||
log.Errorf("we expected: %s", spew.Sdump(tf.Results))
|
log.Errorf("we expected: %s", spew.Sdump(tf.Results))
|
||||||
return false
|
return false
|
||||||
} else {
|
}
|
||||||
log.Warningf("entry valid at end of loop")
|
log.Warningf("entry valid at end of loop")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
|
@ -156,13 +156,12 @@ func LoadBuckets(cscfg *csconfig.CrowdsecServiceCfg, files []string, tomb *tomb.
|
||||||
bucketFactory := BucketFactory{}
|
bucketFactory := BucketFactory{}
|
||||||
err = dec.Decode(&bucketFactory)
|
err = dec.Decode(&bucketFactory)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err == io.EOF {
|
if err != io.EOF {
|
||||||
log.Tracef("End of yaml file")
|
|
||||||
break
|
|
||||||
} else {
|
|
||||||
log.Errorf("Bad yaml in %s : %v", f, err)
|
log.Errorf("Bad yaml in %s : %v", f, err)
|
||||||
return nil, nil, fmt.Errorf("bad yaml in %s : %v", f, err)
|
return nil, nil, fmt.Errorf("bad yaml in %s : %v", f, err)
|
||||||
}
|
}
|
||||||
|
log.Tracef("End of yaml file")
|
||||||
|
break
|
||||||
}
|
}
|
||||||
bucketFactory.DataDir = cscfg.DataDir
|
bucketFactory.DataDir = cscfg.DataDir
|
||||||
//check empty
|
//check empty
|
||||||
|
|
|
@ -59,15 +59,15 @@ func GarbageCollectBuckets(deadline time.Time, buckets *Buckets) error {
|
||||||
toflush = append(toflush, key)
|
toflush = append(toflush, key)
|
||||||
val.tomb.Kill(nil)
|
val.tomb.Kill(nil)
|
||||||
return true
|
return true
|
||||||
} else {
|
|
||||||
val.logger.Tracef("(%s) not dead, count:%f capacity:%f", val.First_ts, tokat, tokcapa)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val.logger.Tracef("(%s) not dead, count:%f capacity:%f", val.First_ts, tokat, tokcapa)
|
||||||
if _, ok := serialized[key]; ok {
|
if _, ok := serialized[key]; ok {
|
||||||
log.Errorf("entry %s already exists", key)
|
log.Errorf("entry %s already exists", key)
|
||||||
return false
|
return false
|
||||||
} else {
|
|
||||||
log.Debugf("serialize %s of %s : %s", val.Name, val.Uuid, val.Mapkey)
|
|
||||||
}
|
}
|
||||||
|
log.Debugf("serialize %s of %s : %s", val.Name, val.Uuid, val.Mapkey)
|
||||||
|
|
||||||
return true
|
return true
|
||||||
})
|
})
|
||||||
log.Infof("Cleaned %d buckets", len(toflush))
|
log.Infof("Cleaned %d buckets", len(toflush))
|
||||||
|
@ -118,15 +118,14 @@ func DumpBucketsStateAt(deadline time.Time, outputdir string, buckets *Buckets)
|
||||||
val.logger.Debugf("UNDERFLOW : first_ts:%s tokens_at:%f capcity:%f", val.First_ts, tokat, tokcapa)
|
val.logger.Debugf("UNDERFLOW : first_ts:%s tokens_at:%f capcity:%f", val.First_ts, tokat, tokcapa)
|
||||||
discard += 1
|
discard += 1
|
||||||
return true
|
return true
|
||||||
} else {
|
|
||||||
val.logger.Debugf("(%s) not dead, count:%f capacity:%f", val.First_ts, tokat, tokcapa)
|
|
||||||
}
|
}
|
||||||
|
val.logger.Debugf("(%s) not dead, count:%f capacity:%f", val.First_ts, tokat, tokcapa)
|
||||||
|
|
||||||
if _, ok := serialized[key]; ok {
|
if _, ok := serialized[key]; ok {
|
||||||
log.Errorf("entry %s already exists", key)
|
log.Errorf("entry %s already exists", key)
|
||||||
return false
|
return false
|
||||||
} else {
|
|
||||||
log.Debugf("serialize %s of %s : %s", val.Name, val.Uuid, val.Mapkey)
|
|
||||||
}
|
}
|
||||||
|
log.Debugf("serialize %s of %s : %s", val.Name, val.Uuid, val.Mapkey)
|
||||||
val.SerializedState = val.Limiter.Dump()
|
val.SerializedState = val.Limiter.Dump()
|
||||||
serialized[key] = *val
|
serialized[key] = *val
|
||||||
return true
|
return true
|
||||||
|
|
|
@ -51,13 +51,12 @@ func (u *OverflowFilter) OnBucketOverflow(Bucket *BucketFactory) func(*Leaky, ty
|
||||||
}
|
}
|
||||||
/*filter returned false, event is blackholded*/
|
/*filter returned false, event is blackholded*/
|
||||||
if !element {
|
if !element {
|
||||||
l.logger.Infof("Event is discard by overflow filter (%s)", u.Filter)
|
l.logger.Infof("Event is discarded by overflow filter (%s)", u.Filter)
|
||||||
return types.RuntimeAlert{
|
return types.RuntimeAlert{
|
||||||
Mapkey: l.Mapkey,
|
Mapkey: l.Mapkey,
|
||||||
}, nil
|
}, nil
|
||||||
} else {
|
|
||||||
l.logger.Tracef("Event is not discard by overflow filter (%s)", u.Filter)
|
|
||||||
}
|
}
|
||||||
|
l.logger.Tracef("Event is not discarded by overflow filter (%s)", u.Filter)
|
||||||
return s, q
|
return s, q
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,16 +64,14 @@ func SourceFromEvent(evt types.Event, leaky *Leaky) (map[string]models.Source, e
|
||||||
src := models.Source{}
|
src := models.Source{}
|
||||||
switch leaky.scopeType.Scope {
|
switch leaky.scopeType.Scope {
|
||||||
case types.Range, types.Ip:
|
case types.Range, types.Ip:
|
||||||
if v, ok := evt.Meta["source_ip"]; ok {
|
v, ok := evt.Meta["source_ip"]
|
||||||
if net.ParseIP(v) == nil {
|
if !ok {
|
||||||
return srcs, fmt.Errorf("scope is %s but '%s' isn't a valid ip", leaky.scopeType.Scope, v)
|
|
||||||
} else {
|
|
||||||
src.IP = v
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return srcs, fmt.Errorf("scope is %s but Meta[source_ip] doesn't exist", leaky.scopeType.Scope)
|
return srcs, fmt.Errorf("scope is %s but Meta[source_ip] doesn't exist", leaky.scopeType.Scope)
|
||||||
}
|
}
|
||||||
|
if net.ParseIP(v) == nil {
|
||||||
|
return srcs, fmt.Errorf("scope is %s but '%s' isn't a valid ip", leaky.scopeType.Scope, v)
|
||||||
|
}
|
||||||
|
src.IP = v
|
||||||
src.Scope = &leaky.scopeType.Scope
|
src.Scope = &leaky.scopeType.Scope
|
||||||
if v, ok := evt.Enriched["ASNumber"]; ok {
|
if v, ok := evt.Enriched["ASNumber"]; ok {
|
||||||
src.AsNumber = v
|
src.AsNumber = v
|
||||||
|
@ -104,7 +102,8 @@ func SourceFromEvent(evt types.Event, leaky *Leaky) (map[string]models.Source, e
|
||||||
_, ipNet, err := net.ParseCIDR(v)
|
_, ipNet, err := net.ParseCIDR(v)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return srcs, fmt.Errorf("Declared range %s of %s can't be parsed", v, src.IP)
|
return srcs, fmt.Errorf("Declared range %s of %s can't be parsed", v, src.IP)
|
||||||
} else if ipNet != nil {
|
}
|
||||||
|
if ipNet != nil {
|
||||||
src.Range = ipNet.String()
|
src.Range = ipNet.String()
|
||||||
leaky.logger.Tracef("Valid range from %s : %s", src.IP, src.Range)
|
leaky.logger.Tracef("Valid range from %s : %s", src.IP, src.Range)
|
||||||
}
|
}
|
||||||
|
@ -116,7 +115,9 @@ func SourceFromEvent(evt types.Event, leaky *Leaky) (map[string]models.Source, e
|
||||||
}
|
}
|
||||||
srcs[*src.Value] = src
|
srcs[*src.Value] = src
|
||||||
default:
|
default:
|
||||||
if leaky.scopeType.RunTimeFilter != nil {
|
if leaky.scopeType.RunTimeFilter == nil {
|
||||||
|
return srcs, fmt.Errorf("empty scope information")
|
||||||
|
}
|
||||||
retValue, err := expr.Run(leaky.scopeType.RunTimeFilter, exprhelpers.GetExprEnv(map[string]interface{}{"evt": &evt}))
|
retValue, err := expr.Run(leaky.scopeType.RunTimeFilter, exprhelpers.GetExprEnv(map[string]interface{}{"evt": &evt}))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return srcs, errors.Wrapf(err, "while running scope filter")
|
return srcs, errors.Wrapf(err, "while running scope filter")
|
||||||
|
@ -130,9 +131,6 @@ func SourceFromEvent(evt types.Event, leaky *Leaky) (map[string]models.Source, e
|
||||||
src.Scope = new(string)
|
src.Scope = new(string)
|
||||||
*src.Scope = leaky.scopeType.Scope
|
*src.Scope = leaky.scopeType.Scope
|
||||||
srcs[*src.Value] = src
|
srcs[*src.Value] = src
|
||||||
} else {
|
|
||||||
return srcs, fmt.Errorf("empty scope information")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return srcs, nil
|
return srcs, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,9 +43,8 @@ func (u *CancelOnFilter) OnBucketPour(bucketFactory *BucketFactory) func(types.E
|
||||||
leaky.logger.Debugf("reset_filter matched, kill bucket")
|
leaky.logger.Debugf("reset_filter matched, kill bucket")
|
||||||
leaky.Suicide <- true
|
leaky.Suicide <- true
|
||||||
return nil //counter intuitively, we need to keep the message so that it doesn't trigger an endless loop
|
return nil //counter intuitively, we need to keep the message so that it doesn't trigger an endless loop
|
||||||
} else {
|
|
||||||
leaky.logger.Debugf("reset_filter didn't match")
|
|
||||||
}
|
}
|
||||||
|
leaky.logger.Debugf("reset_filter didn't match")
|
||||||
}
|
}
|
||||||
return &msg
|
return &msg
|
||||||
}
|
}
|
||||||
|
|
|
@ -97,7 +97,6 @@ func (lim *Limiter) Load(st Lstate) {
|
||||||
lim.tokens = st.Tokens
|
lim.tokens = st.Tokens
|
||||||
lim.last = st.Last
|
lim.last = st.Last
|
||||||
lim.lastEvent = st.LastEvent
|
lim.lastEvent = st.LastEvent
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Limit returns the maximum overall event rate.
|
// Limit returns the maximum overall event rate.
|
||||||
|
|
|
@ -81,7 +81,7 @@ type RuntimeAlert struct {
|
||||||
|
|
||||||
func (r RuntimeAlert) GetSources() []string {
|
func (r RuntimeAlert) GetSources() []string {
|
||||||
ret := make([]string, 0)
|
ret := make([]string, 0)
|
||||||
for key, _ := range r.Sources {
|
for key := range r.Sources {
|
||||||
ret = append(ret, key)
|
ret = append(ret, key)
|
||||||
}
|
}
|
||||||
return ret
|
return ret
|
||||||
|
|
|
@ -38,18 +38,20 @@ func Addr2Ints(any string) (int, int64, int64, int64, int64, error) {
|
||||||
return -1, 0, 0, 0, 0, errors.Wrapf(err, "while parsing range %s", any)
|
return -1, 0, 0, 0, 0, errors.Wrapf(err, "while parsing range %s", any)
|
||||||
}
|
}
|
||||||
return Range2Ints(*net)
|
return Range2Ints(*net)
|
||||||
} else {
|
}
|
||||||
|
|
||||||
ip := net.ParseIP(any)
|
ip := net.ParseIP(any)
|
||||||
if ip == nil {
|
if ip == nil {
|
||||||
return -1, 0, 0, 0, 0, fmt.Errorf("invalid address")
|
return -1, 0, 0, 0, 0, fmt.Errorf("invalid address")
|
||||||
}
|
}
|
||||||
|
|
||||||
sz, start, end, err := IP2Ints(ip)
|
sz, start, end, err := IP2Ints(ip)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return -1, 0, 0, 0, 0, errors.Wrapf(err, "while parsing ip %s", any)
|
return -1, 0, 0, 0, 0, errors.Wrapf(err, "while parsing ip %s", any)
|
||||||
}
|
}
|
||||||
|
|
||||||
return sz, start, end, start, end, nil
|
return sz, start, end, start, end, nil
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/*size (16|4), nw_start, suffix_start, nw_end, suffix_end, error*/
|
/*size (16|4), nw_start, suffix_start, nw_end, suffix_end, error*/
|
||||||
func Range2Ints(network net.IPNet) (int, int64, int64, int64, int64, error) {
|
func Range2Ints(network net.IPNet) (int, int64, int64, int64, int64, error) {
|
||||||
|
|
|
@ -96,9 +96,8 @@ func (n *EmailPlugin) Notify(ctx context.Context, notification *protobufs.Notifi
|
||||||
err = email.Send(smtpClient)
|
err = email.Send(smtpClient)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return &protobufs.Empty{}, err
|
return &protobufs.Empty{}, err
|
||||||
} else {
|
|
||||||
logger.Info(fmt.Sprintf("sent email to %v", cfg.ReceiverEmails))
|
|
||||||
}
|
}
|
||||||
|
logger.Info(fmt.Sprintf("sent email to %v", cfg.ReceiverEmails))
|
||||||
return &protobufs.Empty{}, nil
|
return &protobufs.Empty{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue