diff --git a/.gitignore b/.gitignore
index 319051c..5220d1d 100644
--- a/.gitignore
+++ b/.gitignore
@@ -16,3 +16,5 @@
project.txt
output.html
+
+.vscode/
\ No newline at end of file
diff --git a/cmd/netintcheck.go b/cmd/netintcheck.go
index 8e37498..188c98e 100644
--- a/cmd/netintcheck.go
+++ b/cmd/netintcheck.go
@@ -172,9 +172,10 @@ func networkInterfaceCheck(snmpVersion string, cmd *cobra.Command, args []string
sknchk.Unknown(fmt.Sprint(err), "")
}
- //Check if interface is admin down, in that no need to process other information.
+ //Check if interface is admin down, in this case no need to process other information.
if intNewData.IfAdminStatus != nil && *intNewData.IfAdminStatus == netint.DOWN {
- sknchk.Critical(fmt.Sprintf("The interface is administratively %v",
+ //quit with Ok return Code, because the action have been made consciously
+ sknchk.Ok(fmt.Sprintf("The interface is administratively %v",
sknchk.FmtCritical("DOWN")), "")
}
if intNewData.IfOperStatus != nil {
diff --git a/cmd/version3.go b/cmd/version3.go
index 79ce155..bc2424d 100644
--- a/cmd/version3.go
+++ b/cmd/version3.go
@@ -36,10 +36,10 @@ func init() {
rootCmd.AddCommand(version3Cmd)
version3Cmd.Flags().StringP("username", "u", "admin", "Username used for SNMP v3 authentication.")
- version3Cmd.Flags().StringP("auth-protocol", "a", "SHA", "Authentication protocol (MD5|SHA|SHA-224|SHA-256|SHA-384|SHA-512).")
+ version3Cmd.Flags().StringP("auth-protocol", "a", "SHA", "Authentication protocol, can be in Upper or Lower case (MD5|SHA|SHA-224|SHA-256|SHA-384|SHA-512).")
version3Cmd.Flags().StringP("auth-passphrase", "A", "passphrase", "Authentication passphrase.")
version3Cmd.Flags().StringP("sec-level", "l", "authPriv", "Security level (noAuthNoPriv|authNoPriv|authPriv).")
version3Cmd.Flags().StringP("context", "n", "", "Context name.")
- version3Cmd.Flags().StringP("priv-protocol", "x", "AES", "Privacy protocol (DES|AES).")
+ version3Cmd.Flags().StringP("priv-protocol", "x", "AES", "Privacy protocol, can be in Upper or Lower case (DES|AES).")
version3Cmd.Flags().StringP("priv-passphrase", "X", "passphrase", "Privacy passphrase.")
}
diff --git a/convert/convert.go b/convert/convert.go
index 6117b22..075365f 100644
--- a/convert/convert.go
+++ b/convert/convert.go
@@ -20,41 +20,19 @@ along with this program. If not, see .
import (
"fmt"
- "strconv"
- "strings"
-)
-
-//Global value for B, KB, MB, GB and TB
-const (
- B = 1
- KB = B * 1000
- MB = KB * 1000
- GB = MB * 1000
- TB = GB * 1000
)
//HumanReadable convert float64 value to something more readable in K, M, G, T with a 2 points precision
-func HumanReadable(value float64, suffix string) string {
- unit := ""
-
- switch {
- case value >= TB:
- unit = "T"
- value = value / TB
- case value >= GB:
- unit = "G"
- value = value / GB
- case value >= MB:
- unit = "M"
- value = value / MB
- case value >= KB:
- unit = "K"
- value = value / KB
+func HumanReadable(value float64, base float64, suffix string) string {
+ if value < base {
+ return fmt.Sprintf("%.0f %v", value, suffix)
}
-
- result := strconv.FormatFloat(value, 'f', 2, 64)
- result = strings.TrimSuffix(result, ".0")
- return result + " " + unit + suffix
+ div, exp := base, 0
+ for n := value / base; n >= base; n /= base {
+ div *= base
+ exp++
+ }
+ return fmt.Sprintf("%.2f %c%v", float64(value)/float64(div), "kMGTPE"[exp], suffix)
}
//ToUint convert int and uint types to uint
diff --git a/file/file.go b/file/file.go
index 256b4a7..32e554e 100644
--- a/file/file.go
+++ b/file/file.go
@@ -34,7 +34,7 @@ import (
)
//CheckPath is the global path where all the files read/write by the check will be hosted
-const CheckPath = "/var/tmp/check_snmp_interface_foreach"
+const CheckPath = "/var/tmp/go_check_snmp_interface_foreach"
//DevicePath is the path where is will be stored all the JSON files of the device
var DevicePath string
@@ -99,7 +99,6 @@ func CreateJSONFile(devicePath string, filename string, datas interface{}) error
return fmt.Errorf("Can't create the file : %v", err)
}
return nil
-
}
//GenDeviceDirName will string the full path used to read/write the interface information
diff --git a/go.mod b/go.mod
index 68e32fb..ec36d97 100644
--- a/go.mod
+++ b/go.mod
@@ -6,7 +6,7 @@ require (
github.com/golang/mock v1.4.3 // indirect
github.com/mitchellh/mapstructure v1.3.2
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect
- github.com/pandaoc-io/go-shinken-check v0.2.3
+ github.com/pandaoc-io/go-shinken-check v0.3.1
github.com/sirupsen/logrus v1.6.0
github.com/soniah/gosnmp v1.25.0
github.com/spf13/cobra v1.0.0
diff --git a/go.sum b/go.sum
index 05910a9..95c853e 100644
--- a/go.sum
+++ b/go.sum
@@ -74,6 +74,10 @@ github.com/pandaoc-io/go-shinken-check v0.2.2 h1:3e+11xHZZbFsgnc6sMZ26QB0bWCLuSx
github.com/pandaoc-io/go-shinken-check v0.2.2/go.mod h1:3Wn8r+Mixw3Hq+GD4wDMUcct6jwJj4IGxMtmSXRWZf0=
github.com/pandaoc-io/go-shinken-check v0.2.3 h1:IEQI/VNRLQ1A8uF5aPytPoLMQp8ZOr0rz7VYuWlBJtc=
github.com/pandaoc-io/go-shinken-check v0.2.3/go.mod h1:3Wn8r+Mixw3Hq+GD4wDMUcct6jwJj4IGxMtmSXRWZf0=
+github.com/pandaoc-io/go-shinken-check v0.3.0 h1:sPYi+b4WyTVx1teX03+SekLAYppDmYvREH3gJbWXl48=
+github.com/pandaoc-io/go-shinken-check v0.3.0/go.mod h1:3Wn8r+Mixw3Hq+GD4wDMUcct6jwJj4IGxMtmSXRWZf0=
+github.com/pandaoc-io/go-shinken-check v0.3.1 h1:Nqg2JylLYBDOddq86tc3hrQ3Tispywc0IbtempGZmBY=
+github.com/pandaoc-io/go-shinken-check v0.3.1/go.mod h1:3Wn8r+Mixw3Hq+GD4wDMUcct6jwJj4IGxMtmSXRWZf0=
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
diff --git a/netint/handlers.go b/netint/handlers.go
index cb9078d..31e7edf 100644
--- a/netint/handlers.go
+++ b/netint/handlers.go
@@ -112,7 +112,7 @@ func FetchAllDatas(snmpConnection *g.GoSNMP, index string, version string, cmd *
if err != nil {
return nil, err
}
- if elem == "IfAlias" {
+ if elem == "IfAlias" && networkinterface.IfAlias != nil {
log.Debug("Replace the characters of the alias '|' by '!'")
*networkinterface.IfAlias = strings.ReplaceAll(*networkinterface.IfAlias, "|", "!")
}
@@ -207,7 +207,7 @@ func Bandwidth(intNewData *InterfaceDetails, intOldData *InterfaceDetails, timeD
}
//Force 0% bandwidth usage for interfaces named vlanxxx
- if strings.Contains(strings.ToLower(*intNewData.IfName), "vlan") || strings.Contains(strings.ToLower(*intNewData.IfDescr), "vlan") {
+ if (intNewData.IfName != nil && strings.Contains(strings.ToLower(*intNewData.IfName), "vlan")) || (intNewData.IfDescr != nil && strings.Contains(strings.ToLower(*intNewData.IfDescr), "vlan")) {
intNewData.IfInPrct = nil
intNewData.IfOutPrct = nil
}
@@ -229,13 +229,13 @@ func Bandwidth(intNewData *InterfaceDetails, intOldData *InterfaceDetails, timeD
if intNewData.IfInPrct != nil && *intNewData.IfInPrct > bc {
chk.AddShort(fmt.Sprintf(`Very high In Bandwidth : %v - %v (> %v%%)`,
- convert.HumanReadable(*intNewData.IfInRate, "bits/sec"),
+ convert.HumanReadable(*intNewData.IfInRate, 1024, "bits/sec"),
sknchk.FmtCritical(fmt.Sprintf("%.2f%%", *intNewData.IfInPrct)), bc),
true)
chk.AddCritical()
} else if intNewData.IfInPrct != nil && *intNewData.IfInPrct > bw {
chk.AddShort(fmt.Sprintf(`High In Bandwidth : %v - %v (> %v%%)`,
- convert.HumanReadable(*intNewData.IfInRate, "bits/sec"),
+ convert.HumanReadable(*intNewData.IfInRate, 1024, "bits/sec"),
sknchk.FmtWarning(fmt.Sprintf("%.2f%%", *intNewData.IfInPrct)), bw),
true)
chk.AddWarning()
@@ -243,13 +243,13 @@ func Bandwidth(intNewData *InterfaceDetails, intOldData *InterfaceDetails, timeD
if intNewData.IfOutPrct != nil && *intNewData.IfOutPrct > bc {
chk.AddShort(fmt.Sprintf(`Very high Out Bandwidth : %v - %v (> %v%%)`,
- convert.HumanReadable(*intNewData.IfOutRate, "bits/sec"),
+ convert.HumanReadable(*intNewData.IfOutRate, 1024, "bits/sec"),
sknchk.FmtCritical(fmt.Sprintf("%.2f%%", *intNewData.IfOutPrct)), bc),
true)
chk.AddCritical()
} else if intNewData.IfOutPrct != nil && *intNewData.IfOutPrct > bw {
chk.AddShort(fmt.Sprintf(`High Out Bandwidth : %v - %v (> %v%%)`,
- convert.HumanReadable(*intNewData.IfOutRate, "bits/sec"),
+ convert.HumanReadable(*intNewData.IfOutRate, 1024, "bits/sec"),
sknchk.FmtWarning(fmt.Sprintf("%.2f%%", *intNewData.IfOutPrct)), bw),
true)
chk.AddWarning()
@@ -544,17 +544,17 @@ func Errors(intNewData *InterfaceDetails, intOldData *InterfaceDetails, timeDiff
chk.AddPerfData("in_errors", strconv.FormatFloat(*intNewData.IfInErrorsRate, 'f', 2, 64), "pps", 0, 0, 0, 0)
}
- if intNewData.IfInErrorsPrct != nil {
+ /* if intNewData.IfInErrorsPrct != nil {
chk.AddPerfData("in_errors_prct", strconv.FormatFloat(*intNewData.IfInErrorsPrct, 'f', 2, 64), "%", 0, 0, 0, 0)
- }
+ } */
if intNewData.IfOutErrorsRate != nil {
chk.AddPerfData("out_errors", strconv.FormatFloat(*intNewData.IfOutErrorsRate, 'f', 2, 64), "pps", 0, 0, 0, 0)
}
- if intNewData.IfOutErrorsPrct != nil {
+ /* if intNewData.IfOutErrorsPrct != nil {
chk.AddPerfData("out_errors_prct", strconv.FormatFloat(*intNewData.IfOutErrorsPrct, 'f', 2, 64), "%", 0, 0, 0, 0)
- }
+ } */
//Error thresholds
if ev == "pps" {
@@ -640,17 +640,17 @@ func Discards(intNewData *InterfaceDetails, intOldData *InterfaceDetails, timeDi
chk.AddPerfData("in_discards", strconv.FormatFloat(*intNewData.IfInDiscardsRate, 'f', 2, 64), "pps", 0, 0, 0, 0)
}
- if intNewData.IfInDiscardsPrct != nil {
+ /* if intNewData.IfInDiscardsPrct != nil {
chk.AddPerfData("in_discards_prct", strconv.FormatFloat(*intNewData.IfInDiscardsPrct, 'f', 2, 64), "%", 0, 0, 0, 0)
- }
+ } */
if intNewData.IfOutDiscardsRate != nil {
chk.AddPerfData("out_discards", strconv.FormatFloat(*intNewData.IfOutDiscardsRate, 'f', 2, 64), "pps", 0, 0, 0, 0)
}
- if intNewData.IfOutDiscardsPrct != nil {
+ /* if intNewData.IfOutDiscardsPrct != nil {
chk.AddPerfData("out_discards_prct", strconv.FormatFloat(*intNewData.IfOutDiscardsPrct, 'f', 2, 64), "%", 0, 0, 0, 0)
- }
+ } */
if dv == "pps" {
if intNewData.IfInDiscardsRate != nil && *intNewData.IfInDiscardsRate > dc {
@@ -715,7 +715,15 @@ func Speed(intNewData *InterfaceDetails, chk *sknchk.Check) {
var speed uint
if intNewData.IfHighSpeed != nil {
log.Debug("ifHighSpeed found")
- speed = *intNewData.IfHighSpeed * 1000000
+ if *intNewData.IfHighSpeed == 1 {
+ log.Debug("ifHighSpeed is equal to 1Mb, we check if the ifSpeed is lower than 1Mb.")
+ if intNewData.IfSpeed != nil && *intNewData.IfSpeed < 1000000 {
+ log.Debugf("ifSpeed value is inferior to 1Mb, keep ifSpeed as speed value : %v bps", *intNewData.IfSpeed)
+ speed = *intNewData.IfSpeed
+ }
+ } else {
+ speed = *intNewData.IfHighSpeed * 1000000
+ }
} else if intNewData.IfSpeed != nil {
log.Debug("No ifHighSpeed found, switch to ifSpeed")
if *intNewData.IfSpeed == math.MaxUint32 {
@@ -797,7 +805,7 @@ func bwStats(newData interface{}, oldData interface{}, speed interface{}, elapse
rate = diffConverted * 8 / elapseTime.Seconds()
}
- log.Debugf("Rate : %v\n", convert.HumanReadable(rate, "bits/sec"))
+ log.Debugf("Rate : %v\n", convert.HumanReadable(rate, 1024, "bits/sec"))
speedConverted, err := convert.ToFloat(speed)
if err != nil {
@@ -807,7 +815,7 @@ func bwStats(newData interface{}, oldData interface{}, speed interface{}, elapse
if speedConverted > 0 {
prct = (rate / speedConverted) * 100
}
- log.Debugf("Max value : %v\n", convert.HumanReadable(speedConverted, "bps"))
+ log.Debugf("Max value : %v\n", convert.HumanReadable(speedConverted, 1000, "bps"))
log.Debugf("Percent : %.2f %%\n", prct)
//Now we test is the values are relevant
@@ -823,7 +831,7 @@ func bwStats(newData interface{}, oldData interface{}, speed interface{}, elapse
BwInconsistency = true
rate = 0
prct = 0
- log.Debugf("New Rate : %v\n", convert.HumanReadable(rate, "bits/sec"))
+ log.Debugf("New Rate : %v\n", convert.HumanReadable(rate, 1024, "bits/sec"))
log.Debugf("New Percent : %.2f %%\n", prct)
}
//For some link like bond we don't have any speed, generaly set to 0.
@@ -837,7 +845,7 @@ func bwStats(newData interface{}, oldData interface{}, speed interface{}, elapse
BwInconsistency = true
rate = 0
prct = 0
- log.Debugf("New Rate : %.2f\n", convert.HumanReadable(rate, "bits/sec"))
+ log.Debugf("New Rate : %.2f\n", convert.HumanReadable(rate, 1024, "bits/sec"))
log.Debugf("New Percent : %.2f %%\n", prct)
}
diff --git a/snmp/snmp.go b/snmp/snmp.go
index f83dd5d..548b30c 100644
--- a/snmp/snmp.go
+++ b/snmp/snmp.go
@@ -51,18 +51,18 @@ func CreateConnection(version string, cmd *cobra.Command) (*g.GoSNMP, error) {
var secLevel g.SnmpV3MsgFlags = g.AuthPriv
switch cmd.Flag("auth-protocol").Value.String() {
- case "MD5":
+ case "MD5", "md5":
authProto = g.MD5
- case "SHA":
+ case "SHA", "sha":
authProto = g.SHA
default:
return nil, fmt.Errorf("%v is not a valid authentication protocol, check usage", cmd.Flag("auth-protocol").Value.String())
}
switch cmd.Flag("priv-protocol").Value.String() {
- case "DES":
+ case "DES", "des":
privProto = g.DES
- case "AES":
+ case "AES", "aes":
privProto = g.AES
default:
return nil, fmt.Errorf("%v is not a valid privacy protocol, check usage", cmd.Flag("priv-protocol").Value.String())
diff --git a/ui/cli.go b/ui/cli.go
index 1909cc6..12581cf 100644
--- a/ui/cli.go
+++ b/ui/cli.go
@@ -24,7 +24,7 @@ func CliSummary(intNewData *netint.InterfaceDetails, chk *sknchk.Check) {
if intNewData.IfAlias != nil {
chk.AddShort(fmt.Sprintf("Alias : %v", *intNewData.IfAlias), true)
}
- chk.AddShort(fmt.Sprintf("Speed : %v", convert.HumanReadable(float64(*intNewData.SpeedInbit), "bps")), true)
+ chk.AddShort(fmt.Sprintf("Speed : %v", convert.HumanReadable(float64(*intNewData.SpeedInbit), 1000, "bps")), true)
if intNewData.IfOperStatus != nil {
if *intNewData.IfOperStatus == netint.UP {
chk.AddShort("Oper Status : UP", true)
@@ -49,34 +49,72 @@ func CliSummary(intNewData *netint.InterfaceDetails, chk *sknchk.Check) {
chk.AddShort(fmt.Sprintf("Total pkts In : %.2f pps", *intNewData.IfInTotalPktsRate), true)
chk.AddShort(fmt.Sprintf("Total pkts Out : %.2f pps", *intNewData.IfOutTotalPktsRate), true)
- if intNewData.InUniPcktRate != nil || intNewData.InMultiPcktRate != nil {
- if intNewData.InBroadPcktRate != nil {
- chk.AddShort(fmt.Sprintf("In : Uni : %.2f pps, Multi : %.2f pps, Broad :%.2f pps", *intNewData.InUniPcktRate, *intNewData.InMultiPcktRate, *intNewData.InBroadPcktRate), true)
- } else {
- chk.AddShort(fmt.Sprintf("In : Uni : %.2f pps, Multi/Broad : %.2f pps", *intNewData.InUniPcktRate, *intNewData.InMultiPcktRate), true)
- }
+ if intNewData.InUniPcktRate != nil {
+ chk.AddShort(fmt.Sprintf("In Uni : %.2f pps", *intNewData.InUniPcktRate), true)
} else {
- chk.AddShort("In Uni/Multi/Broadcast packets : Can't be determined", true)
+ chk.AddShort("In Uni : Can't be determined", true)
}
- if intNewData.OutUniPcktRate != nil || intNewData.OutMultiPcktRate != nil {
- if intNewData.OutBroadPcktRate != nil {
- chk.AddShort(fmt.Sprintf("Out : Uni : %.2f pps, Multi : %.2f pps, Broad :%.2f pps", *intNewData.OutUniPcktRate, *intNewData.OutMultiPcktRate, *intNewData.OutBroadPcktRate), true)
- } else {
- chk.AddShort(fmt.Sprintf("Out : Uni : %.2f pps, Multi/Broad : %.2f pps", *intNewData.OutUniPcktRate, *intNewData.OutMultiPcktRate), true)
- }
+
+ if intNewData.InMultiPcktRate != nil {
+ chk.AddShort(fmt.Sprintf("In : Multi : %.2f pps", *intNewData.InMultiPcktRate), true)
+ } else {
+ chk.AddShort("In Multi : Can't be determined", true)
+ }
+
+ if intNewData.InBroadPcktRate != nil {
+ chk.AddShort(fmt.Sprintf("In Broad : %.2f pps", *intNewData.InBroadPcktRate), true)
+ } else {
+ chk.AddShort("In Broad : Can't be determined", true)
+ }
+
+ if intNewData.OutUniPcktRate != nil {
+ chk.AddShort(fmt.Sprintf("Out Uni : %.2f pps", *intNewData.OutUniPcktRate), true)
+ } else {
+ chk.AddShort("Out Uni : Can't be determined", true)
+ }
+
+ if intNewData.OutMultiPcktRate != nil {
+ chk.AddShort(fmt.Sprintf("Out Multi : %.2f pps", *intNewData.OutMultiPcktRate), true)
+ } else {
+ chk.AddShort("Out Multi : Can't be determined", true)
+ }
+
+ if intNewData.OutBroadPcktRate != nil {
+ chk.AddShort(fmt.Sprintf("Out Broad : %.2f pps", *intNewData.OutBroadPcktRate), true)
} else {
- chk.AddShort("Out Uni/Multi/Broadcast packets : Can't be determined", true)
+ chk.AddShort("Out Broad : Can't be determined", true)
}
+
+ var inRateStr string
if intNewData.IfInRate != nil {
- chk.AddShort(fmt.Sprintf("In BW : %v (%.2f%%)", convert.HumanReadable(*intNewData.IfInRate, "bits/sec"), *intNewData.IfInPrct), true)
+ inRateStr = fmt.Sprintf("In BW : %v", convert.HumanReadable(*intNewData.IfInRate, 1024, "bits/sec"))
+ } else {
+ inRateStr = "In BW : Rate can't be determined"
+ }
+ var inPrctStr string
+ if intNewData.IfInPrct != nil {
+ inPrctStr = fmt.Sprintf(" (%.2f%%)", *intNewData.IfInPrct)
} else {
- chk.AddShort("In BW : Can't be determined", true)
+ inPrctStr = ", Percentage can't be determined"
}
+
+ chk.AddShort(inRateStr+inPrctStr, true)
+
+ var outRateStr string
if intNewData.IfOutRate != nil {
- chk.AddShort(fmt.Sprintf("Out BW : %v (%.2f%%)", convert.HumanReadable(*intNewData.IfOutRate, "bits/sec"), *intNewData.IfOutPrct), true)
+ outRateStr = fmt.Sprintf("Out BW : %v", convert.HumanReadable(*intNewData.IfOutRate, 1024, "bits/sec"))
+ } else {
+ outRateStr = "Out BW : Rate can't be determined"
+ }
+ var outPrctStr string
+ if intNewData.IfOutPrct != nil {
+ outPrctStr = fmt.Sprintf(" (%.2f%%)", *intNewData.IfOutPrct)
} else {
- chk.AddShort("Out BW : Can't be determined", true)
+ outPrctStr = ", Percentage can't be determined"
}
+
+ chk.AddShort(outRateStr+outPrctStr, true)
+
if intNewData.IfInErrorsRate != nil {
if intNewData.LocIfInCRCRate != nil {
chk.AddShort(fmt.Sprintf("In Errors : %.2f pps (%.2f%%) with %.2f pps CRC Errors", *intNewData.IfInErrorsRate, *intNewData.IfInErrorsPrct, *intNewData.LocIfInCRCRate), true)
diff --git a/ui/html.go b/ui/html.go
index e5686f5..9cdeca1 100644
--- a/ui/html.go
+++ b/ui/html.go
@@ -22,6 +22,7 @@ import (
"bytes"
"fmt"
"html/template"
+ "regexp"
"strings"
"go-check-network-interface/convert"
@@ -30,13 +31,13 @@ import (
//TableTmpl is the HTML code to generate the table into the long output
const TableTmpl = `
-
+
Name : {{if .IfName}}{{.IfName}}{{else}}No name found{{end}} - Desc : {{if .IfDescr}}{{.IfDescr}}{{else}}No description found{{end}} |
- Alias : {{if .IfAlias}}{{if eq (len .IfAlias) 0 }}Alias is empty{{else}}{{.IfAlias}}{{end}}{{else}}No alias found{{end}} |
+ Alias : {{if .IfAlias}}{{if eq (len .IfAlias) 0 }}Alias is empty{{else}}{{.IfAlias}}{{end}}{{else}}No alias found{{end}}{{if IsCritical}} ☢ Critical interface detected ☢{{end}} |
Oper Status |
@@ -77,24 +78,24 @@ const TableTmpl = `
Usage Critical threshold |
- {{if .IfInPrct -}}
+ {{if .IfInRate -}}
{{if eq (CompPnF .IfInPrct BwCritThreshold) 1 -}}
- {{if .IfInRate}}{{HumanBps .IfInRate}}{{end}} ⬌ {{Float2f .IfInPrct}} % |
+ {{if .IfInRate}}{{HumanBps .IfInRate}}{{end}}{{if .IfInPrct}} ⬌ {{Float2f .IfInPrct}} %{{end}} |
{{else if eq (CompPnF .IfInPrct BwWarnThreshold) 1 -}}
- {{if .IfInRate}}{{HumanBps .IfInRate}}{{end}} ⬌ {{Float2f .IfInPrct}} % |
+ {{if .IfInRate}}{{HumanBps .IfInRate}}{{end}}{{if .IfInPrct}} ⬌ {{Float2f .IfInPrct}} %{{end}} |
{{else -}}
- {{if .IfInRate}}{{HumanBps .IfInRate}}{{end}} ⬌ {{Float2f .IfInPrct}} % |
+ {{if .IfInRate}}{{HumanBps .IfInRate}}{{end}}{{if .IfInPrct}} ⬌ {{Float2f .IfInPrct}} %{{end}} |
{{end -}}
{{else -}}
N/A |
{{end -}}
- {{if .IfOutPrct -}}
+ {{if .IfOutRate -}}
{{if eq (CompPnF .IfOutPrct BwCritThreshold) 1 -}}
- {{if .IfOutRate}}{{HumanBps .IfOutRate}}{{end}} ⬌ {{Float2f .IfOutPrct}} % |
+ {{if .IfOutRate}}{{HumanBps .IfOutRate}}{{end}}{{if .IfOutPrct}} ⬌ {{Float2f .IfOutPrct}} %{{end}} |
{{else if eq (CompPnF .IfOutPrct BwWarnThreshold) 1 -}}
- {{if .IfOutRate}}{{HumanBps .IfOutRate}}{{end}} ⬌ {{Float2f .IfOutPrct}} % |
+ {{if .IfOutRate}}{{HumanBps .IfOutRate}}{{end}}{{if .IfOutPrct}} ⬌ {{Float2f .IfOutPrct}} %{{end}} |
{{else -}}
- {{if .IfOutRate}}{{HumanBps .IfOutRate}}{{end}} ⬌ {{Float2f .IfOutPrct}} % |
+ {{if .IfOutRate}}{{HumanBps .IfOutRate}}{{end}}{{if .IfOutPrct}} ⬌ {{Float2f .IfOutPrct}} %{{end}} |
{{end -}}
{{else -}}
N/A |
@@ -238,8 +239,15 @@ func GenerateHTMLTable(intNewData *netint.InterfaceDetails, threshold *Threshold
}
return "N/A"
},
- "HumanBps": func(f float64) string { return convert.HumanReadable(f, "bits/sec") },
- "HumanSpeed": func() string { return convert.HumanReadable(float64(*intNewData.SpeedInbit), "bps") },
+ "IsCritical": func() bool {
+ re := regexp.MustCompile(`(<>|->|<*>|< >)`)
+ if intNewData.IfAlias == nil {
+ return false
+ }
+ return re.Match([]byte(*intNewData.IfAlias))
+ },
+ "HumanBps": func(f float64) string { return convert.HumanReadable(f, 1024, "bits/sec") },
+ "HumanSpeed": func() string { return convert.HumanReadable(float64(*intNewData.SpeedInbit), 1000, "bps") },
"BwCritThreshold": func() float64 { return threshold.Bc },
"BwWarnThreshold": func() float64 { return threshold.Bw },
"ErrCritThreshold": func() float64 { return threshold.Ec },
@@ -259,6 +267,9 @@ func GenerateHTMLTable(intNewData *netint.InterfaceDetails, threshold *Threshold
return "%"
},
"CompPnF": func(f1 *float64, f2 float64) int {
+ if f1 == nil {
+ return -1
+ }
if *f1 > f2 {
return 1
} else if *f1 == f2 {
diff --git a/vendor/github.com/pandaoc-io/go-shinken-check/check.go b/vendor/github.com/pandaoc-io/go-shinken-check/check.go
index 8b2db10..b394662 100644
--- a/vendor/github.com/pandaoc-io/go-shinken-check/check.go
+++ b/vendor/github.com/pandaoc-io/go-shinken-check/check.go
@@ -84,7 +84,7 @@ func (o *OutputMode) Mode() string {
func (o *OutputMode) SetHTML() {
Output.mode = "html"
Output.newLine = "
"
- Output.bullet = "• "
+ Output.bullet = " • "
Output.classOk = "color: #28a745!important;"
Output.classWarning = "color: #947600!important;"
Output.classCritical = "color: #dc3545!important;"
@@ -213,6 +213,11 @@ func Unknown(short string, long string) {
Exit(check)
}
+//ForceRc will force the return code of the check to the one given in argument
+func (c *Check) ForceRc(rc Status) {
+ c.rc = []Status{rc}
+}
+
//Rc return the Return Code of the check
func (c *Check) Rc() Status {
var maxRc Status
diff --git a/vendor/modules.txt b/vendor/modules.txt
index feced6f..b779b0d 100644
--- a/vendor/modules.txt
+++ b/vendor/modules.txt
@@ -4,7 +4,7 @@ github.com/inconshreveable/mousetrap
github.com/konsorten/go-windows-terminal-sequences
# github.com/mitchellh/mapstructure v1.3.2
github.com/mitchellh/mapstructure
-# github.com/pandaoc-io/go-shinken-check v0.2.3
+# github.com/pandaoc-io/go-shinken-check v0.3.1
github.com/pandaoc-io/go-shinken-check
# github.com/sirupsen/logrus v1.6.0
github.com/sirupsen/logrus