diff --git a/agent/app/dto/alert.go b/agent/app/dto/alert.go index 1881b8f38428..30ea2ad12a6f 100644 --- a/agent/app/dto/alert.go +++ b/agent/app/dto/alert.go @@ -113,8 +113,10 @@ type DiskDTO struct { type AlertLogSearch struct { PageInfo - Count uint `json:"count"` - Status string `json:"status"` + Count uint `json:"count"` + Status string `json:"status"` + StartTime time.Time `json:"startTime"` + EndTime time.Time `json:"endTime"` } type AlertLogDTO struct { diff --git a/agent/app/dto/cronjob.go b/agent/app/dto/cronjob.go index 5d2250c6330a..5325381c7cc4 100644 --- a/agent/app/dto/cronjob.go +++ b/agent/app/dto/cronjob.go @@ -197,6 +197,7 @@ type SearchRecord struct { type Record struct { ID uint `json:"id"` + CronjobID uint `json:"cronjobID"` TaskID string `json:"taskID"` StartTime string `json:"startTime"` Records string `json:"records"` diff --git a/agent/app/service/alert.go b/agent/app/service/alert.go index f8a8c695068b..5b7f5e7d1ea8 100644 --- a/agent/app/service/alert.go +++ b/agent/app/service/alert.go @@ -384,6 +384,9 @@ func (a AlertService) PageAlertLogs(search dto.AlertLogSearch) (int64, []dto.Ale if search.Count != 0 { opts = append(opts, alertRepo.WithByCount(search.Count)) } + if !search.StartTime.IsZero() && !search.EndTime.IsZero() { + opts = append(opts, repo.WithByCreatedAt(search.StartTime, search.EndTime)) + } opts = append(opts, repo.WithOrderDesc("created_at")) total, alerts, err := alertRepo.PageLog(search.Page, search.PageSize, opts...) diff --git a/core/init/validator/validator.go b/core/init/validator/validator.go index 9dfaa0a453e6..817772d40c13 100644 --- a/core/init/validator/validator.go +++ b/core/init/validator/validator.go @@ -55,11 +55,6 @@ var baseSettingKeys = map[string]struct{}{ "AppStoreLastModified": {}, "ScriptSync": {}, "HideMenu": {}, - "OpsReportExportFormat": {}, - "OpsReportSchedule": {}, - "OpsReportSavePath": {}, - "OpsReportThreshold": {}, - "OpsReportAutoExport": {}, } func checkNamePattern(fl validator.FieldLevel) bool { diff --git a/core/utils/req_helper/proxy_local/req_to_local.go b/core/utils/req_helper/proxy_local/req_to_local.go index aaba65a87d2d..df202ce92ef0 100644 --- a/core/utils/req_helper/proxy_local/req_to_local.go +++ b/core/utils/req_helper/proxy_local/req_to_local.go @@ -19,22 +19,48 @@ import ( ) func NewLocalClient(reqUrl, reqMethod string, body io.Reader, ctx *gin.Context) (interface{}, error) { - sockPath := "/etc/1panel/agent.sock" - if _, err := os.Stat(sockPath); err != nil { - return nil, fmt.Errorf("no such agent.sock find in localhost, err: %v", err) - } + client := NewReusableClient() + defer client.CloseIdleConnections() + return client.Request(reqUrl, reqMethod, body, ctx) +} + +type ReusableClient struct { + client *http.Client + sockPath string +} + +func NewReusableClient() *ReusableClient { + return newReusableClient("/etc/1panel/agent.sock") +} + +func newReusableClient(sockPath string) *ReusableClient { dialUnix := func() (conn net.Conn, err error) { return net.Dial("unix", sockPath) } transport := &http.Transport{ + MaxIdleConns: 12, + MaxIdleConnsPerHost: 6, DialContext: func(ctx context.Context, network, addr string) (net.Conn, error) { return dialUnix() }, } - client := &http.Client{ - Transport: transport, + return &ReusableClient{client: &http.Client{Transport: transport}, sockPath: sockPath} +} + +func (c *ReusableClient) CloseIdleConnections() { + if c == nil || c.client == nil { + return + } + c.client.CloseIdleConnections() +} + +func (c *ReusableClient) Request(reqUrl, reqMethod string, body io.Reader, ctx *gin.Context) (interface{}, error) { + if c == nil || c.client == nil { + return nil, errors.New("local agent client is not initialized") + } + if _, err := os.Stat(c.sockPath); err != nil { + return nil, fmt.Errorf("no such agent.sock find in localhost, err: %v", err) } - defer client.CloseIdleConnections() parsedURL, err := url.Parse("http://unix") if err != nil { return nil, fmt.Errorf("handle url Parse failed, err: %v \n", err) @@ -57,7 +83,7 @@ func NewLocalClient(reqUrl, reqMethod string, body io.Reader, ctx *gin.Context) } } - resp, err := client.Do(req) + resp, err := c.client.Do(req) if err != nil { return nil, fmt.Errorf("client do request failed, err: %v", err) } diff --git a/frontend/src/api/helper/check-status.ts b/frontend/src/api/helper/check-status.ts index 5cd2b61e1cfe..c15d390536b2 100644 --- a/frontend/src/api/helper/check-status.ts +++ b/frontend/src/api/helper/check-status.ts @@ -4,7 +4,7 @@ import { MsgError } from '@/utils/message'; import { useGlobalStore } from '@/composables/useGlobalStore'; export const checkStatus = (status: number, msg: string): void => { - const { entrance, isLogin } = useGlobalStore(); + const { entrance, globalStore } = useGlobalStore(); switch (status) { case 400: MsgError(msg ? msg : i18n.global.t('commons.res.paramError')); @@ -13,7 +13,8 @@ export const checkStatus = (status: number, msg: string): void => { MsgError(msg ? msg : i18n.global.t('commons.res.notFound')); break; case 403: - isLogin.value = false; + globalStore.setLogStatus(false); + globalStore.clearAuthInfo(); router.replace({ name: 'entrance', params: { code: entrance.value } }); MsgError(msg ? msg : i18n.global.t('commons.res.forbidden')); break; diff --git a/frontend/src/api/interface/setting.ts b/frontend/src/api/interface/setting.ts index 0a078db1cc3f..146f7a3d10c4 100644 --- a/frontend/src/api/interface/setting.ts +++ b/frontend/src/api/interface/setting.ts @@ -71,11 +71,6 @@ export namespace Setting { proxyUser: string; proxyPasswd: string; proxyPasswdKeep: string; - - opsReportExportFormat: string; - opsReportSchedule: string; - opsReportSavePath: string; - opsReportThreshold: string; } export interface SettingBaseInfo { systemVersion: string; diff --git a/frontend/src/utils/auth-response.ts b/frontend/src/utils/auth-response.ts index 051b05829825..1a8f0de35268 100644 --- a/frontend/src/utils/auth-response.ts +++ b/frontend/src/utils/auth-response.ts @@ -19,8 +19,9 @@ interface AuthResponseOptions { const forbiddenMessage = () => i18n.global.t('commons.res.forbidden'); export const redirectToEntrance = () => { - const { entrance, isLogin } = useGlobalStore(); - isLogin.value = false; + const { entrance, globalStore } = useGlobalStore(); + globalStore.setLogStatus(false); + globalStore.clearAuthInfo(); router.push({ name: 'entrance', params: { code: entrance.value },