-
Notifications
You must be signed in to change notification settings - Fork 634
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow snmp_context to be passed as optional parameter to override the snmp.ContextName #845
Closed
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
c9379db
Update common Prometheus files (#826)
prombot f7fc8a6
add snmp_context as optional param
dszarmach 302e259
dont change config - just use the context name if passed
dszarmach afe9f37
restore blank line
dszarmach ef28cef
add snmp_context as optional param
dszarmach 8e8b6bb
fix formatting
dszarmach File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -115,7 +115,7 @@ type ScrapeResults struct { | |||||
retries uint64 | ||||||
} | ||||||
|
||||||
func ScrapeTarget(ctx context.Context, target string, config *config.Module, logger log.Logger) (ScrapeResults, error) { | ||||||
func ScrapeTarget(ctx context.Context, target string, snmp_context string, config *config.Module, logger log.Logger) (ScrapeResults, error) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Go style does not use underscores for varibale names. Please follow the Go style guide.
Suggested change
|
||||||
results := ScrapeResults{} | ||||||
// Set the options. | ||||||
snmp := gosnmp.GoSNMP{} | ||||||
|
@@ -158,7 +158,7 @@ func ScrapeTarget(ctx context.Context, target string, config *config.Module, log | |||||
} | ||||||
|
||||||
// Configure auth. | ||||||
config.WalkParams.ConfigureSNMP(&snmp) | ||||||
config.WalkParams.ConfigureSNMP(&snmp, snmp_context) | ||||||
|
||||||
// Do the actual walk. | ||||||
err := snmp.Connect() | ||||||
|
@@ -259,14 +259,15 @@ func buildMetricTree(metrics []*config.Metric) *MetricNode { | |||||
} | ||||||
|
||||||
type collector struct { | ||||||
ctx context.Context | ||||||
target string | ||||||
module *config.Module | ||||||
logger log.Logger | ||||||
ctx context.Context | ||||||
target string | ||||||
snmp_context string | ||||||
module *config.Module | ||||||
logger log.Logger | ||||||
} | ||||||
|
||||||
func New(ctx context.Context, target string, module *config.Module, logger log.Logger) *collector { | ||||||
return &collector{ctx: ctx, target: target, module: module, logger: logger} | ||||||
func New(ctx context.Context, target string, snmp_context string, module *config.Module, logger log.Logger) *collector { | ||||||
return &collector{ctx: ctx, target: target, snmp_context: snmp_context, module: module, logger: logger} | ||||||
} | ||||||
|
||||||
// Describe implements Prometheus.Collector. | ||||||
|
@@ -277,7 +278,7 @@ func (c collector) Describe(ch chan<- *prometheus.Desc) { | |||||
// Collect implements Prometheus.Collector. | ||||||
func (c collector) Collect(ch chan<- prometheus.Metric) { | ||||||
start := time.Now() | ||||||
results, err := ScrapeTarget(c.ctx, c.target, c.module, c.logger) | ||||||
results, err := ScrapeTarget(c.ctx, c.target, c.snmp_context, c.module, c.logger) | ||||||
if err != nil { | ||||||
level.Info(c.logger).Log("msg", "Error scraping target", "err", err) | ||||||
ch <- prometheus.NewInvalidMetric(prometheus.NewDesc("snmp_error", "Error scraping target", nil, nil), err) | ||||||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please do not modify
Makefile.common
in this PR. We automatically manage this file.