Skip to content

Commit 21ba9f1

Browse files
committed
wip for discovery via netbox
1 parent 37da3dd commit 21ba9f1

File tree

5 files changed

+45
-0
lines changed

5 files changed

+45
-0
lines changed

go.mod

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ require (
4444
github.com/liamg/furious v0.0.0-20191231090757-c295c872d6c1
4545
github.com/linkedin/goavro/v2 v2.10.1
4646
github.com/montanaflynn/stats v0.7.0
47+
github.com/netbox-community/go-netbox/v4 v4.2.2-3
4748
github.com/netsampler/goflow2/v2 v2.1.3
4849
github.com/oschwald/geoip2-golang v1.9.0
4950
github.com/pkg/errors v0.9.1

go.sum

+2
Original file line numberDiff line numberDiff line change
@@ -717,6 +717,8 @@ github.com/montanaflynn/stats v0.7.0/go.mod h1:etXPPgVO6n31NxCd9KQUMvCM+ve0ruNzt
717717
github.com/mostlygeek/arp v0.0.0-20170424181311-541a2129847a h1:AfneHvfmYgUIcgdUrrDFklLdEzQAvG9AKRTe1x1mx/0=
718718
github.com/mostlygeek/arp v0.0.0-20170424181311-541a2129847a/go.mod h1:jZxafo9CAqaKFQE4zitrg5QNlA6CXUsjwXPlIppF3tk=
719719
github.com/ncw/swift v1.0.52/go.mod h1:23YIA4yWVnGwv2dQlN4bB7egfYX6YLn0Yo/S6zZO/ZM=
720+
github.com/netbox-community/go-netbox/v4 v4.2.2-3 h1:NrAkuI41ExiYa6p1o7F0NvxcS2qxsVJfymR5hAZglDs=
721+
github.com/netbox-community/go-netbox/v4 v4.2.2-3/go.mod h1:X7jbSuzejM0U5uy/ajXidRFEAshl6eKqrcinhMy4aAI=
720722
github.com/netsampler/goflow2/v2 v2.1.3 h1:glfeG2hIzFlAmEz236nZIAWi848AB+p1pJnuQqiyLkI=
721723
github.com/netsampler/goflow2/v2 v2.1.3/go.mod h1:94ZaxfHuUwG6KviCxMWuZIvz0UGu657StE/g83hlS8A=
722724
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=

pkg/inputs/snmp/disco.go

+8
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,14 @@ func Discover(ctx context.Context, log logger.ContextL, pollDuration time.Durati
8787
}
8888
defer mdb.Close()
8989

90+
if conf.Disco.NetboxAPIHost != "" {
91+
err = getDevicesFromNetbox(ctx, conf, log)
92+
if err != nil {
93+
return nil, err
94+
}
95+
return nil, nil
96+
}
97+
9098
ignoreMap := map[string]bool{}
9199
for _, ip := range conf.Disco.IgnoreList {
92100
ignoreMap[ip] = true

pkg/inputs/snmp/netbox.go

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package snmp
2+
3+
/**
4+
Use netbox API to pull down list of devices to target. Get all devices matching a given tag.
5+
*/
6+
import (
7+
"context"
8+
9+
"github.com/kentik/ktranslate/pkg/eggs/logger"
10+
"github.com/kentik/ktranslate/pkg/kt"
11+
12+
"github.com/netbox-community/go-netbox/v4"
13+
)
14+
15+
func getDevicesFromNetbox(ctx context.Context, conf *kt.SnmpConfig, log logger.ContextL) error {
16+
c := netbox.NewAPIClientFor(conf.Disco.NetboxAPIHost, conf.Disco.NetboxAPIToken)
17+
18+
res, _, err := c.DcimAPI.
19+
DcimDevicesList(ctx).
20+
Status([]string{"active"}).
21+
Limit(10).
22+
Execute()
23+
24+
if err != nil {
25+
return err
26+
}
27+
28+
log.Infof("%v", res.Results)
29+
30+
return nil
31+
32+
}

pkg/kt/snmp.go

+2
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,8 @@ type SnmpDiscoConfig struct {
258258
CidrOrig string `yaml:"-"`
259259
IgnoreOrig string `yaml:"-"`
260260
NoUseBulkWalkAll bool `yaml:"no_use_bulkwalkall"`
261+
NetboxAPIHost string `yaml:"netbox_host"`
262+
NetboxAPIToken string `yaml:"netbox_token"`
261263
}
262264

263265
type ProviderMap struct {

0 commit comments

Comments
 (0)