Skip to content

Commit 99c834a

Browse files
authored
Merge pull request #1040 from utmstack/bugfix/10.5.20/update-agent-hostname
Updating front and back to fix the agent update
2 parents 2067524 + 4e63b88 commit 99c834a

File tree

4 files changed

+36
-116
lines changed

4 files changed

+36
-116
lines changed

CHANGELOG.md

-3
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@
33
- Fixed the IP location component to accurately determine whether an IP address is public or private.
44
- Fixed communication from/to agents using secure connections.
55
- Fixed negative operator evaluation matching on wrong input value due to insufficient checking in correlation engine.
6-
- Reorganized GeoIP database and threat intelligence loading into more modular functions for improved maintainability and code readability. Simplified caching, removed unused database function, and restructured rule-handling logic. Addressed minor variable renames and logging adjustments for consistency.
7-
- Removed unused docker volume configuration for GeoIp.
8-
- Fixed Kernel modules wheren't loaded because incorrect function call
96

107
## New Features
118
- Introduced new standards, sections, dashboards, and visualizations to compliance reports.

backend/src/main/java/com/park/utmstack/service/agent_manager/AgentGrpcService.java

+32-6
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,29 @@ public AuthResponseDTO updateAgentAttributes(AgentRequestVM agentRequestVM) thro
9393
final String ctx = CLASSNAME + ".updateAgentAttributes";
9494
try {
9595
AgentRequest req = agentRequestVM.getAgentRequest();
96-
Metadata customHeaders = new Metadata();
97-
customHeaders.put(Metadata.Key.of("key", Metadata.ASCII_STRING_MARSHALLER), agentRequestVM.getAgentKey());
98-
customHeaders.put(Metadata.Key.of("id", Metadata.ASCII_STRING_MARSHALLER), String.valueOf(agentRequestVM.getId()));
96+
97+
// Validating the existence of the agent.
98+
String currentUser = SecurityUtils.getCurrentUserLogin().orElseThrow(() -> new RuntimeException("No current user login"));
99+
Agent agent = null;
100+
String hostname = agentRequestVM.getHostname();
101+
102+
try {
103+
agent = blockingStub.getAgentByHostname(Hostname.newBuilder().setHostname(hostname).build());
104+
if (agent == null) {
105+
String msg = String.format("%1$s: Agent %2$s could not be updated because no information was obtained from the agent", ctx, hostname);
106+
log.error(msg);
107+
throw new Exception(msg);
108+
}
109+
} catch (StatusRuntimeException e) {
110+
if (e.getStatus().getCode() == Status.Code.NOT_FOUND) {
111+
String msg = String.format("%1$s: Agent %2$s could not be updated because was not found", ctx, hostname);
112+
log.error(msg);
113+
throw new Exception(msg);
114+
}
115+
}
116+
117+
assert agent != null;
118+
Metadata customHeaders = getCustomHeaders(agent);
99119

100120
Channel intercept = ClientInterceptors.intercept(grpcManagedChannel, MetadataUtils.newAttachHeadersInterceptor(customHeaders));
101121
AgentServiceGrpc.AgentServiceBlockingStub newStub = AgentServiceGrpc.newBlockingStub(intercept);
@@ -163,9 +183,8 @@ public void deleteAgent(String hostname) {
163183

164184
AgentDelete request = AgentDelete.newBuilder().setDeletedBy(currentUser).build();
165185

166-
Metadata customHeaders = new Metadata();
167-
customHeaders.put(Metadata.Key.of("key", Metadata.ASCII_STRING_MARSHALLER), agent.getAgentKey());
168-
customHeaders.put(Metadata.Key.of("id", Metadata.ASCII_STRING_MARSHALLER), String.valueOf(agent.getId()));
186+
assert agent != null;
187+
Metadata customHeaders = getCustomHeaders(agent);
169188

170189
Channel intercept = ClientInterceptors.intercept(grpcManagedChannel, MetadataUtils.newAttachHeadersInterceptor(customHeaders));
171190
AgentServiceGrpc.AgentServiceBlockingStub newStub = AgentServiceGrpc.newBlockingStub(intercept);
@@ -177,4 +196,11 @@ public void deleteAgent(String hostname) {
177196
throw new RuntimeException(msg);
178197
}
179198
}
199+
200+
private Metadata getCustomHeaders (Agent agent) {
201+
Metadata customHeaders = new Metadata();
202+
customHeaders.put(Metadata.Key.of("key", Metadata.ASCII_STRING_MARSHALLER), agent.getAgentKey());
203+
customHeaders.put(Metadata.Key.of("id", Metadata.ASCII_STRING_MARSHALLER), String.valueOf(agent.getId()));
204+
return customHeaders;
205+
}
180206
}
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,17 @@
11
package com.park.utmstack.web.rest.vm;
22

