use orig version of go ipp lib

This commit is contained in:
lconsuegra 2021-01-15 13:20:54 +01:00
parent 4b61efaff6
commit e6c278ad8f
4 changed files with 18 additions and 13 deletions

2
go.mod
View File

@ -5,7 +5,7 @@ go 1.13
require (
github.com/go-logr/logr v0.3.0
github.com/go-logr/zapr v0.3.0
github.com/phin1x/go-ipp v1.5.0
github.com/phin1x/go-ipp v1.2.1-0.20191226192803-6c9dee854ace
github.com/prometheus/client_golang v1.9.0
go.uber.org/multierr v1.6.0 // indirect
go.uber.org/zap v1.16.0

4
go.sum
View File

@ -204,8 +204,8 @@ github.com/pact-foundation/pact-go v1.0.4/go.mod h1:uExwJY4kCzNPcHRj+hCR/HBbOOIw
github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc=
github.com/pborman/uuid v1.2.0/go.mod h1:X/NO0urCmaxf9VXbdlT7C2Yzkj2IKimNn4k+gtPdI/k=
github.com/performancecopilot/speed v3.0.0+incompatible/go.mod h1:/CLtqpZ5gBg1M9iaPbIdPPGyKcA8hKdoy6hAWba7Yac=
github.com/phin1x/go-ipp v1.5.0 h1:3WLi0RLI3LbF93lHK7TBsK7h53u8tNXZNEokfFOurno=
github.com/phin1x/go-ipp v1.5.0/go.mod h1:GZwyNds6grdLi2xRBX22Cvt7Dh7ITWsML0bjrqBF5uo=
github.com/phin1x/go-ipp v1.2.1-0.20191226192803-6c9dee854ace h1:ELNodn+xPzMsqbwObNVFRt/OYlcCEw51IlRYdCtURcM=
github.com/phin1x/go-ipp v1.2.1-0.20191226192803-6c9dee854ace/go.mod h1:GZwyNds6grdLi2xRBX22Cvt7Dh7ITWsML0bjrqBF5uo=
github.com/pierrec/lz4 v1.0.2-0.20190131084431-473cd7ce01a1/go.mod h1:3/3N9NVKO0jef7pBehbT1qWhCMrIgbYNnFAZCqQ5LRc=
github.com/pierrec/lz4 v2.0.5+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY=
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=

View File

@ -7,7 +7,7 @@ import (
func (e *Exporter) jobsMetrics(ch chan<- prometheus.Metric) error {
printers, err := e.client.GetPrinters([]string{"printer-state"})
printers, err := e.client.GetPrinters([]string{})
if err != nil {
e.log.Error(err, "failed to fetch printers")
@ -16,15 +16,20 @@ func (e *Exporter) jobsMetrics(ch chan<- prometheus.Metric) error {
for _, attr := range printers {
printer := attr["printer-name"][0].Value.(string)
if len(attr["printer-name"]) == 1 {
jobs, err := e.client.GetJobs(printer, "", ipp.JobStateFilterAll, false, 0, 0, []string{})
if err != nil {
e.log.Error(err, "failed to fetch all jobs")
return err
printer := attr["printer-name"][0].Value.(string)
jobs, err := e.client.GetJobs(printer, "", ipp.JobStateFilterAll, false, 0, 0, []string{})
if err != nil {
e.log.Error(err, "failed to fetch all jobs")
return err
}
ch <- prometheus.MustNewConstMetric(e.jobsTotal, prometheus.CounterValue, float64(len(jobs)), printer)
} else {
e.log.Info("printer name attribute missing")
}
ch <- prometheus.MustNewConstMetric(e.jobsTotal, prometheus.CounterValue, float64(len(jobs)), printer)
}
return nil

View File

@ -18,12 +18,12 @@ func (e *Exporter) printerMetrics(ch chan<- prometheus.Metric) error {
printer := attr["printer-name"][0].Value.(string)
states := make(map[int8]int)
states := make(map[ipp.PrinterState]int)
states[ipp.PrinterStateIdle] = 0
states[ipp.PrinterStateProcessing] = 0
states[ipp.PrinterStateStopped] = 0
states[int8(attr["printer-state"][0].Value.(int))]++
states[ipp.PrinterState(attr["printer-state"][0].Value.(int))]++
ch <- prometheus.MustNewConstMetric(e.printerStateTotal, prometheus.GaugeValue, float64(states[ipp.PrinterStateIdle]), printer, "idle")
ch <- prometheus.MustNewConstMetric(e.printerStateTotal, prometheus.GaugeValue, float64(states[ipp.PrinterStateProcessing]), printer, "processing")