forked from elastic/beats
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoutput_elasticsearch_test.go
90 lines (68 loc) · 2.56 KB
/
output_elasticsearch_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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package main
import (
"testing"
"time"
)
const elasticsearchAddr = "localhost"
const elasticsearchPort = 9200
func createElasticsearchConnection() ElasticsearchOutputType {
var elasticsearchOutput ElasticsearchOutputType
elasticsearchOutput.Init(tomlMothership{
Enabled: true,
Save_topology: true,
Host: elasticsearchAddr,
Port: elasticsearchPort,
Username: "",
Password: "",
Path: "",
Index: "packetbeat",
Protocol: "",
})
return elasticsearchOutput
}
func TestTopologyInES(t *testing.T) {
if testing.Short() {
t.Skip("Skipping topology tests in short mode, because they require Elasticsearch")
}
var publisher1 PublisherType = PublisherType{name: "proxy1"}
var publisher2 PublisherType = PublisherType{name: "proxy2"}
var publisher3 PublisherType = PublisherType{name: "proxy3"}
elasticsearchOutput1 := createElasticsearchConnection()
elasticsearchOutput2 := createElasticsearchConnection()
elasticsearchOutput3 := createElasticsearchConnection()
publisher1.TopologyOutput = OutputInterface(&elasticsearchOutput1)
publisher2.TopologyOutput = OutputInterface(&elasticsearchOutput2)
publisher3.TopologyOutput = OutputInterface(&elasticsearchOutput3)
publisher1.PublishTopology("10.1.0.4")
publisher2.PublishTopology("10.1.0.9", "fe80::4e8d:79ff:fef2:de6a")
publisher3.PublishTopology("10.1.0.10")
// give some time to Elasticsearch to add the IPs
time.Sleep(1 * time.Second)
elasticsearchOutput3.UpdateLocalTopologyMap()
name2 := publisher3.GetServerName("10.1.0.9")
if name2 != "proxy2" {
t.Error("Failed to update proxy2 in topology: name=%s", name2)
}
name2 = publisher3.GetServerName("10.1.0.9")
if name2 != "proxy2" {
t.Error("Failed to update proxy2 in topology: name=%s", name2)
}
publisher1.PublishTopology("10.1.0.4")
publisher2.PublishTopology("10.1.0.9")
publisher3.PublishTopology("192.168.1.2")
// give some time to Elasticsearch to add the IPs
time.Sleep(1 * time.Second)
elasticsearchOutput3.UpdateLocalTopologyMap()
name3 := publisher3.GetServerName("192.168.1.2")
if name3 != "proxy3" {
t.Error("Failed to add a new IP")
}
name3 = publisher3.GetServerName("10.1.0.10")
if name3 != "" {
t.Error("Failed to delete old IP of proxy3: %s", name3)
}
name2 = publisher3.GetServerName("fe80::4e8d:79ff:fef2:de6a")
if name2 != "" {
t.Error("Failed to delete old IP of proxy2: %s", name2)
}
}