Skip to content

Commit 0a89a40

Browse files
committed
feat: add tls connection options and setup steps for syslog integrations
Signed-off-by: Manuel Abascal <mjabascal10@gmail.com>
1 parent e3ca85b commit 0a89a40

File tree

3 files changed

+35
-30
lines changed

3 files changed

+35
-30
lines changed

frontend/src/app/app-module/guides/shared/components/log-collector.component.ts

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ import {ModalService} from '../../../../core/modal/modal.service';
33
import {
44
ModalConfirmationComponent
55
} from '../../../../shared/components/utm/util/modal-confirmation/modal-confirmation.component';
6-
import {replaceCommandTokens} from "../../../../shared/util/replace-command-tokens.util";
6+
import {replaceCommandTokens} from '../../../../shared/util/replace-command-tokens.util';
77
import {UtmModulesEnum} from '../../../shared/enum/utm-module.enum';
8-
import {PLATFORMS} from "../constant";
8+
import {PLATFORMS} from '../constant';
99

1010
@Component({
1111
selector: 'app-log-colletor',
@@ -78,13 +78,15 @@ export class LogCollectorComponent {
7878
const protocol = this.selectedProtocol && this.selectedProtocol.name === 'TCP/TLS' ? 'tcp' : this.selectedProtocol.name.toLowerCase();
7979

8080
const command = replaceCommandTokens(this.selectedPlatform.command, {
81-
PROTOCOL: protocol,
82-
AGENT_NAME: this.agentName(),
8381
ACTION: this.selectedAction && this.selectedAction.action || '',
84-
TLS: this.selectedProtocol && this.selectedProtocol.name === 'TCP/TLS' ? ' --tls' : ''
82+
AGENT_NAME: this.agentName(),
83+
PROTOCOL: protocol,
84+
TLS: this.selectedProtocol && this.selectedProtocol.name === 'TCP/TLS' &&
85+
this.selectedAction.name === 'ENABLE' ? `--tls` : ''
8586
});
8687

87-
if (this.selectedProtocol && this.selectedProtocol.name === 'TCP/TLS') {
88+
if (this.selectedProtocol && this.selectedProtocol.name === 'TCP/TLS' &&
89+
this.selectedAction.name === 'ENABLE') {
8890
const extras = this.selectedPlatform.extraCommands ? this.selectedPlatform.extraCommands : [];
8991
return [...extras, command];
9092
}
@@ -179,14 +181,6 @@ export class LogCollectorComponent {
179181
}
180182
}
181183

182-
replaceAll(command, wordsToReplace) {
183-
return Object.keys(wordsToReplace).reduce(
184-
(f, s, i) =>
185-
`${f}`.replace(new RegExp(s, 'ig'), wordsToReplace[s]),
186-
command
187-
);
188-
}
189-
190184
onChangeAction(action: any) {
191185
if (this.selectedPlatform && this.selectedProtocol && action.name === 'DISABLE') {
192186
this.openModal();

frontend/src/app/app-module/guides/shared/constant.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,8 @@ export const createFileBeatsPlatforms = (
9797
];
9898

9999
export const PLATFORMS = createPlatforms(
100-
'Start-Process "C:\\Program Files\\UTMStack\\UTMStack Agent\\utmstack_agent_service.exe" -ArgumentList \'ACTION\', \'AGENT_NAME\', \'PROTOCOL\' TLS -NoNewWindow -Wait\n',
101-
'Start-Process "C:\\Program Files\\UTMStack\\UTMStack Agent\\utmstack_agent_service_arm64.exe" -ArgumentList \'ACTION\', \'AGENT_NAME\', \'PROTOCOL\' TLS -NoNewWindow -Wait\n',
100+
'Start-Process "C:\\Program Files\\UTMStack\\UTMStack Agent\\utmstack_agent_service.exe" -ArgumentList \'ACTION\', \'AGENT_NAME\', \'PROTOCOL\', \'TLS\' -NoNewWindow -Wait\n',
101+
'Start-Process "C:\\Program Files\\UTMStack\\UTMStack Agent\\utmstack_agent_service_arm64.exe" -ArgumentList \'ACTION\', \'AGENT_NAME\', \'PROTOCOL\, \'TLS\' -NoNewWindow -Wait\n',
102102
'sudo bash -c "/opt/utmstack-linux-agent/utmstack_agent_service ACTION AGENT_NAME PROTOCOL TLS"'
103103
);
104104

frontend/src/app/shared/util/replace-command-tokens.util.ts

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,31 @@
1-
/*export function replaceCommandTokens(command: string, wordsToReplace: { [key: string]: string }) {
2-
return Object.keys(wordsToReplace)
3-
.reduce((f, s) => f.replace(new RegExp(s, 'ig'), wordsToReplace[s]), command);
4-
}*/
5-
6-
export function replaceCommandTokens(command: string, wordsToReplace: { [key: string]: string }) {
1+
export function replaceCommandTokens(command: string, wordsToReplace: { [key: string]: string }): string {
72
let cmd = command;
83

9-
Object.entries(wordsToReplace).forEach(([key, value]) => {
10-
if (!value) {
11-
const regex = new RegExp(`\\s*${key}\\b`, 'g');
12-
cmd = cmd.replace(regex, '');
13-
} else {
14-
const regex = new RegExp(`${key}\\b`, 'g');
15-
cmd = cmd.replace(regex, value);
4+
if (cmd.includes('-ArgumentList')) {
5+
6+
const args = Object.values(wordsToReplace)
7+
.filter(v => v && v.trim().length > 0)
8+
.map(v => `'${v.trim()}'`)
9+
.join(', ');
10+
11+
cmd = cmd.replace(
12+
/-ArgumentList\s+(['"].*?['"])(?=\s+-|$)/,
13+
`-ArgumentList ${args}`
14+
);
15+
} else {
16+
const match = cmd.match(/"(.*)"/);
17+
if (match) {
18+
const original = match[1];
19+
const parts = original.split(/\s+/);
20+
const fixedCommand = parts[0];
21+
const args = Object.entries(wordsToReplace)
22+
.filter(([_, v]) => v && v.trim().length > 0)
23+
.map(([_, v]) => v.trim())
24+
.join(' ');
25+
26+
cmd = cmd.replace(/"(.*)"/, `"${fixedCommand} ${args}"`);
1627
}
17-
});
28+
}
1829

1930
cmd = cmd.replace(/\s+/g, ' ').trim();
2031

0 commit comments

Comments
 (0)