Added elasticsearch host reporting field support
@@ -19,10 +19,12 @@ import (
// Options contains necessary options required for elasticsearch communication
type Options struct {
+ // Host is the hostname of the elasticsearch instance
+ Host string `yaml:"host" validate:"required_without=IP"`
// IP for elasticsearch instance
IP string `yaml:"ip" validate:"required,ip"`
// Port is the port of elasticsearch instance
- Port int `yaml:"port" validate:"required,gte=0,lte=65535"`
+ Port int `yaml:"port" validate:"gte=0,lte=65535"`
// SSL (optional) enables ssl for elasticsearch connection
SSL bool `yaml:"ssl"`
// SSLVerification (optional) disables SSL verification for elasticsearch
@@ -81,7 +83,16 @@ func New(option *Options) (*Exporter, error) {
auth = "Basic " + auth
authentication = auth
}
- url := fmt.Sprintf("%s%s:%d/%s/_doc", scheme, option.IP, option.Port, option.IndexName)
+ var addr string
+ if option.Host != "" {
+ addr = option.Host
+ } else {
+ addr = option.IP
+ }
+ if option.Port != 0 {
+ addr += fmt.Sprintf(":%d", option.Port)
+ }
+ url := fmt.Sprintf("%s%s/%s/_doc", scheme, addr, option.IndexName)
ei = &Exporter{
url: url,
