Merge pull request #2653 from projectdiscovery/elasticsearch-host-support

Added elasticsearch host reporting field support
dev
Ice3man 2022-10-03 16:47:18 +05:30 committed by GitHub
commit e875da208e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 14 additions and 3 deletions

View File

@ -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"`
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,