forked from grafana/grafana
/
event.go
32 lines (28 loc) · 887 Bytes
/
event.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package schema
import (
"fmt"
"strings"
)
//go:generate msgp
type ProbeEvent struct {
Id string `json:"id"`
EventType string `json:"event_type"`
OrgId int64 `json:"org_id"`
Severity string `json:"severity"` // enum "INFO" "WARN" "ERROR" "OK"
Source string `json:"source"`
Timestamp int64 `json:"timestamp"`
Message string `json:"message"`
Tags map[string]string `json:"tags"`
}
func (e *ProbeEvent) Validate() error {
if e.EventType == "" || e.OrgId == 0 || e.Source == "" || e.Timestamp == 0 || e.Message == "" {
return fmt.Errorf("event definition not valid")
}
switch strings.ToLower(e.Severity) {
case "info", "ok", "warn", "error", "warning", "critical":
// nop
default:
return fmt.Errorf("'%s' is not a valid severity level", e.Severity)
}
return nil
}