Skip to content

Commit

Permalink
Implement elasticsearch auth support
Browse files Browse the repository at this point in the history
Signed-off-by: Markus Blaschke <[email protected]>
  • Loading branch information
mblaschke committed Jun 21, 2020
1 parent a73168c commit 2a4b41c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
9 changes: 4 additions & 5 deletions exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand All @@ -151,7 +151,6 @@ func (e *PagerdutyElasticsearchExporter) SetElasticsearchRetry(retryCount int, r
e.elasticsearchRetryDelay = retryDelay
}


func (e *PagerdutyElasticsearchExporter) RunSingle() {
e.runScrape()
}
Expand Down
8 changes: 7 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
)

const (
author = "webdevops.io"
author = "webdevops.io"

// Limit of pagerduty incidents per call
PagerdutyIncidentLimit = 100
Expand Down Expand Up @@ -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"`
Expand Down Expand Up @@ -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,
},
Expand Down

0 comments on commit 2a4b41c

Please sign in to comment.