Skip to content

Commit 2a4b41c

Browse files
committed
Implement elasticsearch auth support
Signed-off-by: Markus Blaschke <[email protected]>
1 parent a73168c commit 2a4b41c

File tree

3 files changed

+14
-6
lines changed

3 files changed

+14
-6
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ Application Options:
2222
--pagerduty.date-range= PagerDuty date range (default: 168h) [$PAGERDUTY_DATE_RANGE]
2323
--pagerduty.max-connections= Maximum numbers of TCP connections to PagerDuty API (concurrency) (default: 4) [$PAGERDUTY_MAX_CONNECTIONS]
2424
--elasticsearch.address= ElasticSearch urls [$ELASTICSEARCH_ADDRESS]
25+
--elasticsearch.username= ElasticSearch username for HTTP Basic Authentication [$ELASTICSEARCH_USERNAME]
26+
--elasticsearch.password= ElasticSearch password for HTTP Basic Authenticatio [$ELASTICSEARCH_PASSWORD]
27+
--elasticsearch.apikey= ElasticSearch base64-encoded token for authorization; if set, overrides username and password [$ELASTICSEARCH_APIKEY]
2528
--elasticsearch.index= ElasticSearch index name (placeholders: %y for year, %m for month and %d for day) (default: pagerduty) [$ELASTICSEARCH_INDEX]
2629
--elasticsearch.batch-count= Number of documents which should be indexed in one request (default: 50) [$ELASTICSEARCH_BATCH_COUNT]
2730
--elasticsearch.retry-count= ElasticSearch request retry count (default: 5) [$ELASTICSEARCH_RETRY_COUNT]

exporter.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,10 @@ func (e *PagerdutyElasticsearchExporter) ConnectElasticsearch(cfg elasticsearch.
129129
tries++
130130
if tries >= 5 {
131131
panic(err)
132-
} else {
133-
daemonLogger.Info("Failed to connect to ES, retry...")
134-
time.Sleep(5 * time.Second)
135-
continue
132+
} else {
133+
daemonLogger.Info("Failed to connect to ES, retry...")
134+
time.Sleep(5 * time.Second)
135+
continue
136136
}
137137
}
138138

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

154-
155154
func (e *PagerdutyElasticsearchExporter) RunSingle() {
156155
e.runScrape()
157156
}

main.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
)
1515

1616
const (
17-
author = "webdevops.io"
17+
author = "webdevops.io"
1818

1919
// Limit of pagerduty incidents per call
2020
PagerdutyIncidentLimit = 100
@@ -45,6 +45,9 @@ var opts struct {
4545

4646
// ElasticSearch settings
4747
ElasticsearchAddresses []string `long:"elasticsearch.address" env:"ELASTICSEARCH_ADDRESS" delim:" " description:"ElasticSearch urls" required:"true"`
48+
ElasticsearchUsername string `long:"elasticsearch.username" env:"ELASTICSEARCH_USERNAME" description:"ElasticSearch username for HTTP Basic Authentication"`
49+
ElasticsearchPassword string `long:"elasticsearch.password" env:"ELASTICSEARCH_PASSWORD" description:"ElasticSearch password for HTTP Basic Authenticatio"`
50+
ElasticsearchApiKey string `long:"elasticsearch.apikey" env:"ELASTICSEARCH_APIKEY" description:"ElasticSearch base64-encoded token for authorization; if set, overrides username and password"`
4851
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"`
4952
ElasticsearchBatchCount int `long:"elasticsearch.batch-count" env:"ELASTICSEARCH_BATCH_COUNT" description:"Number of documents which should be indexed in one request" default:"50"`
5053
ElasticsearchRetryCount int `long:"elasticsearch.retry-count" env:"ELASTICSEARCH_RETRY_COUNT" description:"ElasticSearch request retry count" default:"5"`
@@ -89,6 +92,9 @@ func main() {
8992

9093
cfg := elasticsearch.Config{
9194
Addresses: opts.ElasticsearchAddresses,
95+
Username: opts.ElasticsearchUsername,
96+
Password: opts.ElasticsearchPassword,
97+
APIKey: opts.ElasticsearchApiKey,
9298
Transport: &http.Transport{
9399
Proxy: http.ProxyFromEnvironment,
94100
},

0 commit comments

Comments
 (0)