aops-hermes/006-host-status-adaption.patch
Hu gang 3ecdf5ebd9 feat: add host related information
(cherry picked from commit bb9a51fbc16fe100a769cbdc121d9ffd030096eb)
2023-12-22 14:31:33 +08:00

262 lines
9.3 KiB
Diff

From 47aaab21d6606f27d6117eb53034f6c2c5f3edf3 Mon Sep 17 00:00:00 2001
From: Hu gang <18768366022@163.com>
Date: Wed, 20 Dec 2023 19:26:33 +0800
Subject: [PATCH] fix: host status adaptation
---
src/api/leaks.js | 3 +-
src/vendor/ant-design-pro/utils/request.js | 6 ++++
src/views/assests/HostDetail.vue | 34 +++++++------------
.../assests/components/HostBasicInfo.vue | 4 +--
.../assests/components/HostChartInfo.vue | 33 +++++++-----------
src/views/leaks/CVEsDetail.vue | 21 +++++-------
src/views/leaks/LeakTaskDetail.vue | 3 +-
src/views/leaks/components/HostTable.vue | 12 +++----
8 files changed, 49 insertions(+), 67 deletions(-)
diff --git a/src/api/leaks.js b/src/api/leaks.js
index c6f704b..da3fbf8 100644
--- a/src/api/leaks.js
+++ b/src/api/leaks.js
@@ -347,6 +347,7 @@ export function setCveStatus({cveList, status}) {
}
export function getHostUnderCVE({tableInfo, ...parameter}) {
+ const repoList = tableInfo.filters.repo ? tableInfo.filters.repo.map((v) => (v === '' ? null : v)) : null;
return request({
url: api.getHostUnderCVE,
method: 'post',
@@ -358,7 +359,7 @@ export function getHostUnderCVE({tableInfo, ...parameter}) {
fixed: tableInfo.fixed,
host_name: tableInfo.filters.host_name === null ? undefined : tableInfo.filters.host_name,
host_group: tableInfo.filters.host_group === null ? undefined : tableInfo.filters.host_group,
- repo: tableInfo.filters.repo === null ? undefined : tableInfo.filters.repo,
+ repo: repoList === null ? undefined : repoList,
last_scan: tableInfo.filters.last_scan
},
page: tableInfo.pagination.current,
diff --git a/src/vendor/ant-design-pro/utils/request.js b/src/vendor/ant-design-pro/utils/request.js
index 11be85a..36615ad 100644
--- a/src/vendor/ant-design-pro/utils/request.js
+++ b/src/vendor/ant-design-pro/utils/request.js
@@ -165,6 +165,12 @@ request.interceptors.response.use((response) => {
});
});
return retryRequest;
+ case '1108':
+ notification.error({
+ message: '暂无指标数据!',
+ description: response.data.message
+ });
+ break;
default:
notification.error({
message: response.data.label,
diff --git a/src/views/assests/HostDetail.vue b/src/views/assests/HostDetail.vue
index 6eadb05..ea08cfa 100644
--- a/src/views/assests/HostDetail.vue
+++ b/src/views/assests/HostDetail.vue
@@ -49,30 +49,20 @@ export default {
};
},
methods: {
- fetchHostInfo() {
+ async fetchHostInfo() {
this.basicHostInfoIsLoading = true;
- getHostDetail(Number(this.hostId), true)
- .then((res) => {
- this.basicHostInfo = res.data.host_infos[0];
- this.scene = this.basicHostInfo.scene;
- })
- .catch((err) => {
- this.$message.error(err.response.message);
- })
- .finally(() => {
- this.basicHostInfoIsLoading = false;
- });
this.basicInfoIsLoading = true;
- getHostDetail(Number(this.hostId), false)
- .then((res) => {
- this.basicInfo = res.data.host_infos[0];
- })
- .catch((err) => {
- this.$message.error(err.response.message);
- })
- .finally(() => {
- this.basicInfoIsLoading = false;
- });
+ const basicHostRes = await getHostDetail(Number(this.hostId), true);
+ if (basicHostRes) {
+ this.basicHostInfo = basicHostRes.data.host_infos[0];
+ this.scene = this.basicHostInfo.scene;
+ }
+ const basicRes = await getHostDetail(Number(this.hostId), false);
+ if (basicRes) {
+ this.basicInfo = basicRes.data.host_infos[0];
+ }
+ this.basicInfoIsLoading = false;
+ this.basicHostInfoIsLoading = false;
},
reFetchHostInfo() {
this.fetchHostInfo();
diff --git a/src/views/assests/components/HostBasicInfo.vue b/src/views/assests/components/HostBasicInfo.vue
index bab1074..9909e44 100644
--- a/src/views/assests/components/HostBasicInfo.vue
+++ b/src/views/assests/components/HostBasicInfo.vue
@@ -235,6 +235,7 @@ export default {
getDetail() {
let data = this.basicInfo;
data = data.host_info;
+ this.basicInfo.status !== null && (this.status = this.basicInfo.status);
for (const member in data.os) {
this.os[member] = data.os[member] || '暂无';
}
@@ -257,8 +258,7 @@ export default {
this.detailIcon = 'up';
}
}
- },
- mounted() {}
+ }
};
</script>
<style lang="less" scoped>
diff --git a/src/views/assests/components/HostChartInfo.vue b/src/views/assests/components/HostChartInfo.vue
index 2763d3c..d9e8fe7 100644
--- a/src/views/assests/components/HostChartInfo.vue
+++ b/src/views/assests/components/HostChartInfo.vue
@@ -120,29 +120,20 @@ export default {
methods: {
// 获取指标项,一个指标项对应一个图表
getHostMetrics() {
- const _this = this;
- _this.chartLoading = true;
+ this.chartLoading = true;
getHostMetrics({
- query_ip: _this.queryIp
- })
- .then((res) => {
- _this.metrics = res.data.results;
- if (_this.selectedMetrics.length < 1) {
- _this.selectedMetrics = res.data.results.slice(0, 4);
- storage.set('hostChartsSelectedMetrics', _this.selectedMetrics, 30 * 24 * 60 * 60 * 1000);
+ query_ip: this.queryIp
+ }).then((res) => {
+ if (res) {
+ this.metrics = res.data.results;
+ if (this.selectedMetrics.length < 1) {
+ this.selectedMetrics = res.data.results.slice(0, 4);
+ storage.set('hostChartsSelectedMetrics', this.selectedMetrics, 30 * 24 * 60 * 60 * 1000);
}
- _this.getMetricData();
- })
- .catch((err) => {
- if (err.response.code === '1108') {
- _this.$message.info('暂无指标数据!');
- } else {
- _this.$message.error(err.response.message);
- }
- })
- .finally(() => {
- _this.chartLoading = false;
- });
+ this.getMetricData();
+ }
+ this.chartLoading = false;
+ });
},
// 获取各个指标项下的所有序列数据
getMetricData() {
diff --git a/src/views/leaks/CVEsDetail.vue b/src/views/leaks/CVEsDetail.vue
index 3736592..4887c50 100644
--- a/src/views/leaks/CVEsDetail.vue
+++ b/src/views/leaks/CVEsDetail.vue
@@ -175,26 +175,21 @@ export default {
this.getHostList(this.cve_id, data);
},
getHostList(cveId, data) {
- const _this = this;
this.hostIsLoading = true;
getHostUnderCVE({
...data,
cve_id: cveId
- })
- .then(function (res) {
- _this.hostList = res.data.result || [];
- _this.hostList.forEach((item) => {
+ }).then((res) => {
+ if (res) {
+ this.hostList = res.data.result || [];
+ this.hostList.forEach((item) => {
item.hp_status = item.hp_status ? item.hp_status : '——';
item.fixStatus = item.hotpatch ? `是(${item.hp_status})` : '否';
});
- _this.paginationTotal = res.data.total_count || (res.data.total_count === 0 ? 0 : undefined);
- })
- .catch(function (err) {
- _this.$message.error(err.response.message);
- })
- .finally(function () {
- _this.hostIsLoading = false;
- });
+ this.paginationTotal = res.data.total_count || (res.data.total_count === 0 ? 0 : undefined);
+ }
+ });
+ this.hostIsLoading = false;
},
setStatus(status) {
const _this = this;
diff --git a/src/views/leaks/LeakTaskDetail.vue b/src/views/leaks/LeakTaskDetail.vue
index 56056c9..134a0cb 100644
--- a/src/views/leaks/LeakTaskDetail.vue
+++ b/src/views/leaks/LeakTaskDetail.vue
@@ -105,7 +105,7 @@
<a-input-search
:placeholder="taskType === 'hotpatch remove' ? `按CVE ID搜索` : `按主机名或IP搜索`"
style="width: 200px"
- maxLength="20"
+ :maxLength="20"
@search="onSearch"
/>
</a-col>
@@ -646,6 +646,7 @@ export default {
this.tableIsLoading = false;
},
handleTableChange(pagination, filters, sorter) {
+ this.expandedRowKeys = [];
// 存储翻页状态
for (var key in filters) {
if (filters[key] !== null) {
diff --git a/src/views/leaks/components/HostTable.vue b/src/views/leaks/components/HostTable.vue
index b83feb8..1546260 100644
--- a/src/views/leaks/components/HostTable.vue
+++ b/src/views/leaks/components/HostTable.vue
@@ -960,8 +960,8 @@ export default {
},
getRepoList() {
const _this = this;
- getRepoList()
- .then(function (res) {
+ getRepoList().then((res) => {
+ if (res) {
const arr = (res.data.result || []).map((repo) => {
return {
text: repo.repo_name,
@@ -972,11 +972,9 @@ export default {
text: '未设置',
value: ''
});
- _this.repoFilterList = arr;
- })
- .catch(function (err) {
- _this.$message.error(err.response.message);
- });
+ this.repoFilterList = arr;
+ }
+ });
},
// 检查是否有筛选条件
checkHasFilter(filters) {
--
Gitee