Skip to content

Commit

Permalink
Merge pull request #202 from czerwonk/v0.10
Browse files Browse the repository at this point in the history
V0.10
  • Loading branch information
czerwonk committed Nov 22, 2022
2 parents 97376fe + c7673d7 commit cd5c13a
Show file tree
Hide file tree
Showing 108 changed files with 1,427 additions and 1,381 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.18
go-version: 1.19

- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v2
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
test:
strategy:
matrix:
go-version: [1.18.x]
go-version: [1.19.x]
platform: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.platform }}
steps:
Expand Down
19 changes: 0 additions & 19 deletions accounting/accounting_flow.go

This file was deleted.

67 changes: 0 additions & 67 deletions accounting/rpc.go

This file was deleted.

6 changes: 0 additions & 6 deletions alarm/alarm_counter.go

This file was deleted.

20 changes: 0 additions & 20 deletions bfd/rpc.go

This file was deleted.

70 changes: 35 additions & 35 deletions collectors.go
Original file line number Diff line number Diff line change
@@ -1,40 +1,40 @@
package main

import (
"github.com/czerwonk/junos_exporter/accounting"
"github.com/czerwonk/junos_exporter/alarm"
"github.com/czerwonk/junos_exporter/bfd"
"github.com/czerwonk/junos_exporter/bgp"
"github.com/czerwonk/junos_exporter/collector"
"github.com/czerwonk/junos_exporter/config"
"github.com/czerwonk/junos_exporter/connector"
"github.com/czerwonk/junos_exporter/environment"
"github.com/czerwonk/junos_exporter/firewall"
"github.com/czerwonk/junos_exporter/fpc"
"github.com/czerwonk/junos_exporter/interfacediagnostics"
"github.com/czerwonk/junos_exporter/interfacelabels"
"github.com/czerwonk/junos_exporter/interfacequeue"
"github.com/czerwonk/junos_exporter/interfaces"
"github.com/czerwonk/junos_exporter/ipsec"
"github.com/czerwonk/junos_exporter/isis"
"github.com/czerwonk/junos_exporter/l2circuit"
"github.com/czerwonk/junos_exporter/lacp"
"github.com/czerwonk/junos_exporter/ldp"
"github.com/czerwonk/junos_exporter/mac"
"github.com/czerwonk/junos_exporter/mpls_lsp"
"github.com/czerwonk/junos_exporter/nat"
"github.com/czerwonk/junos_exporter/nat2"
"github.com/czerwonk/junos_exporter/ospf"
"github.com/czerwonk/junos_exporter/power"
"github.com/czerwonk/junos_exporter/route"
"github.com/czerwonk/junos_exporter/routingengine"
"github.com/czerwonk/junos_exporter/rpki"
"github.com/czerwonk/junos_exporter/rpm"
"github.com/czerwonk/junos_exporter/security"
"github.com/czerwonk/junos_exporter/storage"
"github.com/czerwonk/junos_exporter/system"
"github.com/czerwonk/junos_exporter/vrrp"
"github.com/czerwonk/junos_exporter/vpws"
"github.com/czerwonk/junos_exporter/internal/config"
"github.com/czerwonk/junos_exporter/pkg/collector"
"github.com/czerwonk/junos_exporter/pkg/connector"
"github.com/czerwonk/junos_exporter/pkg/features/accounting"
"github.com/czerwonk/junos_exporter/pkg/features/alarm"
"github.com/czerwonk/junos_exporter/pkg/features/bfd"
"github.com/czerwonk/junos_exporter/pkg/features/bgp"
"github.com/czerwonk/junos_exporter/pkg/features/environment"
"github.com/czerwonk/junos_exporter/pkg/features/firewall"
"github.com/czerwonk/junos_exporter/pkg/features/fpc"
"github.com/czerwonk/junos_exporter/pkg/features/interfacediagnostics"
"github.com/czerwonk/junos_exporter/pkg/features/interfacequeue"
"github.com/czerwonk/junos_exporter/pkg/features/interfaces"
"github.com/czerwonk/junos_exporter/pkg/features/ipsec"
"github.com/czerwonk/junos_exporter/pkg/features/isis"
"github.com/czerwonk/junos_exporter/pkg/features/l2circuit"
"github.com/czerwonk/junos_exporter/pkg/features/lacp"
"github.com/czerwonk/junos_exporter/pkg/features/ldp"
"github.com/czerwonk/junos_exporter/pkg/features/mac"
"github.com/czerwonk/junos_exporter/pkg/features/mplslsp"
"github.com/czerwonk/junos_exporter/pkg/features/nat"
"github.com/czerwonk/junos_exporter/pkg/features/nat2"
"github.com/czerwonk/junos_exporter/pkg/features/ospf"
"github.com/czerwonk/junos_exporter/pkg/features/power"
"github.com/czerwonk/junos_exporter/pkg/features/route"
"github.com/czerwonk/junos_exporter/pkg/features/routingengine"
"github.com/czerwonk/junos_exporter/pkg/features/rpki"
"github.com/czerwonk/junos_exporter/pkg/features/rpm"
"github.com/czerwonk/junos_exporter/pkg/features/security"
"github.com/czerwonk/junos_exporter/pkg/features/storage"
"github.com/czerwonk/junos_exporter/pkg/features/system"
"github.com/czerwonk/junos_exporter/pkg/features/vpws"
"github.com/czerwonk/junos_exporter/pkg/features/vrrp"
"github.com/czerwonk/junos_exporter/pkg/interfacelabels"
)

