diff --git a/nezha-fronted/src/components/common/rightBox/editEndpointBoxNew.vue b/nezha-fronted/src/components/common/rightBox/editEndpointBoxNew.vue index 21120604f..cd3551438 100644 --- a/nezha-fronted/src/components/common/rightBox/editEndpointBoxNew.vue +++ b/nezha-fronted/src/components/common/rightBox/editEndpointBoxNew.vue @@ -100,6 +100,8 @@ + +
@@ -112,7 +114,7 @@ - + @@ -126,42 +128,42 @@ + { validator: port, trigger: 'blur' }, + { required: true, message: $t('validate.required'), trigger: 'blur' } + ]">
- - -
{{$t('project.module.walk')}}
-
- - - - + + + +
@@ -169,6 +171,7 @@
+
@@ -193,6 +196,7 @@
+
@@ -213,11 +217,12 @@
- - - + + +
+
@@ -232,19 +237,20 @@
- - - + + +
+
{{$t('project.endpoint.item') + index}} - - - + + +
@@ -256,9 +262,9 @@ :prop="'configs.0.config.relabel_config.' + index + '.source_labels'" class="half-form-item" :label="$t('overall.sourceLabels')" :rules="[ - { required: item.action === 'replace' || item.action === 'keep' || item.action === 'drop', message: $t('validate.required'), trigger: 'change' }, - { validator: item.action === 'replace' || item.action === 'keep' || item.action === 'drop'? arrLength : requirdRelabel, trigger: 'change' } - ]"> + { required: item.action === 'replace' || item.action === 'keep' || item.action === 'drop', message: $t('validate.required'), trigger: 'change' }, + { validator: item.action === 'replace' || item.action === 'keep' || item.action === 'drop'? arrLength : requirdRelabel, trigger: 'change' } + ]"> + { required: item.action === 'replace', message: $t('validate.required'), trigger: 'blur' }, + { pattern: /[a-zA-Z_][a-zA-Z0-9_]*/, message: $t('overall.ASCIIKey') ,trigger: 'blur'}]" + >
- +
@@ -303,10 +309,10 @@
- - {{$t('overall.moreOption')}} - - + + {{$t('overall.moreOption')}} + +
@@ -316,6 +322,7 @@
+ @@ -325,25 +332,27 @@ - + - + - + + +
- + {{$t('overall.logs')}} @@ -352,13 +361,15 @@
+ - - + + + + + + + + + + + + + + + + + + + + + + +
+
+
+ {{$t('project.endpoint.item') + subIndex}} + + + +
+
+ + + + + + + + + + + +
+ + +
+ + + + + + + + +
+
+
+ + {{$t('overall.moreOption')}} + + +
+
+
+
+ + + +
+
+
@@ -407,11 +540,12 @@
- - - + + +
+
@@ -495,7 +629,7 @@ :prop="'configs.1.config.'+ index +'.pipeline.' + index2 + '.format'" :rules="[{ required: true, message: $t('validate.required'), trigger: 'blur' }]" > - + @@ -545,12 +679,36 @@ + + + + + + + + + + + + + + + + + + + + + + + + - - + +
-
+
@@ -706,7 +864,12 @@ export default { { value: 'syslog', name: 'Syslog' + }, + { + value: 'kubernetes', + name: 'Kubernetes' } + ], authType: 0, authTypeList: [ @@ -714,6 +877,8 @@ export default { { name: this.$t('project.endpoint.authTypeWord'), value: 1 }, { name: this.$t('project.endpoint.authTypeToken'), value: 2 } ], + + logsAuthType: [0], endpointStateList: [ { name: this.$t('overall.enabled'), value: 1 }, { name: this.$t('profile.close'), value: 0 } @@ -810,7 +975,30 @@ export default { label: 'Labelkeep' }], metricsShow: true, - logsShow: true + logsShow: true, + + logsRoleList: [ + { + value: 'endpoints', + label: 'endpoints' + }, + { + value: 'service', + label: 'service' + }, + { + value: 'pod', + label: 'pod' + }, + { + value: 'node', + label: 'node' + }, + { + value: 'ingress', + label: 'ingress' + } + ] } }, methods: { @@ -957,18 +1145,11 @@ export default { pipeline.expressions = this.labelsToJson(pipeline.expressions) } }) - if (item.type === 'file') { - delete item.unit - delete item.appName - delete item.listenAddress - } else if (item.type === 'journal') { - delete item.fileName - delete item.appName - delete item.listenAddress - } else if (item.type === 'syslog') { - delete item.fileName - delete item.unit - } + item.namespaces && delete item.namespaces.tags + item.relabel_config && item.relabel_config.forEach(subItem => { + delete subItem.tags + delete subItem.showAllRelabelOption + }) }) params.configs[0].config.relabel_config && params.configs[0].config.relabel_config.forEach(item => { delete item.tags @@ -998,8 +1179,11 @@ export default { this.activeNameLogs[keyArr[3]] = 'Labels' } else if (str === 'pipeline') { this.activeNameLogs[keyArr[3]] = 'Pipeline' + } else if (str === 'relabel_config') { + this.activeNameLogs[keyArr[3]] = 'Relabel' + } else if (str === 'basic_auth' || str === 'bearer_token') { + this.activeNameLogs[keyArr[3]] = 'Auth' } - this.activeNameLogs = [...this.activeNameLogs] } } @@ -1069,31 +1253,64 @@ export default { }) }) }, - logsLogsArrAdd () { + logsArrAdd () { this.activeNameLogs.push('Basic') this.logsCopyValue.push('') + this.logsAuthType.push(0) this.editEndpoint.configs[1].config.push({ type: 'file', fileName: '', unit: '', appName: '', listenAddress: '', + apiServer: '', + role: '', + namespaces: { + tags: '', + names: [] + }, labels: '', labelModule: [{ key: '', value: '' }], - pipeline: [] + pipeline: [], + basic_auth: { + username: '', + password: '' + }, + bearer_token: '', + relabel_config: [] }) }, removeLogsArr (index) { if (this.editEndpoint.configs[1].config.length !== 1) { + this.activeNameLogs.splice(index, 1) + this.logsCopyValue.splice(index, 1) + this.logsAuthType.splice(index, 1) this.editEndpoint.configs[1].config.splice(index, 1) } }, - logsBasicTypeChange (i) { - this.editEndpoint.configs[1].config[i].fileName = '' - this.editEndpoint.configs[1].config[i].unit = '' - this.editEndpoint.configs[1].config[i].appName = '' - this.editEndpoint.configs[1].config[i].listenAddress = '' + logsBasicTypeChange (item, val) { + item.fileName = '' + item.unit = '' + item.appName = '' + item.listenAddress = '' + item.apiServer = '' + item.role = '' + this.$set(item, 'namespaces', { + tags: '', + names: [] + }) + if (val === 'kubernetes') { + item.apiServer = '127.0.0.1' + item.role = 'pod' + } else { + item.bearer_token = '' + item.basic_auth = { + username: '', + password: '' + } + } }, + /* 获取project列表 */ getProjectList () { this.$get('monitor/project', { pageSize: -1, pageNo: 1 }).then(response => { @@ -1159,22 +1376,6 @@ export default { } this.editEndpoint.labelModule.splice(index, 1) }, - tagsChange (newTags, index) { - this.editEndpoint.paramObj[index].value = newTags.map(item => item.text) - }, - beforeAddingTag (tag) { - const regx = /[a-zA-Z_][a-zA-Z0-9_]*/ - if (regx.test(tag.tag.text)) { - tag.addTag() - } else { - this.$message.error(this.$t('tip.tagError')) - } - }, - relabelTabBlur (tag) { - this.$nextTick(() => { - this.$refs.relabelTag[0].newTag = '' - }) - }, // 将param转为json字符串格式 paramToJson (param) { const tempParam = {} @@ -1209,13 +1410,33 @@ export default { return (restaurant.value.toLowerCase().indexOf(queryString.toLowerCase()) === 0) } }, + + changeBasicType () { + if (this.editEndpoint.configs[0].config.protocol === 'snmp') { + this.editEndpoint.configs[0].config.metrics_path = '' + this.editEndpoint.configs[0].config.bearer_token = '' + this.editEndpoint.configs[0].config.basic_auth = { + username: '', + password: '' + } + } + }, changeAuthType () { - this.editEndpoint.configs.bearer_token = '' - this.editEndpoint.configs.basic_auth = { + this.editEndpoint.configs[0].config.bearer_token = '' + this.editEndpoint.configs[0].config.basic_auth = { username: '', password: '' } }, + + logsAuthTypeChange (item) { + this.$set(item, 'bearer_token', '') + this.$set(item, 'basic_auth', { + username: '', + password: '' + }) + }, + copyValue () { const domUrl = document.createElement('input') domUrl.value = this.configsCopyValue @@ -1373,6 +1594,23 @@ export default { this.$post('/monitor/endpoint/render', { moduleIds: this.editEndpoint.moduleId, assetIds: this.editEndpoint.assetId }).then(res => { this.editEndpoint.configs = JSON.parse(res.data.list[0].configs) this.activeNameLogs = this.editEndpoint.configs[1].config.map(() => 'Basic') + if (this.editEndpoint.configs[0].config.bearer_token) { + this.authType = 2 + } else if (this.editEndpoint.configs[0].config.basic_auth.username) { + this.authType = 1 + } else { + this.authType = 0 + } + + this.editEndpoint.configs[1].config.forEach((item, index) => { + if (item.bearer_token) { + this.logsAuthType[index] = 2 + } else if (item.basic_auth && item.basic_auth.username) { + this.logsAuthType[index] = 1 + } else { + this.logsAuthType[index] = 0 + } + }) this.editEndpoint.configs[1].config.forEach(item => { item.labelModule = [] if (JSON.stringify(item.labels) !== '{}' && item.labels) { @@ -1406,24 +1644,19 @@ export default { pipeline.expressions = expressionsArr } }) - if (item.type === 'file') { - item.unit = '' - item.appName = '' - item.listenAddress = '' - } else if (item.type === 'journal') { - item.fileName = '' - item.appName = '' - item.listenAddress = '' - } else if (item.type === 'syslog') { - item.fileName = '' - item.unit = '' + if (!item.relabel_config) { + this.$set(item, 'relabel_config', []) } + item.relabel_config && item.relabel_config.forEach(item => { + this.$set(item, 'showAllRelabelOption', false) + this.$set(item, 'tags', '') + }) }) this.editEndpoint.paramObj = [] this.editEndpoint.labelModule = [] this.editEndpoint.configs[0].config.relabel_config && this.editEndpoint.configs[0].config.relabel_config.forEach(item => { - item.showAllRelabelOption = false - item.tags = '' + this.$set(item, 'showAllRelabelOption', false) + this.$set(item, 'tags', '') }) if (JSON.stringify(this.editEndpoint.configs[0].config.labels) !== '{}' && this.editEndpoint.configs[0].config.labels) { Object.keys(this.editEndpoint.configs[0].config.labels).forEach(key => { @@ -1446,6 +1679,30 @@ export default { }) } }, + + actionChange (index) { + this.$refs.moduleForm.clearValidate('configs.0.config.relabel_config.' + index + '.target_label') + this.$refs.moduleForm.clearValidate('configs.0.config.relabel_config.' + index + '.source_labels') + this.$refs.moduleForm.clearValidate('configs.0.config.relabel_config.' + index + '.regex') + this.$refs.moduleForm.clearValidate('configs.0.config.relabel_config.' + index + '.replacement') + }, + logsActionChange (index, subIndex) { + this.$refs.moduleForm.clearValidate('configs.1.config.' + index + '.relabel_config.' + subIndex + '.target_label') + this.$refs.moduleForm.clearValidate('configs.1.config.' + index + '.relabel_config.' + subIndex + '.source_labels') + this.$refs.moduleForm.clearValidate('configs.1.config.' + index + '.relabel_config.' + subIndex + '.regex') + this.$refs.moduleForm.clearValidate('configs.1.config.' + index + '.relabel_config.' + subIndex + '.replacement') + }, + + addRelabel () { + this.editEndpoint.configs[0].config.relabel_config.push({ + source_labels: [], + target_label: '', + action: 'replace', + regex: '(.*)', + replacement: '$1', + showAllRelabelOption: false + }) + }, removeRelabel (index) { // if (this.editEndpoint.configs[0].config.relabel_config.length === 1) { // this.editEndpoint.configs[0].config.relabel_config = [{ @@ -1461,24 +1718,54 @@ export default { this.editEndpoint.configs[0].config.relabel_config.splice(index, 1) this.$refs.moduleForm.clearValidate() }, + + logsAddRelabel (index) { + this.editEndpoint.configs[1].config[index].relabel_config.push({ + source_labels: [], + target_label: '', + action: '', + regex: '(.*)', + replacement: '$1', + showAllRelabelOption: false + }) + }, + logsRemoveRelabel (index, subIndex) { + this.editEndpoint.configs[1].config[index].relabel_config.splice(subIndex, 1) + this.$refs.moduleForm.clearValidate() + }, + + tagsChange (newTags, index) { + this.editEndpoint.paramObj[index].value = newTags.map(item => item.text) + }, + logsTagsChange (newTags, item) { + this.$set(item.namespaces, 'names', newTags.map(item => item.text)) + }, + + beforeAddingTag (tag) { + const regx = /[a-zA-Z_][a-zA-Z0-9_]*/ + if (regx.test(tag.tag.text)) { + tag.addTag() + } else { + this.$message.error(this.$t('tip.tagError')) + } + }, tagsChangeRelabel (newTags, index) { this.editEndpoint.configs[0].config.relabel_config[index].source_labels = newTags.map(item => item.text) this.$refs.moduleForm.clearValidate('configs.0.config.relabel_config.' + index + '.source_labels') }, - actionChange (index) { - this.$refs.moduleForm.clearValidate('configs.0.config.relabel_config.' + index + '.target_label') - this.$refs.moduleForm.clearValidate('configs.0.config.relabel_config.' + index + '.source_labels') - this.$refs.moduleForm.clearValidate('configs.0.config.relabel_config.' + index + '.regex') - this.$refs.moduleForm.clearValidate('configs.0.config.relabel_config.' + index + '.replacement') + relabelTabBlur (tag) { + this.$nextTick(() => { + this.$refs.relabelTag[0].newTag = '' + }) }, - addRelabel () { - this.editEndpoint.configs[0].config.relabel_config.push({ - source_labels: [], - target_label: '', - action: 'replace', - regex: '(.*)', - replacement: '$1', - showAllRelabelOption: false + + logsTagsChangeRelabel (newTags, index, subIndex) { + this.editEndpoint.configs[1].config[index].relabel_config[subIndex].source_labels = newTags.map(item => item.text) + this.$refs.moduleForm.clearValidate('configs.1.config.' + index + '.relabel_config.' + subIndex + '.source_labels') + }, + logsRelabelTabBlur (index, subIndex) { + this.$nextTick(() => { + this.$refs['logsRelabelTag' + index + subIndex][0].newTag = '' }) } }, @@ -1532,6 +1819,16 @@ export default { this.expandedWalkData.push(this.editEndpoint.configs[0].config.walk[i].substring(0, this.editEndpoint.configs[0].config.walk[i].lastIndexOf('.'))) } } + + this.editEndpoint.configs[1].config.forEach((item, index) => { + if (item.bearer_token) { + this.logsAuthType[index] = 2 + } else if (item.basic_auth && item.basic_auth.username) { + this.logsAuthType[index] = 1 + } else { + this.logsAuthType[index] = 0 + } + }) } }, editEndpoint: { @@ -1546,7 +1843,7 @@ export default { if (!params[0].config[key]) { delete params[0].config[key] } - if (Array.isArray(params[0].config[key]) && !params[0].config[key].length) { + if ((Array.isArray(params[0].config[key]) && !params[0].config[key].length) || (JSON.stringify(params[0].config[key]) == '{}')) { delete params[0].config[key] } }) @@ -1566,6 +1863,7 @@ export default { delete item.tags delete item.showAllRelabelOption }) + params[1].config.forEach(item => { if (item.labelModule) { item.labels = this.labelsToJson(item.labelModule) @@ -1579,18 +1877,32 @@ export default { pipeline.expressions = this.labelsToJson(pipeline.expressions) } }) - if (item.type === 'file') { - delete item.unit - delete item.appName - delete item.listenAddress - } else if (item.type === 'journal') { - delete item.fileName - delete item.appName - delete item.listenAddress - } else if (item.type === 'syslog') { - delete item.fileName - delete item.unit + + if (item.namespaces) { + delete item.namespaces.tags + if (!item.namespaces.names.length) { + delete item.namespaces.names + } } + Object.keys(item).forEach(key => { + if (!item[key]) { + delete item[key] + } + if ((Array.isArray(item[key]) && !item[key].length) || (JSON.stringify(item[key]) == '{}')) { + delete item[key] + } + }) + if (item.basic_auth && !item.basic_auth.username) { + delete item.basic_auth + } + if (item.basic_auth && !item.basic_auth.password) { + delete item.basic_auth + } + + item.relabel_config && item.relabel_config.forEach(subItem => { + delete subItem.tags + delete subItem.showAllRelabelOption + }) }) this.configsCopyValue = JSON.stringify(params, null, 2) } diff --git a/nezha-fronted/src/components/common/rightBox/moduleBox.vue b/nezha-fronted/src/components/common/rightBox/moduleBox.vue index a139bf14f..98cacbf35 100644 --- a/nezha-fronted/src/components/common/rightBox/moduleBox.vue +++ b/nezha-fronted/src/components/common/rightBox/moduleBox.vue @@ -267,6 +267,7 @@
+
@@ -491,6 +492,7 @@
+
@@ -677,8 +679,8 @@ - - + +
@@ -1220,10 +1222,10 @@ export default { this.$refs.moduleForm.clearValidate('configs.0.config.relabel_config.' + index + '.replacement') }, logsActionChange (index, subIndex) { - this.$refs.moduleForm.clearValidate('configs.1.config.' + index + '.relabel_config.' + index + '.target_label') - this.$refs.moduleForm.clearValidate('configs.1.config.' + index + '.relabel_config.' + index + '.source_labels') - this.$refs.moduleForm.clearValidate('configs.1.config.' + index + '.relabel_config.' + index + '.regex') - this.$refs.moduleForm.clearValidate('configs.1.config.' + index + '.relabel_config.' + index + '.replacement') + this.$refs.moduleForm.clearValidate('configs.1.config.' + index + '.relabel_config.' + subIndex + '.target_label') + this.$refs.moduleForm.clearValidate('configs.1.config.' + index + '.relabel_config.' + subIndex + '.source_labels') + this.$refs.moduleForm.clearValidate('configs.1.config.' + index + '.relabel_config.' + subIndex + '.regex') + this.$refs.moduleForm.clearValidate('configs.1.config.' + index + '.relabel_config.' + subIndex + '.replacement') }, addRelabel () { @@ -1336,6 +1338,7 @@ export default { return (restaurant.value.toLowerCase().indexOf(queryString.toLowerCase()) === 0) } }, + changeBasicType () { if (this.editModule.configs[0].config.protocol === 'snmp') { this.editModule.configs[0].config.metrics_path = '' @@ -1403,10 +1406,10 @@ export default { item.listenAddress = '' item.apiServer = '' item.role = '' - item.namespaces = { + this.$set(item, 'namespaces', { tags: '', names: [] - } + }) if (val === 'kubernetes') { item.apiServer = '127.0.0.1' item.role = 'pod' @@ -1418,6 +1421,7 @@ export default { } } }, + copyValue () { const domUrl = document.createElement('input') domUrl.value = this.configsCopyValue diff --git a/nezha-fronted/src/components/common/table/settings/endpointTable.vue b/nezha-fronted/src/components/common/table/settings/endpointTable.vue index 7603b70b7..edf804520 100644 --- a/nezha-fronted/src/components/common/table/settings/endpointTable.vue +++ b/nezha-fronted/src/components/common/table/settings/endpointTable.vue @@ -74,9 +74,9 @@ @mouseenter="labelHover(scope.row, item.prop, true,true, $event)" @mouseleave="labelHover(scope.row, item.prop, false,true)"> - {{scope.row.asset.name}} + {{scope.row.asset&&scope.row.asset.name}} - +