mirror of
https://github.com/nshttpd/mikrotik-exporter.git
synced 2024-11-18 10:45:12 +01:00
72ec3c2ce0
collect packages/firmware versions and export them as labels for gauge under : mikrotik_system_package * updated versions of dependent libs * fetch firmware version as gauge * fixed the things that needed to be fixed
52 lines
1.1 KiB
Go
52 lines
1.1 KiB
Go
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() {
|
|
labelNames := []string{"name", "disabled", "version", "build_time"}
|
|
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
|
|
if strings.Compare(pkg.Map["disabled"], "true") == 0 {
|
|
v = 0.0
|
|
}
|
|
ctx.ch <- prometheus.MustNewConstMetric(c.description, prometheus.GaugeValue, v, pkg.Map["name"], pkg.Map["disabled"], pkg.Map["version"], pkg.Map["build-time"])
|
|
}
|
|
|
|
return nil
|
|
}
|