Skip to content

Commit 91bb2c5

Browse files
committed
Show friendly labels for resource alert rule types, metrics, conditions and severities
1 parent 9ec5487 commit 91bb2c5

4 files changed

Lines changed: 28 additions & 2 deletions

File tree

‎ui/src/components/view/DetailsTab.vue‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@
9393
{{ sizeInGiB(dataResource.chainsize) }} GiB
9494
</div>
9595
</div>
96+
<div v-else-if="$route.meta.name === 'resourcealerts' && ['resourcetype', 'metric', 'condition', 'severity'].includes(item)">
97+
{{ resourceAlertLabel(item, dataResource[item]) }}
98+
</div>
9699
<div v-else-if="['name', 'type'].includes(item)">
97100
<span v-if="['USER.LOGIN', 'USER.LOGOUT', 'ROUTER.HEALTH.CHECKS', 'FIREWALL.CLOSE', 'ALERT.SERVICE.DOMAINROUTER'].includes(dataResource[item])">{{ $t(dataResource[item].toLowerCase()) }}</span>
98101
<span v-else>{{ dataResource[item] }}</span>
@@ -263,6 +266,7 @@ import ObjectListTable from '@/components/view/ObjectListTable'
263266
import ExternalConfigurationDetails from '@/views/extension/ExternalConfigurationDetails'
264267
import TooltipButton from '@/components/widgets/TooltipButton'
265268
import { genericCompare } from '@/utils/sort'
269+
import { resourceAlertLabel } from '@/views/resourcealert/resourceAlertOptions'
266270
import CodeHighlight from 'vue-code-highlight/src/CodeHighlight.vue'
267271
import 'vue-code-highlight/themes/prism-okaidia.css'
268272
@@ -466,6 +470,7 @@ export default {
466470
}
467471
},
468472
methods: {
473+
resourceAlertLabel,
469474
decodeUserData (userdata) {
470475
const decodedData = Buffer.from(userdata, 'base64')
471476
return decodedData.toString('utf-8')

‎ui/src/components/view/ResourceAlertsTab.vue‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@
3939
<template v-else-if="column.key === 'metricvalue'">
4040
{{ Number(text).toFixed(2) }}
4141
</template>
42+
<template v-else-if="column.key === 'metrictype'">
43+
{{ resourceAlertLabel('metrictype', text) }}
44+
</template>
4245
<template v-else-if="column.key === 'severity'">
4346
<a-tag :color="severityColor(text)">{{ text }}</a-tag>
4447
</template>
@@ -49,6 +52,7 @@
4952

5053
<script>
5154
import { getAPI } from '@/api'
55+
import { resourceAlertLabel } from '@/views/resourcealert/resourceAlertOptions'
5256
5357
// Shows the alerts of one resource, or of one rule when no resourceType is given.
5458
export default {
@@ -115,6 +119,7 @@ export default {
115119
}
116120
},
117121
methods: {
122+
resourceAlertLabel,
118123
fetchData () {
119124
if (!this.resource || !this.resource.id) return
120125
const params = { listall: true, page: this.page, pagesize: this.pageSize }

‎ui/src/config/section/infra/resourceAlertRules.js‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,19 @@
1818
import { shallowRef, defineAsyncComponent } from 'vue'
1919
import store from '@/store'
2020
import { i18n } from '@/locales'
21+
import { resourceAlertLabel } from '@/views/resourcealert/resourceAlertOptions'
22+
23+
const label = (field) => ({ [field]: (record) => resourceAlertLabel(field, record[field]) })
2124

2225
export default {
2326
name: 'resourcealerts',
2427
title: 'label.resource.alert.rules',
2528
icon: 'BellOutlined',
2629
permission: ['listResourceAlertRules'],
2730
columns: () => {
28-
const cols = ['name', 'resourcetype', {
31+
const cols = ['name', label('resourcetype'), {
2932
resourcename: (record) => record.resourceid ? record.resourcename : i18n.global.t('label.resource.alert.all.resources')
30-
}, 'metric', 'condition', 'threshold', 'severity']
33+
}, label('metric'), label('condition'), 'threshold', label('severity')]
3134
if (['Admin', 'DomainAdmin'].includes(store.getters.userInfo.roletype)) cols.push('account')
3235
return cols
3336
},

‎ui/src/views/resourcealert/resourceAlertOptions.js‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,16 @@ export const SEVERITY_LABELS = {
6363
MEDIUM: 'Medium',
6464
LOW: 'Low'
6565
}
66+
67+
const LABELS_BY_FIELD = {
68+
resourcetype: RESOURCE_TYPE_LABELS,
69+
metric: METRIC_LABELS,
70+
metrictype: METRIC_LABELS,
71+
condition: CONDITION_LABELS,
72+
severity: SEVERITY_LABELS
73+
}
74+
75+
export function resourceAlertLabel (field, value) {
76+
const labels = LABELS_BY_FIELD[field]
77+
return (labels && labels[value]) || value
78+
}

0 commit comments

Comments
 (0)