diff --git a/go.mod b/go.mod index 0f562e0..c7573a4 100644 --- a/go.mod +++ b/go.mod @@ -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 ) diff --git a/wireless/parser.go b/wireless/parser.go index 3e05b44..c20bde0 100644 --- a/wireless/parser.go +++ b/wireless/parser.go @@ -8,7 +8,7 @@ import ( "github.com/slashdoom/aruba_exporter/rpc" "github.com/slashdoom/aruba_exporter/util" - + log "github.com/sirupsen/logrus" ) @@ -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 } @@ -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 = "" @@ -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 } @@ -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]) @@ -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") } diff --git a/wireless/wireless_collector.go b/wireless/wireless_collector.go index 44fb144..4781d52 100644 --- a/wireless/wireless_collector.go +++ b/wireless/wireless_collector.go @@ -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 @@ -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 { @@ -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...) @@ -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 ( @@ -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...) @@ -195,15 +215,15 @@ 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()) @@ -211,4 +231,4 @@ func (c *wirelessCollector) Collect(client *rpc.Client, ch chan<- prometheus.Met log.Debugf("radios: %+v", radios) return nil -} \ No newline at end of file +}