This is an automated email from the ASF dual-hosted git repository.
gongchao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/hertzbeat.git
The following commit(s) were added to refs/heads/master by this push:
new 9d6227013 [improve] auto generate readable random monitor name (#2531)
9d6227013 is described below
commit 9d62270131a42c2bd63bd792145947efa3fbea86
Author: tomsun28 <[email protected]>
AuthorDate: Sat Aug 17 00:04:19 2024 +0800
[improve] auto generate readable random monitor name (#2531)
Signed-off-by: tomsun28 <[email protected]>
Co-authored-by: YuLuo <[email protected]>
---
.../monitor/monitor-new/monitor-new.component.ts | 9 +-
web-app/src/app/shared/utils/common-util.ts | 119 +++++++++++++++++++++
2 files changed, 122 insertions(+), 6 deletions(-)
diff --git
a/web-app/src/app/routes/monitor/monitor-new/monitor-new.component.ts
b/web-app/src/app/routes/monitor/monitor-new/monitor-new.component.ts
index 6534f5adf..7dc647297 100644
--- a/web-app/src/app/routes/monitor/monitor-new/monitor-new.component.ts
+++ b/web-app/src/app/routes/monitor/monitor-new/monitor-new.component.ts
@@ -18,7 +18,6 @@
*/
import { Component, Inject, OnInit } from '@angular/core';
-import { FormGroup } from '@angular/forms';
import { ActivatedRoute, ParamMap, Router } from '@angular/router';
import { I18NService } from '@core';
import { ALAIN_I18N_TOKEN, TitleService } from '@delon/theme';
@@ -33,6 +32,7 @@ import { ParamDefine } from '../../../pojo/ParamDefine';
import { AppDefineService } from '../../../service/app-define.service';
import { CollectorService } from '../../../service/collector.service';
import { MonitorService } from '../../../service/monitor.service';
+import { generateReadableRandomString } from
'../../../shared/utils/common-util';
@Component({
selector: 'app-monitor-add',
@@ -153,11 +153,8 @@ export class MonitorNewComponent implements OnInit {
}
onHostChange(hostValue: string) {
- if (this.monitor.app != 'prometheus') {
- let autoName = `${this.monitor.app.toUpperCase()}_${hostValue}`;
- if (this.monitor.name == undefined || this.monitor.name == '' ||
this.monitor.name.startsWith(this.monitor.app.toUpperCase())) {
- this.monitor.name = autoName;
- }
+ if (this.monitor.name == undefined || this.monitor.name == '') {
+ this.monitor.name = generateReadableRandomString();
}
}
diff --git a/web-app/src/app/shared/utils/common-util.ts
b/web-app/src/app/shared/utils/common-util.ts
index ebba047a5..7b7ca16bc 100644
--- a/web-app/src/app/shared/utils/common-util.ts
+++ b/web-app/src/app/shared/utils/common-util.ts
@@ -43,3 +43,122 @@ export function findDeepestSelected(nodes: any): any {
}
return deepestSelectedNode;
}
+
+export function generateReadableRandomString(): string {
+ const adjectives = [
+ 'quick',
+ 'bright',
+ 'calm',
+ 'brave',
+ 'cool',
+ 'eager',
+ 'fancy',
+ 'gentle',
+ 'happy',
+ 'jolly',
+ 'kind',
+ 'lively',
+ 'merry',
+ 'nice',
+ 'proud',
+ 'witty',
+ 'zesty',
+ 'nifty',
+ 'quirky',
+ 'unique',
+ 'vivid',
+ 'zany',
+ 'zealous',
+ 'yummy',
+ 'agile',
+ 'bold',
+ 'daring',
+ 'fearless',
+ 'gleeful',
+ 'humble',
+ 'jumpy',
+ 'keen',
+ 'loyal',
+ 'majestic',
+ 'noble',
+ 'playful',
+ 'radiant',
+ 'spirited',
+ 'tenacious',
+ 'vibrant',
+ 'wise',
+ 'youthful',
+ 'zippy',
+ 'serene',
+ 'bubbly',
+ 'dreamy',
+ 'fierce',
+ 'graceful'
+ ];
+
+ const nouns = [
+ 'fox',
+ 'lion',
+ 'eagle',
+ 'shark',
+ 'whale',
+ 'falcon',
+ 'panda',
+ 'tiger',
+ 'wolf',
+ 'otter',
+ 'lynx',
+ 'moose',
+ 'dolphin',
+ 'bear',
+ 'hawk',
+ 'zebra',
+ 'giraffe',
+ 'koala',
+ 'lemur',
+ 'lemming',
+ 'cheetah',
+ 'dragon',
+ 'owl',
+ 'rhino',
+ 'stingray',
+ 'jaguar',
+ 'panther',
+ 'elk',
+ 'ocelot',
+ 'beaver',
+ 'walrus',
+ 'gazelle',
+ 'coyote',
+ 'vulture',
+ 'iguana',
+ 'porcupine',
+ 'raccoon',
+ 'sloth',
+ 'armadillo',
+ 'chameleon',
+ 'kestrel',
+ 'weasel',
+ 'hedgehog'
+ ];
+
+ const digits = '23456789';
+ const chars = 'ABCDEFGHJKLMNPQRSTUVWXYZabcdefghjklmnpqrstuvwxyz';
+
+ // Randomly select an adjective and a noun
+ let adjective = adjectives[Math.floor(Math.random() * adjectives.length)];
+ let noun = nouns[Math.floor(Math.random() * nouns.length)];
+
+ // Randomly generate a sequence of numbers and characters
+ const randomDigits = Array.from({ length: 2 }, () =>
digits.charAt(Math.floor(Math.random() * digits.length))).join('');
+
+ const randomChars = Array.from({ length: 2 }, () =>
chars.charAt(Math.floor(Math.random() * chars.length))).join('');
+ adjective = capitalizeFirstLetter(adjective);
+ noun = capitalizeFirstLetter(noun);
+ // Combine the parts to form the final string
+ return `${adjective}_${noun}_${randomDigits}${randomChars}`;
+}
+
+function capitalizeFirstLetter(word: string): string {
+ return word.charAt(0).toUpperCase() + word.slice(1);
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]