forked from menandmice-services/logeater
-
Notifications
You must be signed in to change notification settings - Fork 2
/
logeater-dnssec.go
55 lines (48 loc) · 860 Bytes
/
logeater-dnssec.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
package main
import (
"bufio"
"fmt"
"os"
"sort"
"strings"
)
type sortedMap struct {
m map[string]int
s []string
}
func (sm *sortedMap) Len() int {
return len(sm.m)
}
func (sm *sortedMap) Less(i, j int) bool {
return sm.m[sm.s[i]] > sm.m[sm.s[j]]
}
func (sm *sortedMap) Swap(i, j int) {
sm.s[i], sm.s[j] = sm.s[j], sm.s[i]
}
func sortedKeys(m map[string]int) []string {
sm := new(sortedMap)
sm.m = m
sm.s = make([]string, len(m))
i := 0
for key, _ := range m {
sm.s[i] = key
i++
}
sort.Sort(sm)
return sm.s
}
func main() {
errormap := make(map[string]int)
scanner := bufio.NewScanner(os.Stdin)
for scanner.Scan() {
txt := scanner.Text()
i := strings.Index(txt, "validating")
if (i > 0) {
msg := txt[i+11:]
errormap[msg]++
}
}
for _, res := range sortedKeys(errormap) {
fmt.Println(errormap[res], ":", res)
}
}