forked from opensearch-project/security-analytics
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Chase Engelbrecht <[email protected]>
- Loading branch information
Showing
31 changed files
with
2,033 additions
and
18 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
11 changes: 11 additions & 0 deletions
11
tif/src/main/java/org/opensearch/securityanalytics/exceptions/FeedStoreException.java
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,11 @@ | ||
package org.opensearch.securityanalytics.exceptions; | ||
|
||
public class FeedStoreException extends RuntimeException { | ||
public FeedStoreException(final String message) { | ||
super(message); | ||
} | ||
|
||
public FeedStoreException(final String message, final Throwable cause) { | ||
super(message, cause); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
tif/src/main/java/org/opensearch/securityanalytics/exceptions/IndexAccessorException.java
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,11 @@ | ||
package org.opensearch.securityanalytics.exceptions; | ||
|
||
public class IndexAccessorException extends RuntimeException { | ||
public IndexAccessorException(final String message) { | ||
super(message); | ||
} | ||
|
||
public IndexAccessorException(final String message, final Throwable cause) { | ||
super(message, cause); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
tif/src/main/java/org/opensearch/securityanalytics/exceptions/ResourceReaderException.java
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,7 @@ | ||
package org.opensearch.securityanalytics.exceptions; | ||
|
||
public class ResourceReaderException extends RuntimeException { | ||
public ResourceReaderException(final String message) { | ||
super(message); | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
tif/src/main/java/org/opensearch/securityanalytics/feed/FeedManager.java
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,56 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
package org.opensearch.securityanalytics.feed; | ||
|
||
import com.google.common.annotations.VisibleForTesting; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.time.Duration; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.concurrent.Executors; | ||
import java.util.concurrent.ScheduledExecutorService; | ||
import java.util.concurrent.ScheduledFuture; | ||
import java.util.concurrent.ScheduledThreadPoolExecutor; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
public class FeedManager { | ||
private static final Logger log = LoggerFactory.getLogger(FeedManager.class); | ||
|
||
private final ScheduledExecutorService executorService; | ||
private final Map<String, ScheduledFuture<?>> registeredTasks; | ||
|
||
public FeedManager() { | ||
final ScheduledThreadPoolExecutor scheduledThreadPoolExecutor = new ScheduledThreadPoolExecutor(1); | ||
scheduledThreadPoolExecutor.setRemoveOnCancelPolicy(true); | ||
|
||
executorService = Executors.unconfigurableScheduledExecutorService(scheduledThreadPoolExecutor); | ||
registeredTasks = new HashMap<>(); | ||
} | ||
|
||
@VisibleForTesting | ||
FeedManager(final ScheduledExecutorService scheduledExecutorService, final Map<String, ScheduledFuture<?>> registeredTasks) { | ||
this.executorService = scheduledExecutorService; | ||
this.registeredTasks = registeredTasks; | ||
} | ||
|
||
public void registerFeedRetriever(final String feedId, final Runnable feedRetriever, final Duration refreshInterval) { | ||
if (registeredTasks.containsKey(feedId)) { | ||
log.warn("Field with ID {} already has a retriever registered. Will replace existing feed retriever with new definition.", feedId); | ||
deregisterFeedRetriever(feedId); | ||
} | ||
|
||
final ScheduledFuture<?> retrieverFuture = executorService.scheduleAtFixedRate(feedRetriever, 0, refreshInterval.toMillis(), TimeUnit.MILLISECONDS); | ||
registeredTasks.put(feedId, retrieverFuture); | ||
} | ||
|
||
public void deregisterFeedRetriever(final String feedId) { | ||
if (registeredTasks.containsKey(feedId)) { | ||
final ScheduledFuture<?> retrieverFuture = registeredTasks.remove(feedId); | ||
retrieverFuture.cancel(true); | ||
} | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
tif/src/main/java/org/opensearch/securityanalytics/feed/retriever/FeedRetriever.java
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,40 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
package org.opensearch.securityanalytics.feed.retriever; | ||
|
||
import org.opensearch.securityanalytics.connector.IOCConnector; | ||
import org.opensearch.securityanalytics.feed.store.FeedStore; | ||
import org.opensearch.securityanalytics.feed.store.model.UpdateType; | ||
import org.opensearch.securityanalytics.model.IOC; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.util.List; | ||
|
||
public class FeedRetriever implements Runnable { | ||
private static final Logger log = LoggerFactory.getLogger(FeedRetriever.class); | ||
|
||
private final IOCConnector iocConnector; | ||
private final FeedStore feedStore; | ||
private final UpdateType updateType; | ||
private final String feedId; | ||
|
||
public FeedRetriever(final IOCConnector iocConnector, final FeedStore feedStore, final UpdateType updateType, final String feedId) { | ||
this.iocConnector = iocConnector; | ||
this.feedStore = feedStore; | ||
this.updateType = updateType; | ||
this.feedId = feedId; | ||
} | ||
|
||
@Override | ||
public void run() { | ||
try { | ||
final List<IOC> iocs = iocConnector.loadIOCs(); | ||
feedStore.storeIOCs(iocs, updateType); | ||
} catch (final Exception e) { | ||
log.error("Unable to fetch feed with ID {}", feedId, e); | ||
} | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
tif/src/main/java/org/opensearch/securityanalytics/feed/store/FeedStore.java
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,20 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
package org.opensearch.securityanalytics.feed.store; | ||
|
||
import org.opensearch.securityanalytics.feed.store.model.UpdateType; | ||
import org.opensearch.securityanalytics.model.IOC; | ||
|
||
import java.util.List; | ||
|
||
public interface FeedStore { | ||
/** | ||
* Accepts a list of IOCs and stores them locally for use in feed processing | ||
* | ||
* @param iocs - A list of the IOCs to store | ||
* @param updateType - The type of update to make to the underlying store | ||
*/ | ||
void storeIOCs(List<IOC> iocs, UpdateType updateType); | ||
} |
Oops, something went wrong.