Skip to content

Commit

Permalink
add snmp_context as optional param
Browse files Browse the repository at this point in the history
  • Loading branch information
dszarmach committed Feb 14, 2023
1 parent ab419a4 commit cc28509
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,15 @@ func handler(w http.ResponseWriter, r *http.Request, logger log.Logger) {
if moduleName == "" {
moduleName = "if_mib"
}


snmp_context := query.Get("snmp_context")
if len(query["snmp_context"]) > 1 {
http.Error(w, "'snmp_context' parameter must only be specified once", 400)
snmpRequestErrors.Inc()
return
}

sc.RLock()
module, ok := (*(sc.C))[moduleName]
sc.RUnlock()
Expand All @@ -94,11 +103,11 @@ func handler(w http.ResponseWriter, r *http.Request, logger log.Logger) {
}

logger = log.With(logger, "module", moduleName, "target", target)
level.Debug(logger).Log("msg", "Starting scrape")
level.Debug(logger).Log("msg", "Starting scrape","snmp_context",snmp_context)

start := time.Now()
registry := prometheus.NewRegistry()
c := collector.New(r.Context(), target, module, logger)
c := collector.New(r.Context(), target, snmp_context, module, logger)
registry.MustRegister(c)
// Delegate http serving to Prometheus client library, which will call collector.Collect.
h := promhttp.HandlerFor(registry, promhttp.HandlerOpts{})
Expand Down

0 comments on commit cc28509

Please sign in to comment.