-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbind.go
56 lines (47 loc) · 1.89 KB
/
bind.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
package main
import (
"fmt"
"io/ioutil"
"regexp"
"strings"
)
func parseStatistics(stats []string, statsFile string) []string {
var statusValues []string
var cleanTag string
bindstats, err := ioutil.ReadFile(statsFile)
if err != nil {
fmt.Println("File " + statsFile + " Not Found")
} else {
for _, element := range stats {
idTag := regexp.MustCompile(`(?m)(\d+\s` + element + `$)`)
tag := idTag.FindAllString(string(bindstats), -1)
if len(tag) == 0 {
cleanTag = ""
} else {
removeTag := regexp.MustCompile(`\d+ `)
cleanTag = removeTag.FindString(tag[len(tag)-1])
}
cleanTag = onemptyreturnzero(cleanTag, "bind")
statusValues = append(statusValues, string(cleanTag))
}
}
return statusValues
}
func bindStatus(statisticsfile, qType string) string {
incommingRequests := []string{"QUERY", "STATUS", "NOTIFY", "UPDATE"}
incommingQueries := []string{"A", "NS", "CNAME", "SOA", "PTR", "HINFO", "MX", "TXT", "AAAA", "EID", "SRV", "NAPTR", "A6", "DNAME", "DS", "RRSIG", "DNSKEY", "SPF", "AXFR", "ANY", "Others"}
nsStatistics := []string{`IPv4 requests received`, `IPv6 requests received`, `requests with EDNS\(0\) received`, `TCP requests received`, `auth queries rejected`, `recursive queries rejected`, `transfer requests rejected`, `update requests rejected`, `responses sent`, `truncated responses sent`, `responses with EDNS\(0\) sent`, `queries resulted in successful answer`, `queries resulted in authoritative answer`, `queries resulted in nxrrset`, `queries resulted in NXDOMAIN`, `other query failures`}
var statusValues []string
switch qType {
case "requests":
statusValues = parseStatistics(incommingRequests, statisticsfile)
break
case "queries":
statusValues = parseStatistics(incommingQueries, statisticsfile)
break
case "nsstats":
statusValues = parseStatistics(nsStatistics, statisticsfile)
break
}
return strings.Join(statusValues, "\n")
}