Skip to content
This repository was archived by the owner on Jan 22, 2024. It is now read-only.

Commit df2fc5d

Browse files
author
Michael Kraus
committed
add option for decimal digits of performance data float values
1 parent 1e27cb3 commit df2fc5d

File tree

7 files changed

+9
-5
lines changed

7 files changed

+9
-5
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ OK: No entries found|'count'=0;0;0 'problem_count'=0;0;0
4040
## Program help
4141
```
4242
Usage of ./nscrestc:
43+
-f int
44+
Round performance data float values to this number of digits
4345
-k Insecure mode - skip TLS verification.
4446
-p string
4547
NSClient++ webserver password.

build/darwin/amd64/nscrestc

0 Bytes
Binary file not shown.

build/linux/386/nscrestc

0 Bytes
Binary file not shown.

build/linux/amd64/nscrestc

0 Bytes
Binary file not shown.

build/windows/386/nscrestc.exe

0 Bytes
Binary file not shown.

build/windows/amd64/nscrestc.exe

0 Bytes
Binary file not shown.

nscrestc.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,14 @@ func main() {
9595
var flagTimeout int
9696
var flagVerbose bool
9797
var flagInsecure bool
98+
var flagFloatround int
9899

99100
flag.StringVar(&flagURL, "u", "", "NSCLient++ URL, for example https://10.1.2.3:8443.")
100101
flag.StringVar(&flagPassword, "p", "", "NSClient++ webserver password.")
101102
flag.IntVar(&flagTimeout, "t", 10, "Connection timeout in seconds, defaults to 10.")
102103
flag.BoolVar(&flagVerbose, "v", false, "Enable verbose output.")
103104
flag.BoolVar(&flagInsecure, "k", false, "Insecure mode - skip TLS verification.")
105+
flag.IntVar(&flagFloatround, "f", -1, "Round performance data float values to this number of digits.")
104106

105107
ReturncodeMap := map[string]int{
106108
"OK": 0,
@@ -232,24 +234,24 @@ func main() {
232234
// REFERENCE 'label'=value[UOM];[warn];[crit];[min];[max]
233235
if p.FloatValue != nil {
234236
if p.FloatValue.Value != nil {
235-
val = strconv.FormatFloat(*(p.FloatValue.Value), 'f', -1, 64)
237+
val = strconv.FormatFloat(*(p.FloatValue.Value), 'f', flagFloatround, 64)
236238
} else {
237239
continue
238240
}
239241
if p.FloatValue.Unit != nil {
240242
uni = (*(p.FloatValue.Unit))
241243
}
242244
if p.FloatValue.Warning != nil {
243-
war = strconv.FormatFloat(*(p.FloatValue.Warning), 'f', -1, 64)
245+
war = strconv.FormatFloat(*(p.FloatValue.Warning), 'f', flagFloatround, 64)
244246
}
245247
if p.FloatValue.Critical != nil {
246-
cri = strconv.FormatFloat(*(p.FloatValue.Critical), 'f', -1, 64)
248+
cri = strconv.FormatFloat(*(p.FloatValue.Critical), 'f', flagFloatround, 64)
247249
}
248250
if p.FloatValue.Minimum != nil {
249-
min = strconv.FormatFloat(*(p.FloatValue.Minimum), 'f', -1, 64)
251+
min = strconv.FormatFloat(*(p.FloatValue.Minimum), 'f', flagFloatround, 64)
250252
}
251253
if p.FloatValue.Maximum != nil {
252-
max = strconv.FormatFloat(*(p.FloatValue.Maximum), 'f', -1, 64)
254+
max = strconv.FormatFloat(*(p.FloatValue.Maximum), 'f', flagFloatround, 64)
253255
}
254256
}
255257
if p.IntValue != nil {

0 commit comments

Comments
 (0)