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

adding virtual-chassis check #192

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ States map to human readable names like this:
4 = "Ex-Incr"
5 = "Ex-Full"
```
* VirtualChassis (status of members)
```
0 = "NotPrsnt"
1 = "NotPrsnt"
```
* VRRP (state per interface)
States map to human readable names like this:
```
Expand Down
2 changes: 2 additions & 0 deletions collectors.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
"github.com/czerwonk/junos_exporter/security"
"github.com/czerwonk/junos_exporter/storage"
"github.com/czerwonk/junos_exporter/system"
"github.com/czerwonk/junos_exporter/virtualchassis"
"github.com/czerwonk/junos_exporter/vrrp"
"github.com/czerwonk/junos_exporter/vpws"
)
Expand Down Expand Up @@ -105,6 +106,7 @@ func (c *collectors) initCollectorsForDevices(device *connector.Device) {
c.addCollectorIfEnabledForDevice(device, "system", f.System, system.NewCollector)
c.addCollectorIfEnabledForDevice(device, "power", f.Power, power.NewCollector)
c.addCollectorIfEnabledForDevice(device, "mac", f.MAC, mac.NewCollector)
c.addCollectorIfEnabledForDevice(device, "virtualchassis", f.VirtualChassis, virtualchassis.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)
Expand Down
2 changes: 2 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ type FeatureConfig struct {
Power bool `yaml:"power,omitempty"`
MAC bool `yaml:"mac,omitempty"`
MPLS_LSP bool `yaml:"mpls_lsp,omitempty"`
VirtualChassis bool `yaml:"virtualchassis,omitempty"`
VPWS bool `yaml:"vpws,omitempty"`
VRRP bool `yaml:"vrrp,omitempty"`
}
Expand Down Expand Up @@ -130,6 +131,7 @@ func setDefaultValues(c *Config) {
f.Power = false
f.MAC = false
f.MPLS_LSP = false
f.VirtualChassis = false
f.VPWS = false
f.VRRP = false
f.BFD = false
Expand Down
65 changes: 65 additions & 0 deletions virtualchassis/collector.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package virtualchassis

import (
"github.com/czerwonk/junos_exporter/collector"
"github.com/czerwonk/junos_exporter/rpc"
"github.com/prometheus/client_golang/prometheus"
)

const prefix = "junos_virtualchassis_"

var (
virtualchassismemberstatus *prometheus.Desc
)

func init() {
l := []string{"target", "status", "serial", "model", "id", "fpcslot", "role"}
virtualchassismemberstatus = prometheus.NewDesc(prefix+"member_status", "virtualchassis member-status (1: Prsnt, 0: NotPrsnt)", l, nil)
}

type virtualchassisCollector struct {
}

// Name returns the name of the collector
func (*virtualchassisCollector) Name() string {
return "virtualchassis"
}

// NewCollector creates a new collector
func NewCollector() collector.RPCCollector {
return &virtualchassisCollector{}
}

// Describe describes the metrics
func (*virtualchassisCollector) Describe(ch chan<- *prometheus.Desc) {
ch <- virtualchassismemberstatus
}

// Collect collects metrics from JunOS
func (c *virtualchassisCollector) Collect(client *rpc.Client, ch chan<- prometheus.Metric, labelValues []string) error {
statusValues := map[string]int{
"NotPrsnt": 0,
"Prsnt": 1,
}

var x = virtualChassisRpc{}
if client.Netconf {
err := client.RunCommandAndParse("<get-virtual-chassis-information/>", &x)
if err != nil {
return nil
}
} else {
err := client.RunCommandAndParse("show virtual-chassis", &x)
if err != nil {
return err
}
}

for _, m := range x.VirtualChassisInformation.MemberList.Member {
l := labelValues
l = append(l, m.Status, m.SerialNumber, m.Model, m.Id, m.FpcSlot, m.Role )
ch <- prometheus.MustNewConstMetric(virtualchassismemberstatus, prometheus.GaugeValue, float64(statusValues[m.Status]), l...)
}

return nil
}
22 changes: 22 additions & 0 deletions virtualchassis/rpc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package virtualchassis

type virtualChassisRpc struct {
VirtualChassisInformation struct {
VirtualChassisIdInformation struct {
VirtualChassisId string `xml:"virtual-chassis-id"`
VirtualChassisMode string `xml:"virtual-chassis-mode"`
} `xml:"virtual-chassis-id-information"`
MemberList struct {
Member []vcmembers `xml:"member"`
} `xml:"member-list"`
} `xml:"virtual-chassis-information"`
}

type vcmembers struct {
Status string `xml:"member-status"`
Id string `xml:"member-id"`
FpcSlot string `xml:"fpc-slot"`
SerialNumber string `xml:"member-serial-number"`
Model string `xml:"member-model"`
Role string `xml:"member-role"`
}
6 changes: 6 additions & 0 deletions vpws/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@ func (c *vpwsCollector) Collect(client *rpc.Client, ch chan<- prometheus.Metric,
ch <- prometheus.MustNewConstMetric(vpwsSid, prometheus.GaugeValue, float64(vpwsSidMap[vSid.Status]), l...)
}


if vIf.RemoteStatus.LocalInterfaceName != "" {
l := append(labelValues, vInst.Name, vInst.RD, vIf.Name, "remote", vIf.RemoteStatus.Sid, vIf.RemoteStatus.LocalInterfaceName, "", "local", "")
ch <- prometheus.MustNewConstMetric(vpwsSid, prometheus.GaugeValue, float64(vpwsStatusMap[vIf.RemoteStatus.LocalInterfaceStatus]), l...)
}

for _, vSid := range vIf.RemoteStatus.SidPeInfo {
l := append(labelValues, vInst.Name, vInst.RD, vIf.Name, "remote", vIf.RemoteStatus.Sid, vSid.IP, vSid.Esi, vSid.Mode, vSid.Role)
ch <- prometheus.MustNewConstMetric(vpwsSid, prometheus.GaugeValue, float64(vpwsSidMap[vSid.Status]), l...)
Expand Down
6 changes: 4 additions & 2 deletions vpws/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@ type vpwsInterface struct {
} `xml:"evpn-vpws-service-id-local-status-table>evpn-vpws-sid-local"`

RemoteStatus struct {
Sid string `xml:"evpn-vpws-sid-remote-value"`
SidPeInfo []vpwsSidPeInfo `xml:"evpn-vpws-sid-pe-status-table>evpn-vpws-sid-pe-info"`
Sid string `xml:"evpn-vpws-sid-remote-value"`
LocalInterfaceName string `xml:"evpn-vpws-sid-local-interface-name"`
LocalInterfaceStatus string `xml:"evpn-vpws-sid-local-interface-status"`
SidPeInfo []vpwsSidPeInfo `xml:"evpn-vpws-sid-pe-status-table>evpn-vpws-sid-pe-info"`
} `xml:"evpn-vpws-service-id-remote-status-table>evpn-vpws-sid-remote"`
}

Expand Down