Skip to content

Commit

Permalink
Format code
Browse files Browse the repository at this point in the history
  • Loading branch information
mraerino committed May 31, 2024
1 parent 94847f1 commit 1c0abc8
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 28 deletions.
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ require (
github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.14.0
github.com/sirupsen/logrus v1.9.0
github.com/slashdoom/aruba_exporter v0.0.0-20230115101642-1866425048c5
golang.org/x/crypto v0.5.0
gopkg.in/yaml.v2 v2.4.0
)
Expand Down
30 changes: 15 additions & 15 deletions wireless/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

"github.com/slashdoom/aruba_exporter/rpc"
"github.com/slashdoom/aruba_exporter/util"

log "github.com/sirupsen/logrus"
)

Expand All @@ -20,7 +20,7 @@ func (c *wirelessCollector) ParseAccessPoints(ostype string, output string) (map
aps := make(map[string]WirelessAccessPoint)

lines := strings.Split(output, "\n")

if ostype == rpc.ArubaController {
return aps, nil
}
Expand All @@ -30,12 +30,12 @@ func (c *wirelessCollector) ParseAccessPoints(ostype string, output string) (map
APNameRegexp, _ := regexp.Compile(`^!~~~NO_MATCHES~~~!$`)

ap := WirelessAccessPoint{}
currentAPIP:= ""
currentAPIP := ""

for _, line := range lines {

log.Tracef("line: %+v", line)

if matches := ConductorIPRegexp.FindStringSubmatch(line); matches != nil {
ap = WirelessAccessPoint{Controller: false}
currentAPIP = ""
Expand Down Expand Up @@ -72,13 +72,13 @@ func (c *wirelessCollector) ParseAccessPoints(ostype string, output string) (map
func (c *wirelessCollector) ParseChannels(ostype string, output string) (map[string]WirelessChannel, map[string]WirelessRadio, error) {
log.Debugf("OS: %s\n", ostype)
log.Tracef("output: %s\n", output)

channels := make(map[string]WirelessChannel)
radios := make(map[string]WirelessRadio)

lines := strings.Split(output, "\n")
currentInt := ""

if ostype == rpc.ArubaController {
return channels, radios, nil
}
Expand All @@ -99,12 +99,12 @@ func (c *wirelessCollector) ParseChannels(ostype string, output string) (map[str
if matches := channelRegexp.FindStringSubmatch(line); matches != nil {
channel := WirelessChannel{
AccessPoint: apName,
Band: util.Str2float64(matches[1]),
NoiseFloor: util.Str2float64(matches[3]),
ChUtil: util.Str2float64(matches[4]),
ChQual: util.Str2float64(matches[5]),
CovrIndex: util.Str2float64(matches[6]),
IntfIndex: util.Str2float64(matches[7]),
Band: util.Str2float64(matches[1]),
NoiseFloor: util.Str2float64(matches[3]),
ChUtil: util.Str2float64(matches[4]),
ChQual: util.Str2float64(matches[5]),
CovrIndex: util.Str2float64(matches[6]),
IntfIndex: util.Str2float64(matches[7]),
}
channels[matches[2]] = channel
log.Debugf("channel name: %+v\n", matches[2])
Expand Down Expand Up @@ -143,7 +143,7 @@ func (c *wirelessCollector) ParseChannels(ostype string, output string) (map[str

return channels, radios, nil
}

return make(map[string]WirelessChannel), make(map[string]WirelessRadio), errors.New("Channel info not found")
}

Expand Down
44 changes: 32 additions & 12 deletions wireless/wireless_collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ func (c *wirelessCollector) CollectAccessPoints(client *rpc.Client, ch chan<- pr
return make(map[string]WirelessAccessPoint), err
}
for apName, apData := range aps {
l := append(labelValues, fmt.Sprintf("%v",apName))
l := append(labelValues, fmt.Sprintf("%v", apName))

apUpStatus := 0
if apData.Up {
apUpStatus = 1
Expand All @@ -109,13 +109,33 @@ func (c *wirelessCollector) CollectAccessPoints(client *rpc.Client, ch chan<- pr
return aps, nil
}

func (c *wirelessCollector) CollectVLANUsage(client *rpc.Client, ch chan<- prometheus.Metric) error {
out, err := client.RunCommand([]string{"show ap vlan-usage"})
if err != nil {
return err
}

stats := parseAPVLANUsage(out)
log.Debugf("vlan usage: %#v", stats)
for vlan, clients := range stats {
ch <- prometheus.MustNewConstMetric(
apVLANUsageDesc,
prometheus.GaugeValue,
float64(clients),
strconv.Itoa(vlan),
)
}

return nil
}

// CollectChannels collects memory informations from Aruba Devices
func (c *wirelessCollector) CollectChannels(client *rpc.Client, ch chan<- prometheus.Metric, labelValues []string) (map[string]WirelessRadio, error) {
var (
out string
out string
channels map[string]WirelessChannel
radios map[string]WirelessRadio
err error
radios map[string]WirelessRadio
err error
)

switch client.OSType {
Expand All @@ -139,7 +159,7 @@ func (c *wirelessCollector) CollectChannels(client *rpc.Client, ch chan<- promet
}
for chChannel, chData := range channels {
log.Debugf("channel data: %+v", chData)
l := append(labelValues, fmt.Sprintf("%v", chData.AccessPoint), fmt.Sprintf("%v",chChannel), fmt.Sprintf("%v", chData.Band))
l := append(labelValues, fmt.Sprintf("%v", chData.AccessPoint), fmt.Sprintf("%v", chChannel), fmt.Sprintf("%v", chData.Band))

ch <- prometheus.MustNewConstMetric(channelNoiseDesc, prometheus.GaugeValue, chData.NoiseFloor, l...)
ch <- prometheus.MustNewConstMetric(channelUtilDesc, prometheus.GaugeValue, chData.ChUtil, l...)
Expand All @@ -150,7 +170,7 @@ func (c *wirelessCollector) CollectChannels(client *rpc.Client, ch chan<- promet
return radios, nil
}

func (c *wirelessCollector) CollectRadios(client *rpc.Client, ch chan<- prometheus.Metric, labelValues []string, radios map[string]WirelessRadio) (error) {
func (c *wirelessCollector) CollectRadios(client *rpc.Client, ch chan<- prometheus.Metric, labelValues []string, radios map[string]WirelessRadio) error {
log.Debugf("client: %+v", client)
log.Debugf("labelValues: %+v", labelValues)
var (
Expand Down Expand Up @@ -179,7 +199,7 @@ func (c *wirelessCollector) CollectRadios(client *rpc.Client, ch chan<- promethe
}
for radioId, radioData := range radios {
log.Debugf("radio data: %+v", radioData)
l := append(labelValues, fmt.Sprintf("%v", radioData.AccessPoint), fmt.Sprintf("%v",radioId), fmt.Sprintf("%v", radioData.Bssid))
l := append(labelValues, fmt.Sprintf("%v", radioData.AccessPoint), fmt.Sprintf("%v", radioId), fmt.Sprintf("%v", radioData.Bssid))
log.Debugf("channel labels: %+v", l)
//ch <- prometheus.MustNewConstMetric(channelNoiseDesc, prometheus.GaugeValue, chData.NoiseFloor, l...)
//ch <- prometheus.MustNewConstMetric(channelUtilDesc, prometheus.GaugeValue, chData.ChUtil, l...)
Expand All @@ -195,20 +215,20 @@ func (c *wirelessCollector) Collect(client *rpc.Client, ch chan<- prometheus.Met
log.Debugf("client: %+v", client)
log.Debugf("labelValues: %+v", labelValues)
var err error
var aps map[string]WirelessAccessPoint

var aps map[string]WirelessAccessPoint
aps, err = c.CollectAccessPoints(client, ch, labelValues)
if err != nil {
log.Debugf("CollectAccessPoints for %s: %s\n", labelValues[0], err.Error())
}
log.Debugf("aps: %+v", aps)

var radios map[string]WirelessRadio
var radios map[string]WirelessRadio
radios, err = c.CollectChannels(client, ch, labelValues)
if err != nil {
log.Debugf("CollectChannels for %s: %s\n", labelValues[0], err.Error())
}
log.Debugf("radios: %+v", radios)

return nil
}
}

0 comments on commit 1c0abc8

Please sign in to comment.