33
import com.park.utmstack.service.grpc.AgentRequest;
4-
5-
import javax.validation.constraints.Min;
64
import javax.validation.constraints.NotEmpty;
7-
import javax.validation.constraints.NotNull;
85

6+
/*
7+
* Use this class when you need to update agent's attributes.
8+
* To add new attributes to update, add it to the class. Actually only ip is permitted.
9+
* */
910
public class AgentRequestVM {
1011
@NotEmpty
1112
private String ip;
1213
@NotEmpty
1314
private String hostname;
14-
private String os;
15-
private String platform;
16-
private String version;
17-
@NotEmpty
18-
private String mac;
19-
private String osMajorVersion;
20-
private String osMinorVersion;
21-
private String aliases;
22-
private String addresses;
23-
@NotEmpty
24-
private String agentKey;
25-
@Min(1)
26-
private int id;
2715

2816

2917
public AgentRequestVM() {}
@@ -32,14 +20,6 @@ public AgentRequest getAgentRequest() {
3220
return AgentRequest.newBuilder()
3321
.setIp(this.ip)
3422
.setHostname(this.hostname)
35-
.setOs(this.os)
36-
.setPlatform(this.platform)
37-
.setVersion(this.version)
38-
.setMac(this.mac)
39-
.setOsMajorVersion(this.osMajorVersion)
40-
.setOsMinorVersion(this.osMinorVersion)
41-
.setAliases(this.aliases)
42-
.setAddresses(this.addresses)
4323
.build();
4424
}
4525

@@ -58,84 +38,4 @@ public String getHostname() {
5838
public void setHostname(String hostname) {
5939
this.hostname = hostname;
6040
}
61-
62-
public String getOs() {
63-
return os;
64-
}
65-
66-
public void setOs(String os) {
67-
this.os = os;
68-
}
69-
70-
public String getPlatform() {
71-
return platform;
72-
}
73-
74-
public void setPlatform(String platform) {
75-
this.platform = platform;
76-
}
77-
78-
public String getVersion() {
79-
return version;
80-
}
81-
82-
public void setVersion(String version) {
83-
this.version = version;
84-
}
85-
86-
public String getMac() {
87-
return mac;
88-
}
89-
90-
public void setMac(String mac) {
91-
this.mac = mac;
92-
}
93-
94-
public String getOsMajorVersion() {
95-
return osMajorVersion;
96-
}
97-
98-
public void setOsMajorVersion(String osMajorVersion) {
99-
this.osMajorVersion = osMajorVersion;
100-
}
101-
102-
public String getOsMinorVersion() {
103-
return osMinorVersion;
104-
}
105-
106-
public void setOsMinorVersion(String osMinorVersion) {
107-
this.osMinorVersion = osMinorVersion;
108-
}
109-
110-
public String getAliases() {
111-
return aliases;
112-
}
113-
114-
public void setAliases(String aliases) {
115-
this.aliases = aliases;
116-
}
117-
118-
public String getAddresses() {
119-
return addresses;
120-
}
121-
122-
public void setAddresses(String addresses) {
123-
this.addresses = addresses;
124-
}
125-
126-
public String getAgentKey() {
127-
return agentKey;
128-
}
129-
130-
public void setAgentKey(String agentKey) {
131-
this.agentKey = agentKey;
132-
}
133-
134-
public int getId() {
135-
return id;
136-
}
137-
138-
public void setId(int id) {
139-
this.id = id;
140-
}
14141
}

frontend/src/app/shared/components/utm/util/utm-agent-detail/utm-agent-detail.component.ts

-3
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,8 @@ export class UtmAgentDetailComponent implements OnInit {
5252
changeIp(event: string) {
5353
this.loading = true;
5454
const agent = {
55-
id: this.agent.id,
5655
hostname: this.agent.hostname,
5756
ip: this.agentIp,
58-
mac: this.macs.length > 0 ? this.macs[0] : '',
59-
agentKey: this.agent.agentKey
6057
};
6158

6259
this.agentManagerService.updateAgent(agent)

0 commit comments

Comments
 (0)