Skip to content

Commit

Permalink
fix: allow snmp community to come from the request, templating from o…
Browse files Browse the repository at this point in the history
…ne of the existing items
  • Loading branch information
nicko170 committed Aug 19, 2024
1 parent 944f55d commit fe32b7b
Show file tree
Hide file tree
Showing 5 changed files with 33,803 additions and 33,795 deletions.
1 change: 0 additions & 1 deletion .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion enricher/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func (c *Cache) update() {
}
}

level.Info(c.logger).Log("msg", "Cache updated", "devices", len(c.devices), "ports", len(c.ports), "switchPorts", len(c.portsByName), "ignoredSwitchPorts", ignored)
level.Info(c.logger).Log("msg", "IAA Service cache updated", "devices", len(c.devices), "ports", len(c.ports), "switchPorts", len(c.portsByName), "ignoredSwitchPorts", ignored)
}

func (c *Cache) GetDevice(target string) *admin.Switch {
Expand Down
4 changes: 2 additions & 2 deletions enricher/enricher.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ func (e *Enricher) Write(bytes []byte) (int, error) {

metricFamilies, err := parser.TextToMetricFamilies(r)
if err != nil {
fmt.Printf("Error parsing metrics: %v\n", err)
return 0, err
// Probably no metrics here, just return the bytes
return e.w.Write(bytes)
}

// iterate over the metrics and add the IAA specific labels
Expand Down
17 changes: 13 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,19 @@ func handler(w *enricher.Enricher, r *http.Request, logger log.Logger, exporterM
sc.RLock()
auth, authOk := sc.C.Auths[authName]
if !authOk {
sc.RUnlock()
http.Error(w, fmt.Sprintf("Unknown auth '%s'", authName), http.StatusBadRequest)
snmpRequestErrors.Inc()
return
// If we have a pipe character in the authName, split it, and use the first part as the template, the second as the community.
if strings.Contains(authName, "|") {
parts := strings.Split(authName, "|")
auth, authOk = sc.C.Auths[parts[0]]
if authOk {
auth.Community = config.Secret(parts[1])
}
} else {
sc.RUnlock()
http.Error(w, fmt.Sprintf("Unknown auth '%s'", authName), http.StatusBadRequest)
snmpRequestErrors.Inc()
return
}
}
var nmodules []*collector.NamedModule
for _, m := range modules {
Expand Down
Loading

0 comments on commit fe32b7b

Please sign in to comment.