From a96c9d88b7324e77f17e0bdfd20a556fb2632339 Mon Sep 17 00:00:00 2001 From: Kumi Date: Sun, 3 Sep 2023 09:19:56 +0200 Subject: [PATCH] Refactor printerMetrics function to use int instead of int8 for printer states - Replace int8 with int in the states map - Cast the printer state values to int when updating the states map - Update the metrics values to use int(ipp.PrinterState) with the corresponding state names as labels --- internal/printers.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/internal/printers.go b/internal/printers.go index 369b83e..2819516 100644 --- a/internal/printers.go +++ b/internal/printers.go @@ -12,20 +12,20 @@ func (e *Exporter) printerMetrics(ch chan<- prometheus.Metric) error { return err } - states := map[int8]int{ - ipp.PrinterStateIdle: 0, - ipp.PrinterStateProcessing: 0, - ipp.PrinterStateStopped: 0, + states := map[int]int{ + int(ipp.PrinterStateIdle): 0, + int(ipp.PrinterStateProcessing): 0, + int(ipp.PrinterStateStopped): 0, } for _, attr := range printers { - states[attr["printer-state"][0].Value.(int8)]++ + states[attr["printer-state"][0].Value.(int)]++ } ch <- prometheus.MustNewConstMetric(e.printersTotal, prometheus.GaugeValue, float64(len(printers))) - ch <- prometheus.MustNewConstMetric(e.printerStateTotal, prometheus.GaugeValue, float64(states[ipp.PrinterStateIdle]), "idle") - ch <- prometheus.MustNewConstMetric(e.printerStateTotal, prometheus.GaugeValue, float64(states[ipp.PrinterStateProcessing]), "processing") - ch <- prometheus.MustNewConstMetric(e.printerStateTotal, prometheus.GaugeValue, float64(states[ipp.PrinterStateStopped]), "stopped") + ch <- prometheus.MustNewConstMetric(e.printerStateTotal, prometheus.GaugeValue, float64(states[int(ipp.PrinterStateIdle)]), "idle") + ch <- prometheus.MustNewConstMetric(e.printerStateTotal, prometheus.GaugeValue, float64(states[int(ipp.PrinterStateProcessing)]), "processing") + ch <- prometheus.MustNewConstMetric(e.printerStateTotal, prometheus.GaugeValue, float64(states[int(ipp.PrinterStateStopped)]), "stopped") return nil }