Skip to content

Commit 560fe8e

Browse files
committed
threat detection dashboard fixes
1 parent 92472b6 commit 560fe8e

File tree

13 files changed

+880
-666
lines changed

13 files changed

+880
-666
lines changed

apps/dashboard/src/main/java/com/akto/action/threat_detection/SuspectSampleDataAction.java

+24-8
Original file line numberDiff line numberDiff line change
@@ -42,30 +42,47 @@ public SuspectSampleDataAction() {
4242
}
4343

4444
public String fetchSampleData() {
45-
HttpPost post = new HttpPost(String.format("%s/api/dashboard/list_malicious_requests", this.getBackendUrl()));
45+
HttpPost post = new HttpPost(
46+
String.format("%s/api/dashboard/list_malicious_requests", this.getBackendUrl()));
4647
post.addHeader("Authorization", "Bearer " + this.getApiToken());
4748
post.addHeader("Content-Type", "application/json");
4849

49-
System.out.print("API Token: " + this.getApiToken());
50+
Map<String, Object> filter = new HashMap<>();
51+
if (this.ips != null && !this.ips.isEmpty()) {
52+
filter.put("ips", this.ips);
53+
}
54+
55+
if (this.urls != null && !this.urls.isEmpty()) {
56+
filter.put("urls", this.urls);
57+
}
58+
59+
Map<String, Integer> time_range = new HashMap<>();
60+
if (this.startTimestamp > 0) {
61+
time_range.put("start", this.startTimestamp);
62+
}
63+
64+
if (this.endTimestamp > 0) {
65+
time_range.put("end", this.endTimestamp);
66+
}
67+
68+
filter.put("detected_at_time_range", time_range);
5069

5170
Map<String, Object> body = new HashMap<String, Object>() {
5271
{
5372
put("skip", skip);
5473
put("limit", LIMIT);
74+
put("sort", sort);
75+
put("filter", filter);
5576
}
5677
};
5778
String msg = objectMapper.valueToTree(body).toString();
5879

59-
System.out.println("Request body for list malicious requests" + msg);
60-
6180
StringEntity requestEntity = new StringEntity(msg, ContentType.APPLICATION_JSON);
6281
post.setEntity(requestEntity);
6382

6483
try (CloseableHttpResponse resp = this.httpClient.execute(post)) {
6584
String responseBody = EntityUtils.toString(resp.getEntity());
6685

67-
System.out.println(responseBody);
68-
6986
ProtoMessageUtils.<ListMaliciousRequestsResponse>toProtoMessage(
7087
ListMaliciousRequestsResponse.class, responseBody)
7188
.ifPresent(
@@ -83,6 +100,7 @@ public String fetchSampleData() {
83100
smr.getCountry(),
84101
smr.getDetectedAt()))
85102
.collect(Collectors.toList());
103+
this.total = m.getTotal();
86104
});
87105
} catch (Exception e) {
88106
e.printStackTrace();
@@ -100,8 +118,6 @@ public String fetchFilters() {
100118
try (CloseableHttpResponse resp = this.httpClient.execute(get)) {
101119
String responseBody = EntityUtils.toString(resp.getEntity());
102120

103-
System.out.println(responseBody);
104-
105121
ProtoMessageUtils.<FetchAlertFiltersResponse>toProtoMessage(
106122
FetchAlertFiltersResponse.class, responseBody)
107123
.ifPresent(

apps/dashboard/src/main/java/com/akto/action/threat_detection/ThreatActorAction.java

+33-29
Original file line numberDiff line numberDiff line change
@@ -38,22 +38,23 @@ public ThreatActorAction() {
3838
}
3939

4040
public String getActorsCountPerCounty() {
41-
HttpGet get = new HttpGet(String.format("%s/api/dashboard/get_actors_count_per_country", this.getBackendUrl()));
41+
HttpGet get =
42+
new HttpGet(
43+
String.format("%s/api/dashboard/get_actors_count_per_country", this.getBackendUrl()));
4244
get.addHeader("Authorization", "Bearer " + this.getApiToken());
4345
get.addHeader("Content-Type", "application/json");
4446

4547
try (CloseableHttpResponse resp = this.httpClient.execute(get)) {
4648
String responseBody = EntityUtils.toString(resp.getEntity());
4749

48-
System.out.println(responseBody);
49-
5050
ProtoMessageUtils.<ThreatActorByCountryResponse>toProtoMessage(
51-
ThreatActorByCountryResponse.class, responseBody)
51+
ThreatActorByCountryResponse.class, responseBody)
5252
.ifPresent(
5353
m -> {
54-
this.actorsCountPerCountry = m.getCountriesList().stream()
55-
.map(smr -> new ThreatActorPerCountry(smr.getCode(), smr.getCount()))
56-
.collect(Collectors.toList());
54+
this.actorsCountPerCountry =
55+
m.getCountriesList().stream()
56+
.map(smr -> new ThreatActorPerCountry(smr.getCode(), smr.getCount()))
57+
.collect(Collectors.toList());
5758
});
5859
} catch (Exception e) {
5960
e.printStackTrace();
@@ -64,42 +65,45 @@ public String getActorsCountPerCounty() {
6465
}
6566

6667
public String fetchThreatActors() {
67-
HttpPost post = new HttpPost(String.format("%s/api/dashboard/list_threat_actors", this.getBackendUrl()));
68+
HttpPost post =
69+
new HttpPost(String.format("%s/api/dashboard/list_threat_actors", this.getBackendUrl()));
6870
post.addHeader("Authorization", "Bearer " + this.getApiToken());
6971
post.addHeader("Content-Type", "application/json");
7072

71-
Map<String, Object> body = new HashMap<String, Object>() {
72-
{
73-
put("skip", skip);
74-
put("limit", LIMIT);
75-
}
76-
};
73+
Map<String, Object> body =
74+
new HashMap<String, Object>() {
75+
{
76+
put("skip", skip);
77+
put("limit", LIMIT);
78+
put("sort", sort);
79+
}
80+
};
7781
String msg = objectMapper.valueToTree(body).toString();
7882

79-
System.out.println("Request body for list threat actors" + msg);
80-
8183
StringEntity requestEntity = new StringEntity(msg, ContentType.APPLICATION_JSON);
8284
post.setEntity(requestEntity);
8385

8486
try (CloseableHttpResponse resp = this.httpClient.execute(post)) {
8587
String responseBody = EntityUtils.toString(resp.getEntity());
8688

87-
System.out.println(responseBody);
88-
8989
ProtoMessageUtils.<ListThreatActorResponse>toProtoMessage(
90-
ListThreatActorResponse.class, responseBody)
90+
ListThreatActorResponse.class, responseBody)
9191
.ifPresent(
9292
m -> {
93-
this.actors = m.getActorsList().stream()
94-
.map(
95-
smr -> new DashboardThreatActor(
96-
smr.getId(),
97-
smr.getLatestApiEndpoint(),
98-
smr.getLatestApiIp(),
99-
URLMethods.Method.fromString(smr.getLatestApiMethod()),
100-
smr.getDiscoveredAt(),
101-
smr.getCountry()))
102-
.collect(Collectors.toList());
93+
this.actors =
94+
m.getActorsList().stream()
95+
.map(
96+
smr ->
97+
new DashboardThreatActor(
98+
smr.getId(),
99+
smr.getLatestApiEndpoint(),
100+
smr.getLatestApiIp(),
101+
URLMethods.Method.fromString(smr.getLatestApiMethod()),
102+
smr.getDiscoveredAt(),
103+
smr.getCountry()))
104+
.collect(Collectors.toList());
105+
106+
this.total = m.getTotal();
103107
});
104108
} catch (Exception e) {
105109
e.printStackTrace();

apps/dashboard/src/main/java/com/akto/action/threat_detection/ThreatApiAction.java

+35-30
Original file line numberDiff line numberDiff line change
@@ -38,24 +38,26 @@ public ThreatApiAction() {
3838
}
3939

4040
public String fetchThreatCategoryCount() {
41-
HttpGet get = new HttpGet(String.format("%s/api/dashboard/get_subcategory_wise_count", this.getBackendUrl()));
41+
HttpGet get =
42+
new HttpGet(
43+
String.format("%s/api/dashboard/get_subcategory_wise_count", this.getBackendUrl()));
4244
get.addHeader("Authorization", "Bearer " + this.getApiToken());
4345
get.addHeader("Content-Type", "application/json");
4446

4547
try (CloseableHttpResponse resp = this.httpClient.execute(get)) {
4648
String responseBody = EntityUtils.toString(resp.getEntity());
4749

48-
System.out.println(responseBody);
49-
5050
ProtoMessageUtils.<ThreatCategoryWiseCountResponse>toProtoMessage(
51-
ThreatCategoryWiseCountResponse.class, responseBody)
51+
ThreatCategoryWiseCountResponse.class, responseBody)
5252
.ifPresent(
5353
m -> {
54-
this.categoryCounts = m.getCategoryWiseCountsList().stream()
55-
.map(
56-
smr -> new ThreatCategoryCount(
57-
smr.getCategory(), smr.getSubCategory(), smr.getCount()))
58-
.collect(Collectors.toList());
54+
this.categoryCounts =
55+
m.getCategoryWiseCountsList().stream()
56+
.map(
57+
smr ->
58+
new ThreatCategoryCount(
59+
smr.getCategory(), smr.getSubCategory(), smr.getCount()))
60+
.collect(Collectors.toList());
5961
});
6062
} catch (Exception e) {
6163
e.printStackTrace();
@@ -66,41 +68,44 @@ public String fetchThreatCategoryCount() {
6668
}
6769

6870
public String fetchThreatApis() {
69-
HttpPost post = new HttpPost(String.format("%s/api/dashboard/list_threat_apis", this.getBackendUrl()));
71+
HttpPost post =
72+
new HttpPost(String.format("%s/api/dashboard/list_threat_apis", this.getBackendUrl()));
7073
post.addHeader("Authorization", "Bearer " + this.getApiToken());
7174
post.addHeader("Content-Type", "application/json");
7275

73-
Map<String, Object> body = new HashMap<String, Object>() {
74-
{
75-
put("skip", skip);
76-
put("limit", LIMIT);
77-
}
78-
};
76+
Map<String, Object> body =
77+
new HashMap<String, Object>() {
78+
{
79+
put("skip", skip);
80+
put("limit", LIMIT);
81+
put("sort", sort);
82+
}
83+
};
7984
String msg = objectMapper.valueToTree(body).toString();
8085

81-
System.out.println("Request body for list threat actors" + msg);
82-
8386
StringEntity requestEntity = new StringEntity(msg, ContentType.APPLICATION_JSON);
8487
post.setEntity(requestEntity);
8588

8689
try (CloseableHttpResponse resp = this.httpClient.execute(post)) {
8790
String responseBody = EntityUtils.toString(resp.getEntity());
8891

89-
System.out.println(responseBody);
90-
9192
ProtoMessageUtils.<ListThreatApiResponse>toProtoMessage(
92-
ListThreatApiResponse.class, responseBody)
93+
ListThreatApiResponse.class, responseBody)
9394
.ifPresent(
9495
m -> {
95-
this.apis = m.getApisList().stream()
96-
.map(
97-
smr -> new DashboardThreatApi(
98-
smr.getEndpoint(),
99-
URLMethods.Method.fromString(smr.getMethod()),
100-
smr.getActorsCount(),
101-
smr.getRequestsCount(),
102-
smr.getDiscoveredAt()))
103-
.collect(Collectors.toList());
96+
this.apis =
97+
m.getApisList().stream()
98+
.map(
99+
smr ->
100+
new DashboardThreatApi(
101+
smr.getEndpoint(),
102+
URLMethods.Method.fromString(smr.getMethod()),
103+
smr.getActorsCount(),
104+
smr.getRequestsCount(),
105+
smr.getDiscoveredAt()))
106+
.collect(Collectors.toList());
107+
108+
this.total = m.getTotal();
104109
});
105110
} catch (Exception e) {
106111
e.printStackTrace();

apps/dashboard/src/main/resources/struts.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -7926,4 +7926,4 @@
79267926

79277927
</package>
79287928

7929-
</struts>
7929+
</struts>

0 commit comments

Comments
 (0)