-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathevent.go
66 lines (56 loc) · 1.09 KB
/
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package main
import (
"fmt"
"strings"
"github.com/miekg/dns"
)
type Event struct {
Msg string `json:"msg"`
Name string `json:"name"`
Type dns.Type `json:"type"`
Client string `json:"client,omitempty"`
Server string `json:"server,omitempty"`
Record *Record `json:"record,omitempty"`
Category Category `json:"category"`
Source string `json:"source"`
}
func (e *Event) String() string {
msg := ""
if e.Msg != "" {
msg = fmt.Sprintf("%s: ", e.Msg)
}
srv := ""
if e.Server != "" {
srv = fmt.Sprintf(" | server: %s;", e.Server)
}
client := ""
if e.Client != "" {
client = fmt.Sprintf(" | client: %s;", e.Client)
}
src := ""
if e.Source != "" {
src = fmt.Sprintf(" | source: %s;", e.Source)
}
rec := ""
if e.Record != nil {
rec = fmt.Sprintf(
" | record type: %s: %s, tags: [%s]",
e.Record.Type,
e.Record.Pattern,
strings.Join(e.Record.Tags, ", "),
)
}
return fmt.Sprintf(
"%s name: %s | type: %s%s%s%s%s",
msg,
e.Name,
e.Type,
srv,
client,
rec,
src,
)
}
func (e *Event) Event() string {
return e.String()
}