feat: 操作MML日志

This commit is contained in:
TsMask
2023-09-26 17:33:40 +08:00
parent 806e1ca301
commit 8e4f22b533
2 changed files with 341 additions and 400 deletions

69
src/api/logManage/mml.ts Normal file
View File

@@ -0,0 +1,69 @@
import { RESULT_CODE_SUCCESS } from '@/constants/result-constants';
import { request } from '@/plugins/http-fetch';
import { parseObjLineToHump } from '@/utils/parse-utils';
/**
* 查询日志列表
* @param query 查询参数
* @returns object
*/
export async function listMML(query: Record<string, any>) {
let totalSQL = 'select count(*) as total from mml_log where 1=1 ';
let rowsSQL = 'select * from mml_log where 1=1 ';
// 查询
let querySQL = '';
if (query.accountName) {
querySQL += ` and user like '%${query.accountName}%' `;
}
if (query.beginTime) {
querySQL += ` and log_time >= '${query.beginTime}' `;
}
if (query.endTime) {
querySQL += ` and log_time <= '${query.endTime}' `;
}
// 排序
let sortSql = ' order by log_time ';
if (query.sortOrder === 'asc') {
sortSql += ' asc ';
} else {
sortSql += ' desc ';
}
// 分页
const pageNum = (query.pageNum - 1) * query.pageSize;
const limtSql = ` limit ${pageNum},${query.pageSize} `;
// 发起请求
const result = await request({
url: `/databaseManagement/v1/select/omc_db/mml_log`,
method: 'get',
params: {
totalSQL: totalSQL + querySQL,
rowsSQL: rowsSQL + querySQL + sortSql + limtSql,
},
});
// 解析数据
if (result.code === RESULT_CODE_SUCCESS) {
const data: DataList = {
total: 0,
rows: [],
code: result.code,
msg: result.msg,
};
result.data.data.forEach((item: any) => {
const itemData = item['mml_log'];
if (Array.isArray(itemData)) {
if (itemData.length === 1 && itemData[0]['total']) {
data.total = itemData[0]['total'];
} else {
data.rows = itemData.map(v => parseObjLineToHump(v));
}
}
});
return data;
}
return result;
}

View File

