Documentation ¶
Overview ¶
Package gateway provides an easily configurable server that can connect to multiple gNMI targets (devices) and relay received messages to various exporters and to downstream gNMI clients.
Targets are configured via a TargetLoader which generate all of the needed configuration for connecting to a target. See github.com/openconfig/gnmi/proto/target for details on the Configuration options that are available. See the TargetLoader docs for the minimum configuration required to connect to a target.
The gateway only supports TLS so you'll need to generate some keys first if you don't already have them. In production you should use properly signed TLS certificates.
# Generate private key (server.key) openssl genrsa -out server.key 2048 # or openssl ecparam -genkey -name secp384r1 -out server.key # Generation of self-signed(x509) public key (server.crt) based on the private key (server.key) openssl req -new -x509 -sha256 -key server.key -out server.crt -days 3650
You'll also need a copy of the latest OpenConfig YANG models if you don't already have it.
git clone https://github.com/openconfig/public.git oc-models
Finally, you need to build your target configurations. Copy targets-example.json to targets.json and edit it to match the targets you want to connect to.
cp targets-example.json targets.json vim targets.json
See the example below or the Main() function in gateway.go for an example of how to start the server. If you'd like to just use the built-in loaders and exporters you can configure them more easily from the command line:
go build ./gnmi-gateway -EnableGNMIServer -EnablePrometheusExporter -OpenConfigDirectory=./oc-models/
Example ¶
A simple example of how to configure the gateway.
config := &configuration.GatewayConfig{ EnableGNMIServer: true, OpenConfigDirectory: "./oc-models", ServerListenPort: 2906, ServerTLSCert: "server.crt", ServerTLSKey: "server.key", TargetLoaders: &configuration.TargetLoadersConfig{ Enabled: []string{"json"}, JSONFile: "targets.json", JSONFileReloadInterval: 60 * time.Second, }, TargetDialTimeout: 5 * time.Second, TargetLimit: 100, ZookeeperHosts: []string{"127.0.0.1"}, ZookeeperTimeout: 1 * time.Second, } gateway := NewGateway(config) err := gateway.StartGateway(&StartOpts{ TargetLoaders: []loaders.TargetLoader{json.NewJSONFileTargetLoader(config)}, Exporters: []exporters.Exporter{ prometheus.NewPrometheusExporter(config), }, }) // run forever (or until an error happens) if err != nil { fmt.Printf("Gateway exited with an error: %v", err) os.Exit(1) }
Output:
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ( // Buildtime is set to the current time during the build process by GOLDFLAGS Buildtime string // Version is set to the current git tag during the build process by GOLDFLAGS Version string )
var ( CPUProfile string PrintVersion bool PProf bool )
Functions ¶
func Main ¶
func Main()
Main is the entry point for the command-line and it's a good example of how to call StartGateway but other than that you probably don't need Main for anything.
func ParseArgs ¶
func ParseArgs(config *configuration.GatewayConfig) error
ParseArgs will parse all of the command-line parameters and configured the associated attributes on the GatewayConfig. ParseArgs calls flag.Parse before returning so if you need to add arguments you should make any calls to flag before calling ParseArgs.
func SetupDebugging ¶
func SetupDebugging(config *configuration.GatewayConfig) (func(), error)
SetupDebugging optionally sets up debugging features including -LogCaller and -PProf.
Types ¶
type CacheClient ¶ added in v0.7.0
type CacheClient struct { External bool // contains filtered or unexported fields }
func NewCacheClient ¶ added in v0.8.0
func NewCacheClient(name string, newClient func(leaf *ctree.Leaf), external bool, size uint64) *CacheClient
NewCacheClient creates a new cache client instance and starts the associated goroutines.
func (*CacheClient) Send ¶ added in v0.7.0
func (c *CacheClient) Send(leaf *ctree.Leaf)
type Gateway ¶
type Gateway struct {
// contains filtered or unexported fields
}
func NewGateway ¶
func NewGateway(config *configuration.GatewayConfig) *Gateway
NewGateway returns an new Gateway instance.
func (*Gateway) AddClient ¶
Client functions need to complete very quickly to prevent blocking upstream.
func (*Gateway) StartGNMIServer ¶
StartGNMIServer will start the gNMI server that serves the Subscribe interface to downstream gNMI clients.
func (*Gateway) StartGateway ¶
StartGateway starts up all of the loaders and exporters provided by StartOpts. This is the primary way the server should be started.
Directories ¶
Path | Synopsis |
---|---|
Package clustering provides an interface to register and list members in a cluster.
|
Package clustering provides an interface to register and list members in a cluster. |
Package configuration contains the GatewayConfig type that is used by the gateway package and all of it's sub-packages.
|
Package configuration contains the GatewayConfig type that is used by the gateway package and all of it's sub-packages. |
Package connections provides the connection manager that forms the transport connection to gNMI targets and initiates gNMI RPC calls.
|
Package connections provides the connection manager that forms the transport connection to gNMI targets and initiates gNMI RPC calls. |
Package exporters provides an interface to export gNMI notifications to other systems or data formats.
|
Package exporters provides an interface to export gNMI notifications to other systems or data formats. |
debug
Package debug provides an exporter that will log all received gNMI messages for debugging purposes.
|
Package debug provides an exporter that will log all received gNMI messages for debugging purposes. |
Package loaders provides an interface load target configurations into the connection manager.
|
Package loaders provides an interface load target configurations into the connection manager. |
netbox
Package netbox provides a TargetLoader for loading devices from NetBox.
|
Package netbox provides a TargetLoader for loading devices from NetBox. |
simple
Package simple provides a TargetLoader for parsing a simple target YAML config file.
|
Package simple provides a TargetLoader for parsing a simple target YAML config file. |
Package openconfig provides useful types and functions for interacting with OpenConfig modeled data.
|
Package openconfig provides useful types and functions for interacting with OpenConfig modeled data. |
Package server implements the gnmi.proto service API.
|
Package server implements the gnmi.proto service API. |