Skip to content

Commit

Permalink
Add Indices to Quickly Search for Hosts which Contacted BL Hosts (#627)
Browse files Browse the repository at this point in the history
* Add blacklisted host indices

* Fix method missing from interface

Co-authored-by: Logan L <[email protected]>
  • Loading branch information
Zalgo2462 and Logan L authored Apr 13, 2021
1 parent ce2efdc commit 5ade17b
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
5 changes: 5 additions & 0 deletions parser/fsimporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -892,6 +892,11 @@ func (fs *FSImporter) markBlacklistedPeers(hostMap map[string]*host.Input) {
if len(hostMap) > 0 {
blacklistRepo := blacklist.NewMongoRepository(fs.res)

err := blacklistRepo.CreateIndexes()
if err != nil {
fs.res.Log.Error(err)
}

// send uconns to host analysis
blacklistRepo.Upsert()
}
Expand Down
23 changes: 23 additions & 0 deletions pkg/blacklist/mongodb.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/activecm/rita/pkg/data"
"github.com/activecm/rita/resources"
"github.com/activecm/rita/util"
"github.com/globalsign/mgo"
"github.com/globalsign/mgo/bson"
)

Expand All @@ -21,6 +22,28 @@ func NewMongoRepository(res *resources.Resources) Repository {
}
}

//CreateIndexes sets up the indices needed to find hosts which contacted blacklisted hosts
func (r *repo) CreateIndexes() error {
session := r.res.DB.Session.Copy()
defer session.Close()

coll := session.DB(r.res.DB.GetSelectedDB()).C(r.res.Config.T.Structure.HostTable)

// create hosts collection
// Desired indexes
indexes := []mgo.Index{
{Key: []string{"dat.bl.ip", "dat.bl.network_uuid"}},
}

for _, index := range indexes {
err := coll.EnsureIndex(index)
if err != nil {
return err
}
}
return nil
}

//Upsert loops through every domain ....
func (r *repo) Upsert() {

Expand Down
1 change: 1 addition & 0 deletions pkg/blacklist/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

// Repository for blacklist results in host collection
type Repository interface {
CreateIndexes() error
Upsert()
}

Expand Down

0 comments on commit 5ade17b

Please sign in to comment.