forked from influxdata/telegraf
-
Notifications
You must be signed in to change notification settings - Fork 2
/
reversedns_test.go
56 lines (48 loc) · 1.22 KB
/
reversedns_test.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 reverse_dns
import (
"testing"
"time"
"github.com/influxdata/telegraf/config"
"github.com/influxdata/telegraf/metric"
"github.com/influxdata/telegraf/testutil"
"github.com/stretchr/testify/require"
)
func TestSimpleReverseLookup(t *testing.T) {
now := time.Now()
m, _ := metric.New("name", map[string]string{
"dest_ip": "8.8.8.8",
}, map[string]interface{}{
"source_ip": "127.0.0.1",
}, now)
dns := newReverseDNS()
dns.Log = &testutil.Logger{}
dns.Lookups = []lookupEntry{
{
Field: "source_ip",
Dest: "source_name",
},
{
Tag: "dest_ip",
Dest: "dest_name",
},
}
acc := &testutil.Accumulator{}
dns.Start(acc)
dns.Add(m, acc)
dns.Stop()
// should be processed now.
require.Len(t, acc.GetTelegrafMetrics(), 1)
processedMetric := acc.GetTelegrafMetrics()[0]
f, ok := processedMetric.GetField("source_name")
require.True(t, ok)
require.EqualValues(t, "localhost", f)
tag, ok := processedMetric.GetTag("dest_name")
require.True(t, ok)
require.EqualValues(t, "dns.google.", tag)
}
func TestLoadingConfig(t *testing.T) {
c := config.NewConfig()
err := c.LoadConfigData([]byte("[[processors.reverse_dns]]\n" + sampleConfig))
require.NoError(t, err)
require.Len(t, c.Processors, 1)
}