Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions agent/app/dto/alert.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions agent/app/dto/cronjob.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
3 changes: 3 additions & 0 deletions agent/app/service/alert.go
Original file line number Diff line number Diff line change
Expand Up @@ -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...)
Expand Down
5 changes: 0 additions & 5 deletions core/init/validator/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,6 @@ var baseSettingKeys = map[string]struct{}{
"AppStoreLastModified": {},
"ScriptSync": {},
"HideMenu": {},
"OpsReportExportFormat": {},
"OpsReportSchedule": {},
"OpsReportSavePath": {},
"OpsReportThreshold": {},
"OpsReportAutoExport": {},
}

func checkNamePattern(fl validator.FieldLevel) bool {
Expand Down
42 changes: 34 additions & 8 deletions core/utils/req_helper/proxy_local/req_to_local.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Comment on lines 21 to +25

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)
Expand All @@ -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)
}
Expand Down
5 changes: 3 additions & 2 deletions frontend/src/api/helper/check-status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand All @@ -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;
Expand Down
5 changes: 0 additions & 5 deletions frontend/src/api/interface/setting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 3 additions & 2 deletions frontend/src/utils/auth-response.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Comment on lines 21 to 25
name: 'entrance',
params: { code: entrance.value },
Expand Down
Loading