Skip to content

Commit 03f784f

Browse files
author
RincewindsHat
committed
Make linter happy
1 parent 7b032af commit 03f784f

File tree

3 files changed

+58
-56
lines changed

3 files changed

+58
-56
lines changed

perfdata/type.go

+20-18
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ package perfdata
22

33
import (
44
"errors"
5-
"fmt"
65
"math"
6+
"strconv"
77
"strings"
88

99
"github.com/NETWAYS/go-check"
@@ -19,24 +19,26 @@ var replacer = strings.NewReplacer("=", "_", "`", "_", "'", "_", "\"", "_")
1919
// represent a valid measurement, e.g INF for floats
2020
// This error can probably ignored in most cases and the perfdata point omitted,
2121
// 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) {
2323
switch value.kind {
2424
case floatType:
2525
if math.IsInf(value.floatVal, 0) {
26-
return "", errors.New("Perfdata value is inifinite")
26+
return "", errors.New("perfdata value is inifinite")
2727
}
2828

2929
if math.IsNaN(value.floatVal) {
30-
return "", errors.New("Perfdata value is inifinite")
30+
return "", errors.New("perfdata value is NaN")
3131
}
3232

3333
return check.FormatFloat(value.floatVal), nil
3434
case intType:
35-
return fmt.Sprintf("%d", value.intVal), nil
35+
return strconv.FormatInt(value.intVal, 10), nil
3636
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")
3840
default:
39-
return "", errors.New("This should not happen")
41+
return "", errors.New("this should not happen")
4042
}
4143
}
4244

@@ -53,13 +55,13 @@ func formatNumeric(value PerfdataValue) (string, error) {
5355
// https://icinga.com/docs/icinga-2/latest/doc/05-service-monitoring/#unit-of-measurement-uom
5456
type Perfdata struct {
5557
Label string
56-
Value PerfdataValue
58+
Value Value
5759
// Uom is the unit-of-measurement, see links above for details.
5860
Uom string
5961
Warn *check.Threshold
6062
Crit *check.Threshold
61-
Min PerfdataValue
62-
Max PerfdataValue
63+
Min Value
64+
Max Value
6365
}
6466

6567
type perfdataValueTypeEnum int
@@ -71,29 +73,29 @@ const (
7173
floatType
7274
)
7375

74-
type PerfdataValue struct {
76+
type Value struct {
7577
kind perfdataValueTypeEnum
7678
uintVal uint64
7779
intVal int64
7880
floatVal float64
7981
}
8082

81-
func NewPdvUint64(val uint64) PerfdataValue {
82-
return PerfdataValue{
83+
func NewPdvUint64(val uint64) Value {
84+
return Value{
8385
kind: uintType,
8486
uintVal: val,
8587
}
8688
}
8789

88-
func NewPdvInt64(val int64) PerfdataValue {
89-
return PerfdataValue{
90+
func NewPdvInt64(val int64) Value {
91+
return Value{
9092
kind: intType,
9193
intVal: val,
9294
}
9395
}
9496

95-
func NewPdvFloat64(val float64) PerfdataValue {
96-
return PerfdataValue{
97+
func NewPdvFloat64(val float64) Value {
98+
return Value{
9799
kind: floatType,
98100
floatVal: val,
99101
}
@@ -138,7 +140,7 @@ func (p Perfdata) ValidatedString() (string, error) {
138140
}
139141

140142
// Limits
141-
for _, value := range []PerfdataValue{p.Min, p.Max} {
143+
for _, value := range []Value{p.Min, p.Max} {
142144
sb.WriteString(";")
143145

144146
if value.kind != noneType {

perfdata/type_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ func TestRenderPerfdata(t *testing.T) {
104104

105105
type pfFormatTest struct {
106106
Result string
107-
InputValue PerfdataValue
107+
InputValue Value
108108
}
109109

110110
func TestFormatNumeric(t *testing.T) {

result/overall.go

+37-37
Original file line numberDiff line numberDiff line change
@@ -98,53 +98,53 @@ func (o *Overall) GetStatus() int {
9898
return check.Warning
9999
} else if o.oks > 0 {
100100
return check.OK
101-
} else {
102-
return check.Unknown
103-
}
104-
} else {
105-
// state not set explicitly!
106-
if len(o.PartialResults) == 0 {
107-
return check.Unknown
108101
}
109102

110-
var (
111-
criticals int
112-
warnings int
113-
oks int
114-
unknowns int
115-
)
103+
return check.Unknown
104+
}
116105

117-
for _, sc := range o.PartialResults {
118-
switch sc.GetStatus() {
119-
case check.Critical:
120-
criticals++
121-
case check.Warning:
122-
warnings++
123-
case check.Unknown:
124-
unknowns++
125-
case check.OK:
126-
oks++
127-
}
128-
}
106+
// state not set explicitly!
107+
if len(o.PartialResults) == 0 {
108+
return check.Unknown
109+
}
129110

130-
if criticals > 0 {
131-
return check.Critical
111+
var (
112+
criticals int
113+
warnings int
114+
oks int
115+
unknowns int
116+
)
117+
118+
for _, sc := range o.PartialResults {
119+
switch sc.GetStatus() {
120+
case check.Critical:
121+
criticals++
122+
case check.Warning:
123+
warnings++
124+
case check.Unknown:
125+
unknowns++
126+
case check.OK:
127+
oks++
132128
}
129+
}
133130

134-
if unknowns > 0 {
135-
return check.Unknown
136-
}
131+
if criticals > 0 {
132+
return check.Critical
133+
}
137134

138-
if warnings > 0 {
139-
return check.Warning
140-
}
135+
if unknowns > 0 {
136+
return check.Unknown
137+
}
141138

142-
if oks > 0 {
143-
return check.OK
144-
}
139+
if warnings > 0 {
140+
return check.Warning
141+
}
145142

146-
return check.Unknown
143+
if oks > 0 {
144+
return check.OK
147145
}
146+
147+
return check.Unknown
148148
}
149149

150150
// GetSummary returns a text representation of the current state of the Overall

0 commit comments

Comments
 (0)