Skip to content

Commit ad02ff4

Browse files
authored
Merge pull request #3747 from akto-api-security/agent-traffic-detector-cronjob
Added AgentBasePromptDetectionCron class and integrated it into Initi…
2 parents e10a6f3 + 9f7e732 commit ad02ff4

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

apps/dashboard/src/main/java/com/akto/listener/InitializerListener.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@
225225
import com.akto.utils.crons.SyncCron;
226226
import com.akto.utils.crons.TokenGeneratorCron;
227227
import com.akto.utils.crons.UpdateSensitiveInfoInApiInfo;
228+
import com.akto.utils.crons.AgentBasePromptDetectionCron;
228229
import com.akto.utils.jobs.CleanInventory;
229230
import com.akto.utils.jobs.DeactivateCollections;
230231
import com.akto.utils.jobs.JobUtils;
@@ -278,6 +279,7 @@ public class InitializerListener implements ServletContextListener {
278279
SyncCron syncCronInfo = new SyncCron();
279280
TokenGeneratorCron tokenGeneratorCron = new TokenGeneratorCron();
280281
UpdateSensitiveInfoInApiInfo updateSensitiveInfoInApiInfo = new UpdateSensitiveInfoInApiInfo();
282+
AgentBasePromptDetectionCron agentBasePromptDetectionCron = new AgentBasePromptDetectionCron();
281283

282284
private static String domain = null;
283285
public static String subdomain = "https://app.akto.io";
@@ -2627,6 +2629,7 @@ public void accept(Account account) {
26272629
updateSensitiveInfoInApiInfo.setUpSensitiveMapInApiInfoScheduler();
26282630
syncCronInfo.setUpUpdateCronScheduler();
26292631
syncCronInfo.setUpMcpMaliciousnessCronScheduler();
2632+
agentBasePromptDetectionCron.setUpAgentBasePromptDetectionScheduler();
26302633
setUpTestEditorTemplatesScheduler();
26312634
JobsCron.instance.jobsScheduler(JobExecutorType.DASHBOARD);
26322635
updateApiGroupsForAccounts();
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package com.akto.utils.crons;
2+
3+
import java.util.concurrent.Executors;
4+
import java.util.concurrent.ScheduledExecutorService;
5+
import java.util.concurrent.TimeUnit;
6+
import java.util.function.Consumer;
7+
8+
import com.akto.dto.Account;
9+
import com.akto.log.LoggerMaker;
10+
import com.akto.log.LoggerMaker.LogDb;
11+
import com.akto.runtime.AgentBasePromptDetectionService;
12+
import com.akto.util.AccountTask;
13+
14+
public class AgentBasePromptDetectionCron {
15+
private static final LoggerMaker loggerMaker = new LoggerMaker(AgentBasePromptDetectionCron.class, LogDb.DASHBOARD);
16+
ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
17+
18+
public void setUpAgentBasePromptDetectionScheduler() {
19+
scheduler.scheduleAtFixedRate(new Runnable() {
20+
public void run() {
21+
AccountTask.instance.executeTask(new Consumer<Account>() {
22+
@Override
23+
public void accept(Account t) {
24+
try {
25+
loggerMaker.debugAndAddToDb("Starting agent base prompt detection for account: " + t.getId(), LogDb.DASHBOARD);
26+
AgentBasePromptDetectionService service = new AgentBasePromptDetectionService();
27+
service.runJob();
28+
loggerMaker.debugAndAddToDb("Completed agent base prompt detection for account: " + t.getId(), LogDb.DASHBOARD);
29+
} catch (Exception e) {
30+
loggerMaker.errorAndAddToDb(e,
31+
String.format("Error while running agent base prompt detection for account %d: %s",
32+
t.getId(), e.toString()),
33+
LogDb.DASHBOARD);
34+
}
35+
}
36+
}, "agent-base-prompt-detection");
37+
}
38+
}, 0, 24, TimeUnit.HOURS);
39+
}
40+
}
41+

0 commit comments

Comments
 (0)