...

Source file src/github.com/prometheus/alertmanager/cli/format/sort.go

Documentation: github.com/prometheus/alertmanager/cli/format

     1  // Copyright 2018 Prometheus Team
     2  // Licensed under the Apache License, Version 2.0 (the "License");
     3  // you may not use this file except in compliance with the License.
     4  // You may obtain a copy of the License at
     5  //
     6  // http://www.apache.org/licenses/LICENSE-2.0
     7  //
     8  // Unless required by applicable law or agreed to in writing, software
     9  // distributed under the License is distributed on an "AS IS" BASIS,
    10  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    11  // See the License for the specific language governing permissions and
    12  // limitations under the License.
    13  
    14  package format
    15  
    16  import (
    17  	"bytes"
    18  	"net"
    19  	"strconv"
    20  	"time"
    21  
    22  	"github.com/prometheus/alertmanager/api/v2/models"
    23  )
    24  
    25  type ByEndAt []models.GettableSilence
    26  
    27  func (s ByEndAt) Len() int      { return len(s) }
    28  func (s ByEndAt) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
    29  func (s ByEndAt) Less(i, j int) bool {
    30  	return time.Time(*s[i].Silence.EndsAt).Before(time.Time(*s[j].Silence.EndsAt))
    31  }
    32  
    33  type ByStartsAt []*models.GettableAlert
    34  
    35  func (s ByStartsAt) Len() int      { return len(s) }
    36  func (s ByStartsAt) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
    37  func (s ByStartsAt) Less(i, j int) bool {
    38  	return time.Time(*s[i].StartsAt).Before(time.Time(*s[j].StartsAt))
    39  }
    40  
    41  type ByAddress []*models.PeerStatus
    42  
    43  func (s ByAddress) Len() int      { return len(s) }
    44  func (s ByAddress) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
    45  func (s ByAddress) Less(i, j int) bool {
    46  	ip1, port1, _ := net.SplitHostPort(*s[i].Address)
    47  	ip2, port2, _ := net.SplitHostPort(*s[j].Address)
    48  	if ip1 == ip2 {
    49  		p1, _ := strconv.Atoi(port1)
    50  		p2, _ := strconv.Atoi(port2)
    51  		return p1 < p2
    52  	}
    53  	return bytes.Compare(net.ParseIP(ip1), net.ParseIP(ip2)) < 0
    54  }
    55  

View as plain text