diff --git a/management/internals/modules/reverseproxy/accesslogs/filter.go b/management/internals/modules/reverseproxy/accesslogs/filter.go index bd031d126..23dbb25ca 100644 --- a/management/internals/modules/reverseproxy/accesslogs/filter.go +++ b/management/internals/modules/reverseproxy/accesslogs/filter.go @@ -29,6 +29,7 @@ type AccessLogFilter struct { UserEmail *string // Filter by user email (requires user lookup) UserName *string // Filter by user name (requires user lookup) Method *string // Filter by HTTP method + Status *string // Filter by status: "success" (2xx/3xx) or "failed" (1xx/4xx/5xx) StatusCode *int // Filter by HTTP status code StartDate *time.Time // Filter by timestamp >= start_date EndDate *time.Time // Filter by timestamp <= end_date @@ -87,6 +88,10 @@ func (f *AccessLogFilter) ParseFromRequest(r *http.Request) { f.Method = &method } + if status := queryParams.Get("status"); status != "" { + f.Status = &status + } + if statusCodeStr := queryParams.Get("status_code"); statusCodeStr != "" { if statusCode, err := strconv.Atoi(statusCodeStr); err == nil && statusCode > 0 { f.StatusCode = &statusCode diff --git a/management/server/store/sql_store.go b/management/server/store/sql_store.go index 8cf98810c..2c374bfd4 100644 --- a/management/server/store/sql_store.go +++ b/management/server/store/sql_store.go @@ -5105,8 +5105,8 @@ func (s *SqlStore) applyAccessLogFilters(query *gorm.DB, filter accesslogs.Acces if filter.Search != nil { searchPattern := "%" + *filter.Search + "%" query = query.Where( - "location_connection_ip LIKE ? OR host LIKE ? OR path LIKE ? OR user_id IN (SELECT id FROM users WHERE email LIKE ? OR name LIKE ?)", - searchPattern, searchPattern, searchPattern, searchPattern, searchPattern, + "location_connection_ip LIKE ? OR host LIKE ? OR path LIKE ? OR CONCAT(host, path) LIKE ? OR user_id IN (SELECT id FROM users WHERE email LIKE ? OR name LIKE ?)", + searchPattern, searchPattern, searchPattern, searchPattern, searchPattern, searchPattern, ) } @@ -5131,6 +5131,14 @@ func (s *SqlStore) applyAccessLogFilters(query *gorm.DB, filter accesslogs.Acces query = query.Where("method = ?", *filter.Method) } + if filter.Status != nil { + if *filter.Status == "success" { + query = query.Where("status_code >= ? AND status_code < ?", 200, 400) + } else if *filter.Status == "failed" { + query = query.Where("status_code < ? OR status_code >= ?", 200, 400) + } + } + if filter.StatusCode != nil { query = query.Where("status_code = ?", *filter.StatusCode) } diff --git a/shared/management/http/api/openapi.yml b/shared/management/http/api/openapi.yml index 69d07b44a..11ced2e9d 100644 --- a/shared/management/http/api/openapi.yml +++ b/shared/management/http/api/openapi.yml @@ -6430,6 +6430,12 @@ paths: type: string enum: [GET, POST, PUT, PATCH, DELETE, HEAD, OPTIONS] description: Filter by HTTP method + - in: query + name: status + schema: + type: string + enum: [success, failed] + description: Filter by status (success = 2xx/3xx, failed = 1xx/4xx/5xx) - in: query name: status_code schema: