mirror of
https://github.com/prometheus/alertmanager
synced 2024-12-28 00:52:13 +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.
54 lines
1.3 KiB
Go
54 lines
1.3 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 web
|
|
|
|
import (
|
|
"html/template"
|
|
"reflect"
|
|
"time"
|
|
)
|
|
|
|
func timeSince(t time.Time) string {
|
|
return time.Now().Round(time.Second / 10).Sub(t.Round(time.Second / 10)).String()
|
|
}
|
|
|
|
// By Russ Cox, https://groups.google.com/d/msg/golang-nuts/OEdSDgEC7js/iyhU9DW_IKcJ.
|
|
func eq(args ...interface{}) bool {
|
|
if len(args) == 0 {
|
|
return false
|
|
}
|
|
x := args[0]
|
|
switch x := x.(type) {
|
|
case string, int, int64, byte, float32, float64:
|
|
for _, y := range args[1:] {
|
|
if x == y {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
|
|
for _, y := range args[1:] {
|
|
if reflect.DeepEqual(x, y) {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
|
|
var webHelpers = template.FuncMap{
|
|
"timeSince": timeSince,
|
|
"eq": eq,
|
|
}
|