mirror of
https://github.com/prometheus/alertmanager
synced 2025-01-17 11:40:51 +00:00
f431335c69
This adds mandatory Summary and Description fields to Event. As for the alert name, there were two options: keep it a separate field and treat it separately everywhere (including in silence Filter matching), or make it a required field in the event's labels. The latter was causing far less trouble, so I went with that. The alertname label still doesn't have a special meaning to most parts of the code, except that the API checks its presence and the web UI displays it differently.
66 lines
1.6 KiB
Go
66 lines
1.6 KiB
Go
// Copyright 2013 Prometheus Team
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
|
|
package manager
|
|
|
|
import (
|
|
"fmt"
|
|
"hash/fnv"
|
|
"sort"
|
|
)
|
|
|
|
const EventNameLabel = "alertname"
|
|
|
|
type EventFingerprint uint64
|
|
|
|
type EventLabels map[string]string
|
|
type EventPayload map[string]string
|
|
|
|
// Event models an action triggered by Prometheus.
|
|
type Event struct {
|
|
// Short summary of event.
|
|
Summary string
|
|
// Long description of event.
|
|
Description string
|
|
// Label value pairs for purpose of aggregation, matching, and disposition
|
|
// dispatching. This must minimally include an "alertname" label.
|
|
Labels EventLabels
|
|
// Extra key/value information which is not used for aggregation.
|
|
Payload EventPayload
|
|
}
|
|
|
|
func (e Event) Name() string {
|
|
return e.Labels[EventNameLabel]
|
|
}
|
|
|
|
func (e Event) Fingerprint() EventFingerprint {
|
|
keys := []string{}
|
|
|
|
for k := range e.Labels {
|
|
keys = append(keys, k)
|
|
}
|
|
|
|
sort.Strings(keys)
|
|
|
|
summer := fnv.New64a()
|
|
|
|
separator := string([]byte{0})
|
|
for _, k := range keys {
|
|
fmt.Fprintf(summer, "%s%s%s%s", k, separator, e.Labels[k], separator)
|
|
}
|
|
|
|
return EventFingerprint(summer.Sum64())
|
|
}
|
|
|
|
type Events []*Event
|