feat: enhance alert log search with start and end time filters (#13489)

This commit is contained in:
蘭 authored and GitHub committed 2026-08-05 21:13:25 +08:00
1 parent 54854e99e7
commit 122a474032
8 files changed
+48 -24

No files matched your search

+4 -2
View File
@@ -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 {
+1
View File
@@ -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"`
+3
View File
@@ -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...)
-5
View File
@@ -55,11 +55,6 @@ var baseSettingKeys = map[string]struct{}{
"AppStoreLastModified": {},
"ScriptSync": {},
"HideMenu": {},
"OpsReportExportFormat": {},
"OpsReportSchedule": {},
"OpsReportSavePath": {},
"OpsReportThreshold": {},
"OpsReportAutoExport": {},
}
func checkNamePattern(fl validator.FieldLevel) bool {
@@ -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)
}
+3 -2
View File
@@ -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;
-5
View File
@@ -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;
+3 -2
View File
@@ -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 },