@@ -1,432 +1,304 @@
<script lang="ts" setup> <script setup lang="ts">
import { onMounted, reactive, toRaw } from 'vue'; import { useRoute } from 'vue-router';
import { reactive, ref, onMounted, toRaw } from 'vue';
import { PageContainer } from '@ant-design-vue/pro-layout'; import { PageContainer } from '@ant-design-vue/pro-layout';
import saveAs from 'file-saver'; import { SizeType } from 'ant-design-vue/lib/config-provider';
import useNeInfoStore from '@/store/modules/neinfo'; import { MenuInfo } from 'ant-design-vue/lib/menu/src/interface';
import { import { ColumnsType } from 'ant-design-vue/lib/table';
RESULT_CODE_ERROR, import { parseDateToStr } from '@/utils/date-utils';
RESULT_CODE_SUCCESS, import { RESULT_CODE_SUCCESS } from '@/constants/result-constants';
} from '@/constants/result-constants'; import { listMML } from '@/api/logManage/mml';
import useI18n from '@/hooks/useI18n'; import useI18n from '@/hooks/useI18n';
import { message, Form } from 'ant-design-vue/lib';
import {
tcpdumpNeTask,
tcpdumpNeUPFTask,
tcpdumpPcapDownload,
} from '@/api/traceManage/pcap';
import { ref } from 'vue';
const { t } = useI18n(); const { t } = useI18n();
const route = useRoute();
/**对话框对象信息状态类型 */ /**路由标题 */
type ModalStateType = { let title = ref<string>((route.meta.title as string) ?? '标题');
/**网元类型 */
neType: string[];
/**表单数据 */
from: Record<string, any>;
/**确定按钮 loading */
confirmLoading: boolean;
/**执行日志 */
execLogMsg: string;
/**文件名 */
fileName: string;
/**下载文件按钮 */
downBtn: boolean;
};
/**对话框对象信息状态 */ /**记录开始结束时间 */
let modalState: ModalStateType = reactive({ let queryRangePicker = ref<[string, string]>(['', '']);
neType: [],
from: { /**查询参数 */
ip: '', let queryParams = reactive({
cmd: 'sctp or tcp port 8080 or 8088', /**登录账号 */
timeout: 60, accountName: '',
upfStart: 'pcap dispatch trace on max 100000', /**记录时间 */
upfStop: 'pcap dispatch trace off', beginTime: '',
}, endTime: '',
confirmLoading: false, /**当前页数 */
execLogMsg: '', pageNum: 1,
fileName: '', /**每页条数 */
downBtn: false, pageSize: 20,
}); });
/**网元类型选择对应修改 */ /**查询参数重置 */
function fnNeChange(_: any, item: any) { function fnQueryReset() {
modalState.from.ip = item[1].ip; queryParams = Object.assign(queryParams, {
modalState.execLogMsg = ''; accountName: '',
modalState.fileName = ''; beginTime: '',
modalState.downBtn = false; endTime: undefined,
runTime.value = 0; pageNum: 1,
pageSize: 20,
});
queryRangePicker.value = ['', ''];
tablePagination.current = 1;
tablePagination.pageSize = 20;
fnGetList();
} }
/**对话框内表单属性和校验规则 */ /**表格状态类型 */
const modalStateFrom = Form.useForm( type TabeStateType = {
modalState.from, /**加载等待 */
reactive({ loading: boolean;
cmd: [{ required: true, message: 'tcpdump any 参数!' }], /**紧凑型 */
timeout: [{ required: true, message: '执行时长,单位是秒!' }], size: SizeType;
upfStart: [{ required: true, message: 'upf start pacp 命令!' }], /**搜索栏 */
upfStop: [{ required: true, message: 'upf stop pacp 命令!' }], seached: boolean;
}) /**记录数据 */
); data: object[];
};
// 创建 AbortController 实例 /**表格状态 */
let controller = new AbortController(); let tableState: TabeStateType = reactive({
let timeoutId: any = 0; loading: false,
let runTime = ref<number>(0); size: 'middle',
seached: true,
data: [],
});
/**普通抓包执行 */ /**表格字段列 */
function fnStart() { let tableColumns: ColumnsType = [
modalStateFrom {
.validate(['cmd', 'timeout']) title: t('common.rowId'),
.then(() => { dataIndex: 'id',
modalState.confirmLoading = true; align: 'center',
const from = toRaw(modalState.from); },
const hide = message.loading('正在执行...', 0); {
controller = new AbortController(); title: '登录账号',
const signal = controller.signal; dataIndex: 'user',
timeoutId = setInterval(() => { align: 'center',
runTime.value++; },
if (runTime.value > from.timeout + 5) { {
clearInterval(timeoutId); title: 'IP地址',
runTime.value = 0; dataIndex: 'ip',
message.warning({ align: 'center',
content: `执行超时`, },
duration: 2, {
}); title: '网元类型',
// 超时终止请求 dataIndex: 'neType',
controller.abort(); align: 'center',
} },
}, 1000); {
title: '网元唯一标识',
dataIndex: 'neId',
align: 'center',
},
{
title: 'MML',
dataIndex: 'mml',
key: 'mml',
align: 'center',
},
{
title: '记录时间',
dataIndex: 'logTime',
align: 'center',
customRender(opt) {
if (!opt.value) return '';
return parseDateToStr(opt.value);
},
},
];
tcpdumpNeTask(signal, { /**表格分页器参数 */
neType: modalState.neType[0], let tablePagination = reactive({
neId: modalState.neType[1], /**当前页数 */
timeout: from.timeout, current: 1,
cmd: from.cmd, /**每页条数 */
}) pageSize: 20,
.then(res => { /**默认的每页条数 */
if (res.code === RESULT_CODE_SUCCESS) { defaultPageSize: 20,
message.success({ /**指定每页可以显示多少条 */
content: `执行完成`, pageSizeOptions: ['10', '20', '50', '100'],
duration: 3, /**只有一页时是否隐藏分页器 */
}); hideOnSinglePage: false,
let logmsg = res.data.cmd + '\n\n' + res.data.msg; /**是否可以快速跳转至某页 */
logmsg = logmsg.replace(' \n', '\n\n'); showQuickJumper: true,
modalState.execLogMsg = logmsg; /**是否可以改变 pageSize */
modalState.fileName = res.data.fileName; showSizeChanger: true,
modalState.downBtn = true; /**数据总数 */
} else if ( total: 0,
res.code === RESULT_CODE_ERROR && showTotal: (total: number) => t('common.tablePaginationTotal', { total }),
res.msg.includes('timeout') onChange: (page: number, pageSize: number) => {
) { tablePagination.current = page;
message.warning({ tablePagination.pageSize = pageSize;
content: `中断执行`, queryParams.pageNum = page;
duration: 3, queryParams.pageSize = pageSize;
}); fnGetList();
} else { },
message.error({ });
content: `执行失败`,
duration: 3, /**表格紧凑型变更操作 */
}); function fnTableSize({ key }: MenuInfo) {
} tableState.size = key as SizeType;
})
.finally(() => {
hide();
clearInterval(timeoutId);
runTime.value = 0;
modalState.confirmLoading = false;
});
})
.catch(e => {
message.error(t('common.errorFields', { num: e.errorFields.length }), 3);
});
} }
/**普通抓包中断 */ /**查询备份信息列表 */
function fnStop() { function fnGetList() {
controller.abort(); // 终止请求 if (tableState.loading) return;
clearInterval(timeoutId); tableState.loading = true;
runTime.value = 0; queryParams.beginTime = queryRangePicker.value[0];
} queryParams.endTime = queryRangePicker.value[1];
listMML(toRaw(queryParams)).then(res => {
/**下载PCAP文件 */ console.log(res);
function fnDownPCAP() { if (res.code === RESULT_CODE_SUCCESS && Array.isArray(res.rows)) {
if (!modalState.fileName) { tablePagination.total = res.total;
message.warning({ tableState.data = res.rows;
content: `无效文件名`,
duration: 2,
});
return;
}
const key = 'tcpdumpPcapDownload';
message.loading({ content: '请稍等...', key });
tcpdumpPcapDownload({
neType: modalState.neType[0],
neId: modalState.neType[1],
fileName: modalState.fileName,
}).then(res => {
if (res.code === RESULT_CODE_SUCCESS) {
message.success({
content: `已完成`,
key,
duration: 2,
});
saveAs(res.data, modalState.fileName);
} else {
message.error({
content: `${res.msg}`,
key,
duration: 2,
});
} }
tableState.loading = false;
}); });
} }
/**UPF抓包执行 */
function fnUPF(runType: 'start' | 'stop') {
let validateArr = ['upfStop'];
if (runType === 'start') {
validateArr = ['upfStart'];
}
modalStateFrom
.validate(validateArr)
.then(() => {
modalState.confirmLoading = true;
const from = toRaw(modalState.from);
const hide = message.loading('请稍等...', 0);
tcpdumpNeUPFTask({
neType: modalState.neType[0],
neId: modalState.neType[1],
runType: runType,
cmd: from.upfStart,
})
.then(res => {
if (res.code === RESULT_CODE_SUCCESS) {
let logmsg = res.data.cmd + '\n\n' + res.data.msg;
logmsg = logmsg.replace(' \n', '\n\n');
modalState.execLogMsg = logmsg;
modalState.fileName = res.data.fileName;
if (runType === 'start') {
if (res.data.msg.includes('already')) {
message.warning({
content: `已经执行, 请根据情况停止抓包`,
duration: 10,
});
} else {
message.success({
content: `执行成功, 请根据情况停止抓包`,
duration: 10,
});
}
}
if (runType === 'stop') {
if (res.data.msg.includes('already')) {
message.warning({
content: `已经停止, 请根据情况开始抓包`,
duration: 10,
});
} else {
message.success({
content: `执行成功, 抓包已停止`,
duration: 10,
});
modalState.downBtn = true;
}
}
} else {
message.error({
content: `执行失败`,
duration: 3,
});
}
})
.finally(() => {
hide();
modalState.confirmLoading = false;
});
})
.catch(e => {
message.error(t('common.errorFields', { num: e.errorFields.length }), 3);
});
}
onMounted(() => { onMounted(() => {
// 获取网元网元列表 // 获取列表数据
useNeInfoStore() fnGetList();
.fnNelist()
.then(res => {
if (res.code === RESULT_CODE_SUCCESS && Array.isArray(res.data)) {
if (res.data.length > 0) {
const info = res.data[0];
modalState.neType = [info.neType, info.neId];
modalState.from.ip = info.ip;
}
} else {
message.warning({
content: `暂无网元列表数据`,
duration: 2,
});
}
});
}); });
</script> </script>
<template> <template>
<PageContainer> <PageContainer :title="title">
<a-card :title="t('views.traceManage.pcap.cardTitle')"> <a-card
<a-row :gutter="16"> v-show="tableState.seached"
<a-col :lg="12" :md="12" :xs="24"> :bordered="false"
<a-form :body-style="{ marginBottom: '24px', paddingBottom: 0 }"
name="modalState" >
:model="modalState" <!-- 表格搜索栏 -->
layout="horizontal" <a-form :model="queryParams" name="queryParams" layout="horizontal">
autocomplete="off" <a-row :gutter="16">
:label-col="{ span: 5 }" <a-col :lg="6" :md="12" :xs="24">
labelWrap <a-form-item label="登录账号" name="accountName">
> <a-input
<a-form-item :label="t('views.traceManage.pcap.neType')" name="neType"> v-model:value="queryParams.accountName"
<a-cascader :allow-clear="true"
v-model:value="modalState.neType" placeholder="查询登录账号"
:options="useNeInfoStore().getNeCascaderOtions" ></a-input>
@change="fnNeChange"
:allow-clear="false"
placeholder="请选择网元"
/>
</a-form-item> </a-form-item>
<a-form-item :label="t('views.traceManage.pcap.neIp')" name="ip"> </a-col>
<span style="font-weight: bold">{{ modalState.from.ip }}</span> <a-col :lg="8" :md="12" :xs="24">
<a-form-item label="记录时间" name="queryRangePicker">
<a-range-picker
v-model:value="queryRangePicker"
allow-clear
bordered
show-time
value-format="YYYY-MM-DD HH:mm:ss"
format="YYYY-MM-DD HH:mm:ss"
:placeholder="['记录开始', '记录结束']"
style="width: 100%"
></a-range-picker>
</a-form-item> </a-form-item>
</a-col>
<template v-if="modalState.neType[0] === 'UPF'"> <a-col :lg="6" :md="12" :xs="24">
<a-form-item <a-form-item>
:label="t('views.traceManage.pcap.capStart')" <a-space :size="8">
name="upfStart" <a-button type="primary" @click.prevent="fnGetList">
v-bind="modalStateFrom.validateInfos.upfStart" <template #icon><SearchOutlined /></template>
> {{ t('common.search') }}
<a-input-group compact> </a-button>
<a-input <a-button type="default" @click.prevent="fnQueryReset">
v-model:value="modalState.from.upfStart" <template #icon><ClearOutlined /></template>
allow-clear {{ t('common.reset') }}
placeholder="upf pacp 命令" </a-button>
style="width: 75%" </a-space>
/>
<a-button
type="primary"
style="width: 25%"
:disabled="modalState.confirmLoading"
:loading="modalState.confirmLoading"
@click.prevent="fnUPF('start')"
>
{{ t('views.traceManage.pcap.runText') }}
</a-button>
</a-input-group>
</a-form-item>
<a-form-item
:label="t('views.traceManage.pcap.capStop')"
name="upfStop"
v-bind="modalStateFrom.validateInfos.upfStop"
>
<a-input-group compact>
<a-input
v-model:value="modalState.from.upfStop"
allow-clear
placeholder="upf pacp 命令"
style="width: 75%"
/>
<a-button
type="primary"
style="width: 25%"
:disabled="modalState.confirmLoading"
:loading="modalState.confirmLoading"
@click.prevent="fnUPF('stop')"
>
{{ t('views.traceManage.pcap.runText') }}
</a-button>
</a-input-group>
</a-form-item>
</template>
<template v-else>
<a-form-item
:label="t('views.traceManage.pcap.capArg')"
name="cmd"
v-bind="modalStateFrom.validateInfos.cmd"
>
<a-input
v-model:value="modalState.from.cmd"
allow-clear
placeholder="tcpdump any 参数"
>
</a-input>
</a-form-item>
<a-form-item
:label="t('views.traceManage.pcap.capTime')"
name="timeout"
v-bind="modalStateFrom.validateInfos.timeout"
>
<a-input-number
v-model:value="modalState.from.timeout"
placeholder="单位是秒's"
:min="5"
:max="120"
/>
</a-form-item>
<a-form-item :wrapperCol="{ offset: 5 }">
<a-space :size="8">
<a-button
type="primary"
:disabled="modalState.confirmLoading"
:loading="modalState.confirmLoading"
@click.prevent="fnStart"
>
<template #icon><ApiOutlined /></template>
{{
runTime != 0
? t('views.traceManage.pcap.runTimeText', { s: runTime })
: t('views.traceManage.pcap.runText')
}}
</a-button>
<a-button
type="dashed"
danger
:disabled="!modalState.confirmLoading"
@click.prevent="fnStop"
>
{{ t('views.traceManage.pcap.stopText') }}
</a-button>
</a-space>
</a-form-item>
</template>
</a-form>
</a-col>
<a-col :offset="2" :lg="10" :md="10" :xs="24">
<a-form layout="vertical" autocomplete="off">
<a-form-item
:label="t('views.traceManage.pcap.capLog')"
name="execLogMsg"
v-show="!!modalState.execLogMsg"
>
<a-textarea
v-model:value="modalState.execLogMsg"
:auto-size="{ minRows: 10, maxRows: 15 }"
:disabled="true"
placeholder="输出执行日志..."
/>
</a-form-item> </a-form-item>
<a-form-item v-show="modalState.downBtn"> </a-col>
<a-button </a-row>
type="primary" </a-form>
:title="modalState.fileName" </a-card>
@click.prevent="fnDownPCAP"
> <a-card :bordered="false" :body-style="{ padding: '0px' }">
<template #icon><DownloadOutlined /></template> <!-- 插槽-卡片左侧侧 -->
{{ t('views.traceManage.pcap.capDownText') }} <template #title> </template>
<!-- 插槽-卡片右侧 -->
<template #extra>
<a-space :size="8" align="center">
<a-tooltip>
<template #title>{{ t('common.searchBarText') }}</template>
<a-switch
v-model:checked="tableState.seached"
:checked-children="t('common.switch.show')"
:un-checked-children="t('common.switch.hide')"
size="small"
/>
</a-tooltip>
<a-tooltip>
<template #title>{{ t('common.reloadText') }}</template>
<a-button type="text" @click.prevent="fnGetList">
<template #icon><ReloadOutlined /></template>
</a-button>
</a-tooltip>
<a-tooltip>
<template #title>{{ t('common.sizeText') }}</template>
<a-dropdown trigger="click" placement="bottomRight">
<a-button type="text">
<template #icon><ColumnHeightOutlined /></template>
</a-button> </a-button>
</a-form-item> <template #overlay>
</a-form> <a-menu
</a-col> :selected-keys="[tableState.size as string]"
</a-row> @click="fnTableSize"
>
<a-menu-item key="default">
{{ t('common.size.default') }}
</a-menu-item>
<a-menu-item key="middle">
{{ t('common.size.middle') }}
</a-menu-item>
<a-menu-item key="small">
{{ t('common.size.small') }}
</a-menu-item>
</a-menu>
</template>
</a-dropdown>
</a-tooltip>
</a-space>
</template>
<!-- 表格列表 -->
<a-table
class="table"
row-key="id"
:columns="tableColumns"
:loading="tableState.loading"
:data-source="tableState.data"
:size="tableState.size"
:pagination="tablePagination"
:scroll="{ x: true }"
>
<template #bodyCell="{ column, record }">
<template v-if="column.key === 'mml'">
<a-space :size="8" align="center">
<a-tooltip>
<template #title>{{ record.result }}</template>
<div class="mmlText">{{ record.mml }}</div>
</a-tooltip>
</a-space>
</template>
</template>
</a-table>
</a-card> </a-card>
</PageContainer> </PageContainer>
</template> </template>
<style lang="less" scoped></style> <style lang="less" scoped>
.table :deep(.ant-pagination) {
padding: 0 24px;
}
.mmlText {
max-width: 200px;
cursor: pointer;
text-align: start;
}
</style>