Skip to content

Commit

Permalink
go fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
monicasarbu committed Aug 7, 2014
1 parent eb25691 commit 54260cd
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 52 deletions.
44 changes: 22 additions & 22 deletions output_elasticsearch.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,22 @@ package main
import (
"encoding/json"
"fmt"
"strings"
"github.com/packetbeat/elastigo/api"
"github.com/packetbeat/elastigo/core"
"strings"
)

type ElasticsearchOutputType struct {
OutputInterface
Index string
Index string
TopologyExpire int

TopologyMap map[string]string
}

type PublishedTopology struct {
Name string
IPs string
IPs string
}

var ElasticsearchOutput ElasticsearchOutputType
Expand Down Expand Up @@ -54,16 +54,16 @@ func (out *ElasticsearchOutputType) Init(config tomlMothership) error {

INFO("[ElasticsearchOutput] Using Elasticsearch %s://%s:%s%s", api.Protocol, api.Domain, api.Port, api.BasePath)
INFO("[ElasticsearchOutput] Using index pattern [%s-]YYYY.MM.DD", out.Index)
INFO("[ElasticsearchOutput] Topology expires after %ds", out.TopologyExpire / 1000)
INFO("[ElasticsearchOutput] Topology expires after %ds", out.TopologyExpire/1000)

return nil
}

func (out *ElasticsearchOutputType) EnableTTL() error {
setting := map[string]interface{}{
"server-ip": map[string]interface{}{
"_ttl": map[string]string{"enabled": "true", "default": "15000"},
},
"_ttl": map[string]string{"enabled": "true", "default": "15000"},
},
}

// Make sure the index exists, but ignore errors (probably exists already)
Expand All @@ -87,24 +87,24 @@ func (out *ElasticsearchOutputType) PublishIPs(name string, localAddrs []string)
DEBUG("output_elasticsearch", "Publish IPs %s with expiration time %d", localAddrs, out.TopologyExpire)
_, err := core.IndexWithParameters(
"packetbeat-topology", /*index*/
"server-ip", /*type*/
name, /* id */
"", /*parent id */
0, /* version */
"", /* op_type */
"", /* routing */
"", /* timestamp */
out.TopologyExpire, /*ttl*/
"", /* percolate */
"", /* timeout */
false, /*refresh */
nil, /*args */
"server-ip", /*type*/
name, /* id */
"", /*parent id */
0, /* version */
"", /* op_type */
"", /* routing */
"", /* timestamp */
out.TopologyExpire, /*ttl*/
"", /* percolate */
"", /* timeout */
false, /*refresh */
nil, /*args */
PublishedTopology{name, strings.Join(localAddrs, ",")} /* data */)

if err != nil {
ERR("Fail to publish IP addresses: %s", err)
return err
}
if err != nil {
ERR("Fail to publish IP addresses: %s", err)
return err
}

out.UpdateLocalTopologyMap()

Expand Down
18 changes: 8 additions & 10 deletions output_elasticsearch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ func createElasticsearchConnection() ElasticsearchOutputType {

var elasticsearchOutput ElasticsearchOutputType
elasticsearchOutput.Init(tomlMothership{
Enabled: true,
Enabled: true,
Save_topology: true,
Host: elasticsearchAddr,
Port: elasticsearchPort,
Username: "",
Password: "",
Path: "",
Index: "packetbeat",
Protocol: "",
Host: elasticsearchAddr,
Port: elasticsearchPort,
Username: "",
Password: "",
Path: "",
Index: "packetbeat",
Protocol: "",
})

return elasticsearchOutput
Expand Down Expand Up @@ -86,5 +86,3 @@ func TestTopologyInES(t *testing.T) {
t.Error("Failed to delete old IP of proxy2: %s", name2)
}
}


30 changes: 15 additions & 15 deletions output_redis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,29 @@ func TestTopologyInRedis(t *testing.T) {
var publisher3 PublisherType = PublisherType{name: "proxy3"}

var redisOutput1 = RedisOutputType{
Index: "packetbeat",
Hostname: redisAddr,
Password: "",
DbTopology: 1,
Timeout: time.Duration(5) * time.Second,
Index: "packetbeat",
Hostname: redisAddr,
Password: "",
DbTopology: 1,
Timeout: time.Duration(5) * time.Second,
TopologyExpire: time.Duration(15) * time.Second,
}

var redisOutput2 = RedisOutputType{
Index: "packetbeat",
Hostname: redisAddr,
Password: "",
DbTopology: 1,
Timeout: time.Duration(5) * time.Second,
Index: "packetbeat",
Hostname: redisAddr,
Password: "",
DbTopology: 1,
Timeout: time.Duration(5) * time.Second,
TopologyExpire: time.Duration(15) * time.Second,
}

var redisOutput3 = RedisOutputType{
Index: "packetbeat",
Hostname: redisAddr,
Password: "",
DbTopology: 1,
Timeout: time.Duration(5) * time.Second,
Index: "packetbeat",
Hostname: redisAddr,
Password: "",
DbTopology: 1,
Timeout: time.Duration(5) * time.Second,
TopologyExpire: time.Duration(15) * time.Second,
}

Expand Down
10 changes: 5 additions & 5 deletions publish.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import (
)

type PublisherType struct {
name string
disabled bool
Index string
Output []OutputInterface
name string
disabled bool
Index string
Output []OutputInterface
TopologyOutput OutputInterface

RefreshTopologyTimer <-chan time.Time
Expand Down Expand Up @@ -215,7 +215,7 @@ func (publisher *PublisherType) PublishEvent(ts time.Time, src *Endpoint, dst *E
}
}

if has_error {
if has_error {
return errors.New("Fail to publish event")
}
return nil
Expand Down

0 comments on commit 54260cd

Please sign in to comment.