From c01b3764f889a6099d33e84a46940ef5807e5b01 Mon Sep 17 00:00:00 2001 From: ssongliu <73214554+ssongliu@users.noreply.github.com> Date: Wed, 11 Oct 2023 17:20:30 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20SSH=20=E6=97=A5=E5=BF=97=E7=BB=9F?= =?UTF-8?q?=E8=AE=A1=E4=BF=A1=E6=81=AF=E5=A2=9E=E5=8A=A0=E5=88=86=E9=A1=B5?= =?UTF-8?q?=20(#2509)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/app/dto/ssh.go | 8 +++ backend/app/service/ssh.go | 25 +++++++- cmd/server/docs/docs.go | 34 ++++------- cmd/server/docs/swagger.json | 30 ++++------ cmd/server/docs/swagger.yaml | 21 +++---- frontend/src/api/interface/host.ts | 9 +++ frontend/src/api/modules/host.ts | 4 +- .../src/views/host/ssh/log/analysis/index.vue | 59 +++++++++++++------ 8 files changed, 111 insertions(+), 79 deletions(-) diff --git a/backend/app/dto/ssh.go b/backend/app/dto/ssh.go index b7e42eef7..b8c9544d1 100644 --- a/backend/app/dto/ssh.go +++ b/backend/app/dto/ssh.go @@ -38,9 +38,17 @@ type SSHLog struct { } type SearchForAnalysis struct { + PageInfo OrderBy string `json:"orderBy" validate:"required,oneof=Success Failed"` } +type AnalysisRes struct { + Total int64 `json:"total"` + Items []SSHLogAnalysis `json:"items"` + SuccessfulCount int `json:"successfulCount"` + FailedCount int `json:"failedCount"` +} + type SSHLogAnalysis struct { Address string `json:"address"` Area string `json:"area"` diff --git a/backend/app/service/ssh.go b/backend/app/service/ssh.go index cee2a2773..7a9ac4fc2 100644 --- a/backend/app/service/ssh.go +++ b/backend/app/service/ssh.go @@ -32,7 +32,7 @@ type ISSHService interface { UpdateByFile(value string) error Update(key, value string) error GenerateSSH(req dto.GenerateSSH) error - AnalysisLog(req dto.SearchForAnalysis) ([]dto.SSHLogAnalysis, error) + AnalysisLog(req dto.SearchForAnalysis) (*dto.AnalysisRes, error) LoadSSHSecret(mode string) (string, error) LoadLog(req dto.SearchSSHLog) (*dto.SSHLog, error) @@ -304,7 +304,7 @@ func (u *SSHService) LoadLog(req dto.SearchSSHLog) (*dto.SSHLog, error) { return &data, nil } -func (u *SSHService) AnalysisLog(req dto.SearchForAnalysis) ([]dto.SSHLogAnalysis, error) { +func (u *SSHService) AnalysisLog(req dto.SearchForAnalysis) (*dto.AnalysisRes, error) { var fileList []string baseDir := "/var/log" if err := filepath.Walk(baseDir, func(pathItem string, info os.FileInfo, err error) error { @@ -365,7 +365,26 @@ func (u *SSHService) AnalysisLog(req dto.SearchForAnalysis) ([]dto.SSHLogAnalysi } } - return sortSlice, nil + var backData dto.AnalysisRes + for _, item := range sortSlice { + backData.FailedCount += item.FailedCount + backData.SuccessfulCount += item.SuccessfulCount + } + + var data []dto.SSHLogAnalysis + total, start, end := len(sortSlice), (req.Page-1)*req.PageSize, req.Page*req.PageSize + if start > total { + data = make([]dto.SSHLogAnalysis, 0) + } else { + if end >= total { + end = total + } + data = sortSlice[start:end] + } + backData.Items = data + backData.Total = int64(total) + + return &backData, nil } func (u *SSHService) LoadSSHConf() (string, error) { diff --git a/cmd/server/docs/docs.go b/cmd/server/docs/docs.go index ffb9dd34f..5faa3d7e4 100644 --- a/cmd/server/docs/docs.go +++ b/cmd/server/docs/docs.go @@ -1,5 +1,5 @@ -// Package docs GENERATED BY SWAG; DO NOT EDIT -// This file was generated by swaggo/swag +// Code generated by swaggo/swag. DO NOT EDIT. + package docs import "github.com/swaggo/swag" @@ -7950,7 +7950,7 @@ const docTemplate = `{ "ApiKeyAuth": [] } ], - "description": "操作 Node 项目的 modules", + "description": "操作 Node 项目 modules", "consumes": [ "application/json" ], @@ -14917,7 +14917,9 @@ const docTemplate = `{ "dto.SearchForAnalysis": { "type": "object", "required": [ - "orderBy" + "orderBy", + "page", + "pageSize" ], "properties": { "orderBy": { @@ -14926,6 +14928,12 @@ const docTemplate = `{ "Success", "Failed" ] + }, + "page": { + "type": "integer" + }, + "pageSize": { + "type": "integer" } } }, @@ -16730,24 +16738,6 @@ const docTemplate = `{ "properties": { "ID": { "type": "integer" - }, - "module": { - "type": "string" - }, - "operate": { - "type": "string", - "enum": [ - "install", - "uninstall", - "update" - ] - }, - "pkgManager": { - "type": "string", - "enum": [ - "npm", - "yarn" - ] } } }, diff --git a/cmd/server/docs/swagger.json b/cmd/server/docs/swagger.json index 64efc6f2e..f1d02c414 100644 --- a/cmd/server/docs/swagger.json +++ b/cmd/server/docs/swagger.json @@ -7943,7 +7943,7 @@ "ApiKeyAuth": [] } ], - "description": "操作 Node 项目的 modules", + "description": "操作 Node 项目 modules", "consumes": [ "application/json" ], @@ -14910,7 +14910,9 @@ "dto.SearchForAnalysis": { "type": "object", "required": [ - "orderBy" + "orderBy", + "page", + "pageSize" ], "properties": { "orderBy": { @@ -14919,6 +14921,12 @@ "Success", "Failed" ] + }, + "page": { + "type": "integer" + }, + "pageSize": { + "type": "integer" } } }, @@ -16723,24 +16731,6 @@ "properties": { "ID": { "type": "integer" - }, - "module": { - "type": "string" - }, - "operate": { - "type": "string", - "enum": [ - "install", - "uninstall", - "update" - ] - }, - "pkgManager": { - "type": "string", - "enum": [ - "npm", - "yarn" - ] } } }, diff --git a/cmd/server/docs/swagger.yaml b/cmd/server/docs/swagger.yaml index 25f95f694..7e201f2b9 100644 --- a/cmd/server/docs/swagger.yaml +++ b/cmd/server/docs/swagger.yaml @@ -1931,8 +1931,14 @@ definitions: - Success - Failed type: string + page: + type: integer + pageSize: + type: integer required: - orderBy + - page + - pageSize type: object dto.SearchForTree: properties: @@ -3135,19 +3141,6 @@ definitions: properties: ID: type: integer - module: - type: string - operate: - enum: - - install - - uninstall - - update - type: string - pkgManager: - enum: - - npm - - yarn - type: string required: - ID type: object @@ -9207,7 +9200,7 @@ paths: post: consumes: - application/json - description: 操作 Node 项目的 modules + description: 操作 Node 项目 modules parameters: - description: request in: body diff --git a/frontend/src/api/interface/host.ts b/frontend/src/api/interface/host.ts index 35fc0ddc7..b0af66242 100644 --- a/frontend/src/api/interface/host.ts +++ b/frontend/src/api/interface/host.ts @@ -136,6 +136,15 @@ export namespace Host { info: string; status: string; } + export interface analysisSSHLog extends ReqPage { + orderBy: string; + } + export interface logAnalysisRes { + total: number; + items: Array; + successfulCount: number; + failedCount: number; + } export interface sshLog { logs: Array; successfulCount: number; diff --git a/frontend/src/api/modules/host.ts b/frontend/src/api/modules/host.ts index ab1922f41..5875f3886 100644 --- a/frontend/src/api/modules/host.ts +++ b/frontend/src/api/modules/host.ts @@ -123,6 +123,6 @@ export const loadSecret = (mode: string) => { export const loadSSHLogs = (params: Host.searchSSHLog) => { return http.post(`/hosts/ssh/log`, params); }; -export const loadAnalysis = (orderBy: string) => { - return http.post>(`/hosts/ssh/log/analysis`, { orderBy: orderBy }, TimeoutEnum.T_40S); +export const loadAnalysis = (params: Host.analysisSSHLog) => { + return http.post(`/hosts/ssh/log/analysis`, params, TimeoutEnum.T_40S); }; diff --git a/frontend/src/views/host/ssh/log/analysis/index.vue b/frontend/src/views/host/ssh/log/analysis/index.vue index 2ed094333..8cc5771cf 100644 --- a/frontend/src/views/host/ssh/log/analysis/index.vue +++ b/frontend/src/views/host/ssh/log/analysis/index.vue @@ -32,14 +32,16 @@ {{ $t('firewall.deny') }} - +