Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V0.10 #202

Merged
merged 29 commits into from
Nov 22, 2022
Merged

V0.10 #202

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
8219716
upgrade go 1.19, optimize locking
czerwonk Nov 21, 2022
2710920
fix unused flags
czerwonk Nov 21, 2022
199101a
use double check ideom
czerwonk Nov 21, 2022
c2e1330
replace ioutil usages
czerwonk Nov 21, 2022
4608030
please the linter for modules: VRRP, VPWS, System, Storage
czerwonk Nov 21, 2022
fed844e
please the linter for security
czerwonk Nov 21, 2022
52ac070
please the linter for rpm
czerwonk Nov 21, 2022
bd91b1d
please linter for RPKI
czerwonk Nov 21, 2022
648e98d
rename test file
czerwonk Nov 21, 2022
1aec04a
please linter for routingengine
czerwonk Nov 21, 2022
857e756
please linter for route
czerwonk Nov 21, 2022
be815d3
please the linter for power
czerwonk Nov 21, 2022
d5a4de6
please the linter: ospf
czerwonk Nov 21, 2022
e68732b
introduce new folder structure
czerwonk Nov 21, 2022
503ce28
move refactored modules
czerwonk Nov 21, 2022
f1a5648
move collector and rpc package
czerwonk Nov 21, 2022
1b67ca8
linter: accounting
czerwonk Nov 21, 2022
98022fb
linter: alarm
czerwonk Nov 21, 2022
72ffdb2
refactor system collector
czerwonk Nov 22, 2022
1eee734
make the linter more happy
czerwonk Nov 22, 2022
125cf43
make the linter more happy
czerwonk Nov 22, 2022
9ffbec5
make the linter more happy
czerwonk Nov 22, 2022
e26b43f
cleanup
czerwonk Nov 22, 2022
9ab61df
remove ignoreConfigTargets in favor of device templates (host pattern)
czerwonk Nov 22, 2022
329cf1e
remove unused ssh connections if not used any more
czerwonk Nov 22, 2022
b6c1788
set default expire timeout to 15 minutes
czerwonk Nov 22, 2022
8a5d632
skip host pattern devices
czerwonk Nov 22, 2022
103fa42
return after terminating connection when expired
czerwonk Nov 22, 2022
c7673d7
fix error logging for interface regex
czerwonk Nov 22, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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