-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathprocess.go
54 lines (42 loc) · 1.22 KB
/
process.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
package main
import (
"fmt"
"github.com/miekg/dns"
)
func processDNSResponse(response *dns.Msg, datadog bool, debug bool, gateway string, log bool, metric bool, model string, statsdipport string) bool {
found := false
metrics := []string{}
outageMetricName := model + ".outage"
outageMetricValue := "0.0"
outageMetric := outageMetricName + "=" + outageMetricValue
for _, answer := range response.Answer {
if aRecord, ok := answer.(*dns.A); ok {
found = true
ip := aRecord.A.String()
if ip == gateway {
outageMetricValue = "1.0"
outageMetric = outageMetricName + "=" + outageMetricValue
metrics = append(metrics, outageMetric)
if datadog {
giveMetricsToDatadogStatsd(debug, metrics, model, statsdipport)
}
if debug || log {
logWithTimestamp(fmt.Sprintf("Outage detected: %s", ip))
}
return true
} else if debug && !metric {
logWithTimestamp(fmt.Sprintf("No outage detected: %s", ip))
}
if metric && !datadog {
fmt.Println(outageMetric)
} else if datadog {
metrics = append(metrics, outageMetric)
giveMetricsToDatadogStatsd(debug, metrics, model, statsdipport)
}
}
}
if !found {
logWithTimestamp("No A records found.")
}
return false
}