fix status filter (#6827)

pull/6833/head
Prabhat Khera 3 years ago committed by GitHub
parent abb79ccbeb
commit 33f433ce45
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -24,6 +24,11 @@ const (
EdgeDeviceFilterNone = "none" EdgeDeviceFilterNone = "none"
) )
const (
EdgeDeviceIntervalMultiplier = 2
EdgeDeviceIntervalAdd = 20
)
var endpointGroupNames map[portainer.EndpointGroupID]string var endpointGroupNames map[portainer.EndpointGroupID]string
// @id EndpointList // @id EndpointList
@ -128,7 +133,7 @@ func (handler *Handler) endpointList(w http.ResponseWriter, r *http.Request) *ht
} }
if len(statuses) > 0 { if len(statuses) > 0 {
filteredEndpoints = filterEndpointsByStatuses(filteredEndpoints, statuses) filteredEndpoints = filterEndpointsByStatuses(filteredEndpoints, statuses, settings)
} }
if search != "" { if search != "" {
@ -221,15 +226,19 @@ func filterEndpointsBySearchCriteria(endpoints []portainer.Endpoint, endpointGro
return filteredEndpoints return filteredEndpoints
} }
func filterEndpointsByStatuses(endpoints []portainer.Endpoint, statuses []int) []portainer.Endpoint { func filterEndpointsByStatuses(endpoints []portainer.Endpoint, statuses []int, settings *portainer.Settings) []portainer.Endpoint {
filteredEndpoints := make([]portainer.Endpoint, 0) filteredEndpoints := make([]portainer.Endpoint, 0)
for _, endpoint := range endpoints { for _, endpoint := range endpoints {
status := endpoint.Status status := endpoint.Status
if endpointutils.IsEdgeEndpoint(&endpoint) { if endpointutils.IsEdgeEndpoint(&endpoint) {
isCheckValid := false isCheckValid := false
if endpoint.EdgeCheckinInterval != 0 && endpoint.LastCheckInDate != 0 { edgeCheckinInterval := endpoint.EdgeCheckinInterval
isCheckValid = time.Now().Unix()-endpoint.LastCheckInDate <= int64(endpoint.EdgeCheckinInterval*2+20) if endpoint.EdgeCheckinInterval == 0 {
edgeCheckinInterval = settings.EdgeAgentCheckinInterval
}
if edgeCheckinInterval != 0 && endpoint.LastCheckInDate != 0 {
isCheckValid = time.Now().Unix()-endpoint.LastCheckInDate <= int64(edgeCheckinInterval*EdgeDeviceIntervalMultiplier+EdgeDeviceIntervalAdd)
} }
status = portainer.EndpointStatusDown // Offline status = portainer.EndpointStatusDown // Offline
if isCheckValid { if isCheckValid {

Loading…
Cancel
Save