-
Notifications
You must be signed in to change notification settings - Fork 216
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #631 from akto-api-security/feature/add_analyser_logs
added logs to analyser
- Loading branch information
Showing
7 changed files
with
122 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package com.akto.dao; | ||
|
||
import com.akto.dao.context.Context; | ||
import com.akto.dto.Log; | ||
import com.mongodb.client.MongoCursor; | ||
import com.mongodb.client.MongoDatabase; | ||
import com.mongodb.client.model.CreateCollectionOptions; | ||
import com.mongodb.client.model.Indexes; | ||
import org.bson.Document; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class AnalyserLogsDao extends AccountsContextDao<Log> { | ||
|
||
public static final AnalyserLogsDao instance = new AnalyserLogsDao(); | ||
public void createIndicesIfAbsent() { | ||
boolean exists = false; | ||
String dbName = Context.accountId.get()+""; | ||
MongoDatabase db = clients[0].getDatabase(dbName); | ||
for (String col: db.listCollectionNames()){ | ||
if (getCollName().equalsIgnoreCase(col)){ | ||
exists = true; | ||
break; | ||
} | ||
}; | ||
|
||
if (!exists) { | ||
db.createCollection(getCollName(), new CreateCollectionOptions().capped(true).maxDocuments(100_000).sizeInBytes(100_000_000)); | ||
} | ||
|
||
MongoCursor<Document> cursor = db.getCollection(getCollName()).listIndexes().cursor(); | ||
List<Document> indices = new ArrayList<>(); | ||
|
||
while (cursor.hasNext()) { | ||
indices.add(cursor.next()); | ||
} | ||
|
||
if (indices.size() == 1) { | ||
instance.getMCollection().createIndex(Indexes.descending(Log.TIMESTAMP)); | ||
} | ||
} | ||
|
||
@Override | ||
public String getCollName() { | ||
return "logs_analyser"; | ||
} | ||
|
||
@Override | ||
public Class<Log> getClassT() { | ||
return Log.class; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters