diff --git a/README.md b/README.md index e3223c0..e1d9bad 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,9 @@ Application Options: --pagerduty.date-range= PagerDuty date range (default: 168h) [$PAGERDUTY_DATE_RANGE] --pagerduty.max-connections= Maximum numbers of TCP connections to PagerDuty API (concurrency) (default: 4) [$PAGERDUTY_MAX_CONNECTIONS] --elasticsearch.address= ElasticSearch urls [$ELASTICSEARCH_ADDRESS] + --elasticsearch.username= ElasticSearch username for HTTP Basic Authentication [$ELASTICSEARCH_USERNAME] + --elasticsearch.password= ElasticSearch password for HTTP Basic Authenticatio [$ELASTICSEARCH_PASSWORD] + --elasticsearch.apikey= ElasticSearch base64-encoded token for authorization; if set, overrides username and password [$ELASTICSEARCH_APIKEY] --elasticsearch.index= ElasticSearch index name (placeholders: %y for year, %m for month and %d for day) (default: pagerduty) [$ELASTICSEARCH_INDEX] --elasticsearch.batch-count= Number of documents which should be indexed in one request (default: 50) [$ELASTICSEARCH_BATCH_COUNT] --elasticsearch.retry-count= ElasticSearch request retry count (default: 5) [$ELASTICSEARCH_RETRY_COUNT] diff --git a/exporter.go b/exporter.go index b1b0530..523f24a 100644 --- a/exporter.go +++ b/exporter.go @@ -129,10 +129,10 @@ func (e *PagerdutyElasticsearchExporter) ConnectElasticsearch(cfg elasticsearch. tries++ if tries >= 5 { panic(err) - } else { - daemonLogger.Info("Failed to connect to ES, retry...") - time.Sleep(5 * time.Second) - continue + } else { + daemonLogger.Info("Failed to connect to ES, retry...") + time.Sleep(5 * time.Second) + continue } } @@ -151,7 +151,6 @@ func (e *PagerdutyElasticsearchExporter) SetElasticsearchRetry(retryCount int, r e.elasticsearchRetryDelay = retryDelay } - func (e *PagerdutyElasticsearchExporter) RunSingle() { e.runScrape() } diff --git a/main.go b/main.go index 4e966a5..a819edb 100644 --- a/main.go +++ b/main.go @@ -14,7 +14,7 @@ import ( ) const ( - author = "webdevops.io" + author = "webdevops.io" // Limit of pagerduty incidents per call PagerdutyIncidentLimit = 100 @@ -45,6 +45,9 @@ var opts struct { // ElasticSearch settings ElasticsearchAddresses []string `long:"elasticsearch.address" env:"ELASTICSEARCH_ADDRESS" delim:" " description:"ElasticSearch urls" required:"true"` + ElasticsearchUsername string `long:"elasticsearch.username" env:"ELASTICSEARCH_USERNAME" description:"ElasticSearch username for HTTP Basic Authentication"` + ElasticsearchPassword string `long:"elasticsearch.password" env:"ELASTICSEARCH_PASSWORD" description:"ElasticSearch password for HTTP Basic Authenticatio"` + ElasticsearchApiKey string `long:"elasticsearch.apikey" env:"ELASTICSEARCH_APIKEY" description:"ElasticSearch base64-encoded token for authorization; if set, overrides username and password"` ElasticsearchIndex string `long:"elasticsearch.index" env:"ELASTICSEARCH_INDEX" description:"ElasticSearch index name (placeholders: %y for year, %m for month and %d for day)" default:"pagerduty"` ElasticsearchBatchCount int `long:"elasticsearch.batch-count" env:"ELASTICSEARCH_BATCH_COUNT" description:"Number of documents which should be indexed in one request" default:"50"` ElasticsearchRetryCount int `long:"elasticsearch.retry-count" env:"ELASTICSEARCH_RETRY_COUNT" description:"ElasticSearch request retry count" default:"5"` @@ -89,6 +92,9 @@ func main() { cfg := elasticsearch.Config{ Addresses: opts.ElasticsearchAddresses, + Username: opts.ElasticsearchUsername, + Password: opts.ElasticsearchPassword, + APIKey: opts.ElasticsearchApiKey, Transport: &http.Transport{ Proxy: http.ProxyFromEnvironment, },