type collectors struct {
Expand Down Expand Up @@ -107,7 +107,7 @@ func (c *collectors) initCollectorsForDevices(device *connector.Device) {
c.addCollectorIfEnabledForDevice(device, "mac", f.MAC, mac.NewCollector)
c.addCollectorIfEnabledForDevice(device, "vrrp", f.VRRP, vrrp.NewCollector)
c.addCollectorIfEnabledForDevice(device, "vpws", f.VPWS, vpws.NewCollector)
c.addCollectorIfEnabledForDevice(device, "mpls_lsp", f.MPLS_LSP, mpls_lsp.NewCollector)
c.addCollectorIfEnabledForDevice(device, "mpls_lsp", f.MPLSLSP, mplslsp.NewCollector)
}

func (c *collectors) addCollectorIfEnabledForDevice(device *connector.Device, key string, enabled bool, newCollector func() collector.RPCCollector) {
Expand Down
6 changes: 3 additions & 3 deletions collectors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import (

"github.com/stretchr/testify/assert"

"github.com/czerwonk/junos_exporter/config"
"github.com/czerwonk/junos_exporter/connector"
"github.com/czerwonk/junos_exporter/interfacelabels"
"github.com/czerwonk/junos_exporter/internal/config"
"github.com/czerwonk/junos_exporter/pkg/connector"
"github.com/czerwonk/junos_exporter/pkg/interfacelabels"
)

func TestCollectorsRegistered(t *testing.T) {
Expand Down
21 changes: 13 additions & 8 deletions devices.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"regexp"
"strings"

"github.com/czerwonk/junos_exporter/config"
"github.com/czerwonk/junos_exporter/connector"
"github.com/czerwonk/junos_exporter/internal/config"
"github.com/czerwonk/junos_exporter/pkg/connector"
"github.com/pkg/errors"
)

Expand All @@ -19,13 +19,18 @@ func devicesForConfig(cfg *config.Config) ([]*connector.Device, error) {
cfg.Devices = devicesFromTargets(cfg.Targets)
}

devs := make([]*connector.Device, len(cfg.Devices))
var err error
for i, d := range cfg.Devices {
devs[i], err = deviceFromDeviceConfig(d, cfg)
devs := make([]*connector.Device, 0)
for _, d := range cfg.Devices {
if d.IsHostPattern {
continue
}

dev, err := deviceFromDeviceConfig(d, d.Host, cfg)
if err != nil {
return nil, err
}

devs = append(devs, dev)
}

return devs, nil
Expand All @@ -42,7 +47,7 @@ func devicesFromTargets(targets []string) []*config.DeviceConfig {
return devices
}

func deviceFromDeviceConfig(device *config.DeviceConfig, cfg *config.Config) (*connector.Device, error) {
func deviceFromDeviceConfig(device *config.DeviceConfig, hostname string, cfg *config.Config) (*connector.Device, error) {
auth, err := authForDevice(device, cfg)
if err != nil {
return nil, errors.Wrapf(err, "could not initialize config for device %s", device.Host)
Expand All @@ -56,7 +61,7 @@ func deviceFromDeviceConfig(device *config.DeviceConfig, cfg *config.Config) (*c
}

return &connector.Device{
Host: device.Host,
Host: hostname,
Auth: auth,
}, nil
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/czerwonk/junos_exporter

go 1.18
go 1.19

require (
github.com/pkg/errors v0.9.1
Expand Down
11 changes: 5 additions & 6 deletions config/config.go → internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package config

import (
"io"
"io/ioutil"
"regexp"

"gopkg.in/yaml.v2"
Expand Down Expand Up @@ -60,7 +59,7 @@ type FeatureConfig struct {
System bool `yaml:"system,omitempty"`
Power bool `yaml:"power,omitempty"`
MAC bool `yaml:"mac,omitempty"`
MPLS_LSP bool `yaml:"mpls_lsp,omitempty"`
MPLSLSP bool `yaml:"mpls_lsp,omitempty"`
VPWS bool `yaml:"vpws,omitempty"`
VRRP bool `yaml:"vrrp,omitempty"`
}
Expand All @@ -77,7 +76,7 @@ func New() *Config {

// Load loads a config from reader
func Load(reader io.Reader) (*Config, error) {
b, err := ioutil.ReadAll(reader)
b, err := io.ReadAll(reader)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -129,15 +128,15 @@ func setDefaultValues(c *Config) {
f.Satellite = false
f.Power = false
f.MAC = false
f.MPLS_LSP = false
f.MPLSLSP = false
f.VPWS = false
f.VRRP = false
f.BFD = false
}

// FeaturesForDevice gets the feature set configured for a device
func (c *Config) FeaturesForDevice(host string) *FeatureConfig {
d := c.findDeviceConfig(host)
d := c.FindDeviceConfig(host)

if d != nil && d.Features != nil {
return d.Features
Expand All @@ -146,7 +145,7 @@ func (c *Config) FeaturesForDevice(host string) *FeatureConfig {
return &c.Features
}

func (c *Config) findDeviceConfig(host string) *DeviceConfig {
func (c *Config) FindDeviceConfig(host string) *DeviceConfig {
for _, dc := range c.Devices {
if dc.HostPattern != nil {
if dc.HostPattern.MatchString(host) {
Expand Down
Loading

0 comments on commit cd5c13a

Please sign in to comment.