@@ -2,8 +2,8 @@ package perfdata
2
2
3
3
import (
4
4
"errors"
5
- "fmt"
6
5
"math"
6
+ "strconv"
7
7
"strings"
8
8
9
9
"github.com/NETWAYS/go-check"
@@ -19,24 +19,26 @@ var replacer = strings.NewReplacer("=", "_", "`", "_", "'", "_", "\"", "_")
19
19
// represent a valid measurement, e.g INF for floats
20
20
// This error can probably ignored in most cases and the perfdata point omitted,
21
21
// but silently dropping the value and returning the empty strings seems like bad style
22
- func formatNumeric (value PerfdataValue ) (string , error ) {
22
+ func formatNumeric (value Value ) (string , error ) {
23
23
switch value .kind {
24
24
case floatType :
25
25
if math .IsInf (value .floatVal , 0 ) {
26
- return "" , errors .New ("Perfdata value is inifinite" )
26
+ return "" , errors .New ("perfdata value is inifinite" )
27
27
}
28
28
29
29
if math .IsNaN (value .floatVal ) {
30
- return "" , errors .New ("Perfdata value is inifinite " )
30
+ return "" , errors .New ("perfdata value is NaN " )
31
31
}
32
32
33
33
return check .FormatFloat (value .floatVal ), nil
34
34
case intType :
35
- return fmt . Sprintf ( "%d" , value .intVal ), nil
35
+ return strconv . FormatInt ( value .intVal , 10 ), nil
36
36
case uintType :
37
- return fmt .Sprintf ("%d" , value .uintVal ), nil
37
+ return strconv .FormatUint (value .uintVal , 10 ), nil
38
+ case noneType :
39
+ return "" , errors .New ("value was not set" )
38
40
default :
39
- return "" , errors .New ("This should not happen" )
41
+ return "" , errors .New ("this should not happen" )
40
42
}
41
43
}
42
44
@@ -53,13 +55,13 @@ func formatNumeric(value PerfdataValue) (string, error) {
53
55
// https://icinga.com/docs/icinga-2/latest/doc/05-service-monitoring/#unit-of-measurement-uom
54
56
type Perfdata struct {
55
57
Label string
56
- Value PerfdataValue
58
+ Value Value
57
59
// Uom is the unit-of-measurement, see links above for details.
58
60
Uom string
59
61
Warn * check.Threshold
60
62
Crit * check.Threshold
61
- Min PerfdataValue
62
- Max PerfdataValue
63
+ Min Value
64
+ Max Value
63
65
}
64
66
65
67
type perfdataValueTypeEnum int
@@ -71,29 +73,29 @@ const (
71
73
floatType
72
74
)
73
75
74
- type PerfdataValue struct {
76
+ type Value struct {
75
77
kind perfdataValueTypeEnum
76
78
uintVal uint64
77
79
intVal int64
78
80
floatVal float64
79
81
}
80
82
81
- func NewPdvUint64 (val uint64 ) PerfdataValue {
82
- return PerfdataValue {
83
+ func NewPdvUint64 (val uint64 ) Value {
84
+ return Value {
83
85
kind : uintType ,
84
86
uintVal : val ,
85
87
}
86
88
}
87
89
88
- func NewPdvInt64 (val int64 ) PerfdataValue {
89
- return PerfdataValue {
90
+ func NewPdvInt64 (val int64 ) Value {
91
+ return Value {
90
92
kind : intType ,
91
93
intVal : val ,
92
94
}
93
95
}
94
96
95
- func NewPdvFloat64 (val float64 ) PerfdataValue {
96
- return PerfdataValue {
97
+ func NewPdvFloat64 (val float64 ) Value {
98
+ return Value {
97
99
kind : floatType ,
98
100
floatVal : val ,
99
101
}
@@ -138,7 +140,7 @@ func (p Perfdata) ValidatedString() (string, error) {
138
140
}
139
141
140
142
// Limits
141
- for _ , value := range []PerfdataValue {p .Min , p .Max } {
143
+ for _ , value := range []Value {p .Min , p .Max } {
142
144
sb .WriteString (";" )
143
145
144
146
if value .kind != noneType {
0 commit comments