2020-04-08 05:06:38 +02:00
|
|
|
package collector
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/prometheus/client_golang/prometheus"
|
|
|
|
log "github.com/sirupsen/logrus"
|
|
|
|
)
|
|
|
|
|
|
|
|
type firmwareCollector struct {
|
|
|
|
props []string
|
|
|
|
description *prometheus.Desc
|
|
|
|
}
|
|
|
|
|
|
|
|
func newFirmwareCollector() routerOSCollector {
|
|
|
|
c := &firmwareCollector{}
|
|
|
|
c.init()
|
|
|
|
return c
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *firmwareCollector) init() {
|
2020-12-08 19:31:12 +01:00
|
|
|
labelNames := []string{"devicename", "name", "disabled", "version", "build_time"}
|
2020-04-08 05:06:38 +02:00
|
|
|
c.description = description("system", "package", "system packages version", labelNames)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *firmwareCollector) describe(ch chan<- *prometheus.Desc) {
|
|
|
|
ch <- c.description
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *firmwareCollector) collect(ctx *collectorContext) error {
|
|
|
|
reply, err := ctx.client.Run("/system/package/getall")
|
|
|
|
if err != nil {
|
|
|
|
log.WithFields(log.Fields{
|
|
|
|
"device": ctx.device.Name,
|
|
|
|
"error": err,
|
|
|
|
})
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
pkgs := reply.Re
|
|
|
|
|
|
|
|
for _, pkg := range pkgs {
|
|
|
|
v := 1.0
|
2020-12-08 19:31:12 +01:00
|
|
|
if strings.EqualFold(pkg.Map["disabled"], "true") {
|
2020-04-08 05:06:38 +02:00
|
|
|
v = 0.0
|
|
|
|
}
|
2020-12-08 19:31:12 +01:00
|
|
|
ctx.ch <- prometheus.MustNewConstMetric(c.description, prometheus.GaugeValue, v, ctx.device.Name, pkg.Map["name"], pkg.Map["disabled"], pkg.Map["version"], pkg.Map["build-time"])
|
2020-04-08 05:06:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|