master
go 52 lines 1.46 KB
Raw
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 package snmp
4
5 import (
6 "fmt"
7 "log/slog"
8 "path/filepath"
9 "strings"
10
11 "github.com/netdata/netdata/go/plugins/logger"
12 "github.com/netdata/netdata/go/plugins/plugin/go.d/collector/snmp/ddsnmp"
13 "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/snmputils"
14 )
15
16 func (c *Collector) setupProfiles(si *snmputils.SysInfo) []*ddsnmp.Profile {
17 resolved := ddsnmp.DefaultCatalog().Resolve(ddsnmp.ResolveRequest{
18 SysObjectID: si.SysObjectID,
19 SysDescr: si.Descr,
20 ManualProfiles: c.ManualProfiles,
21 ManualPolicy: ddsnmp.ManualProfileFallback,
22 })
23 matchedProfiles := resolved.Profiles()
24 c.logMatchedProfiles(matchedProfiles, si.SysObjectID)
25
26 profiles := resolved.Project(ddsnmp.ConsumerMetrics, ddsnmp.ConsumerLicensing, ddsnmp.ConsumerBGP).Profiles()
27 if profilesHaveBGP(profiles) {
28 c.enableBGPIntegration()
29 }
30
31 return profiles
32 }
33
34 func (c *Collector) logMatchedProfiles(profiles []*ddsnmp.Profile, sysObjectID string) {
35 var profInfo []string
36
37 for _, prof := range profiles {
38 if logger.Level.Enabled(slog.LevelDebug) {
39 profInfo = append(profInfo, prof.SourceTree())
40 } else {
41 name := strings.TrimSuffix(filepath.Base(prof.SourceFile), filepath.Ext(prof.SourceFile))
42 profInfo = append(profInfo, name)
43 }
44 }
45
46 msg := fmt.Sprintf("device matched %d profile(s): %s (sysObjectID: '%s')", len(profiles), strings.Join(profInfo, ", "), sysObjectID)
47 if len(profiles) == 0 {
48 c.Warning(msg)
49 } else {
50 c.Info(msg)
51 }
52 }