Skip to content

Commit

Permalink
Merge branch 'release/0.3.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
Pandaoc-io committed Jun 26, 2020
2 parents 4165453 + 2d1c379 commit 273d796
Show file tree
Hide file tree
Showing 23 changed files with 147 additions and 106 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@
# vendor/

project.txt
output.html
26 changes: 19 additions & 7 deletions cmd/netintcheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ func networkInterfaceCheck(snmpVersion string, cmd *cobra.Command, args []string
ecflag, _ := cmd.Flags().GetString("error-critical")
ewflag, _ := cmd.Flags().GetString("error-warning")
//Bandwidth thresholds
bcflag, _ := cmd.Flags().GetFloat64("bandwidth-critical")
bwflag, _ := cmd.Flags().GetFloat64("bandwidth-warning")
bcflag, _ := cmd.Flags().GetString("bandwidth-critical")
bwflag, _ := cmd.Flags().GetString("bandwidth-warning")

//Check if Error/Dicard thresholds have the same type
if (strings.Contains(dcflag, "pps") && !strings.Contains(dwflag, "pps")) || (strings.Contains(dcflag, "%") && !strings.Contains(dwflag, "%")) {
Expand All @@ -55,6 +55,16 @@ func networkInterfaceCheck(snmpVersion string, cmd *cobra.Command, args []string
sknchk.Unknown("Error thresholds haven't the same type. See usage for more details.", "")
}

if !strings.Contains(bcflag, "%") || !strings.Contains(bwflag, "%") {
sknchk.Unknown("Bandwidth thresholds aren't of type %. See usage for more details.", "")
}

var bc float64
var bw float64

bc, _ = strconv.ParseFloat(strings.Split(bcflag, "%")[0], 64)
bw, _ = strconv.ParseFloat(strings.Split(bwflag, "%")[0], 64)

var ec float64
var ew float64
var ev string
Expand Down Expand Up @@ -163,13 +173,15 @@ func networkInterfaceCheck(snmpVersion string, cmd *cobra.Command, args []string

//Check if interface is admin down, in that no need to process other information.
if intNewData.IfAdminStatus != nil && *intNewData.IfAdminStatus == netint.DOWN {
sknchk.Critical(`The interface is administratively <span style="color: hsl(348, 86%%, 61%%);">DOWN</span>`, "")
sknchk.Critical(fmt.Sprintf("The interface is administratively %v",
sknchk.FmtCritical("DOWN")), "")
}
if intNewData.IfOperStatus != nil {
for _, st := range []uint{2, 3, 4, 5, 6, 7} {
if st == *intNewData.IfOperStatus {
operStStrg := netint.OperToString(st)
sknchk.Critical(fmt.Sprintf(`The interface status is <span style="color: hsl(348, 86%%, 61%%);">%v</span> (oper), <span style="color: hsl(348, 86%%, 61%%);">UP</span> (admin)`, operStStrg), "")
sknchk.Critical(fmt.Sprintf("The interface status is %v (oper), %v (admin)",
sknchk.FmtCritical(operStStrg), sknchk.FmtOk("UP")), "")
}
}
}
Expand Down Expand Up @@ -246,7 +258,7 @@ func networkInterfaceCheck(snmpVersion string, cmd *cobra.Command, args []string
//speed is also used for the creation of the bandwidtch perfdata. Need to be called before Bandwidth function
netint.Speed(intNewData, chk)

netint.Bandwidth(intNewData, intOldData, timeDiff, chk, bwflag, bcflag)
netint.Bandwidth(intNewData, intOldData, timeDiff, chk, bw, bc)

netint.Packets(intNewData, intOldData, timeDiff)

Expand Down Expand Up @@ -276,8 +288,8 @@ func networkInterfaceCheck(snmpVersion string, cmd *cobra.Command, args []string
} else {
var tableHTML string
thresholds := &ui.Thresholds{
Bw: bwflag,
Bc: bcflag,
Bw: bw,
Bc: bc,
Ewflag: ewflag,
Ecflag: ecflag,
Dwflag: dwflag,
Expand Down
4 changes: 2 additions & 2 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ func init() {
rootCmd.PersistentFlags().IntP("retry", "r", 3, "Number of retry of the SNMP requests")
rootCmd.PersistentFlags().BoolP("verbose", "v", false, "Activate the verbose mode to display more debuging information")

rootCmd.PersistentFlags().Float64("bandwidth-warning", 80, "Warning threshold of the Bandwidth usage (in %%)")
rootCmd.PersistentFlags().Float64("bandwidth-critical", 90, "Critical threshold of the Bandwidth usage (in %%)")
rootCmd.PersistentFlags().String("bandwidth-warning", "80%", "Warning threshold of the Bandwidth usage (in %%)")
rootCmd.PersistentFlags().String("bandwidth-critical", "90%", "Critical threshold of the Bandwidth usage (in %%)")

rootCmd.PersistentFlags().String("error-warning", "50pps", "Warning threshold of the Errors (in %% or pps)")
rootCmd.PersistentFlags().String("error-critical", "100pps", "Critical threshold of the Errors (in %% or pps)")
Expand Down
11 changes: 5 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,19 @@ 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.1
github.com/pandaoc-io/go-shinken-check v0.2.2
github.com/sirupsen/logrus v1.6.0
github.com/soniah/gosnmp v1.25.0
github.com/spf13/cobra v1.0.0
github.com/stretchr/objx v0.2.0 // indirect
github.com/stretchr/testify v1.6.1 // indirect
github.com/yuin/goldmark v1.1.32 // indirect
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 // indirect
golang.org/x/mod v0.3.0 // indirect
golang.org/x/net v0.0.0-20200602114024-627f9648deb9 // indirect
golang.org/x/sync v0.0.0-20200317015054-43a5402ce75a // indirect
golang.org/x/sys v0.0.0-20200622214017-ed371f2e16b4
golang.org/x/net v0.0.0-20200625001655-4c5254603344 // indirect
golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208 // indirect
golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae
golang.org/x/text v0.3.3 // indirect
golang.org/x/tools v0.0.0-20200622203043-20e05c1c8ffa // indirect
golang.org/x/tools v0.0.0-20200626171337-aa94e735be7f // indirect
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f // indirect
gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776 // indirect
rsc.io/sampler v1.99.99 // indirect
Expand Down
10 changes: 10 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ github.com/pandaoc-io/go-shinken-check v0.0.0-20200618195007-bd7cec54a6f0 h1:rQn
github.com/pandaoc-io/go-shinken-check v0.0.0-20200618195007-bd7cec54a6f0/go.mod h1:3Wn8r+Mixw3Hq+GD4wDMUcct6jwJj4IGxMtmSXRWZf0=
github.com/pandaoc-io/go-shinken-check v0.2.1 h1:h48poDqaAyq7JLw96RruyTg/LFRXttDQ9Wk1pxf/Oeo=
github.com/pandaoc-io/go-shinken-check v0.2.1/go.mod h1:3Wn8r+Mixw3Hq+GD4wDMUcct6jwJj4IGxMtmSXRWZf0=
github.com/pandaoc-io/go-shinken-check v0.2.2 h1:3e+11xHZZbFsgnc6sMZ26QB0bWCLuSx2xWzFV8oi0NY=
github.com/pandaoc-io/go-shinken-check v0.2.2/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=
Expand Down Expand Up @@ -140,13 +142,17 @@ golang.org/x/net v0.0.0-20190522155817-f3200d17e092/go.mod h1:HSz+uSET+XFnRR8LxR
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200602114024-627f9648deb9/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
golang.org/x/net v0.0.0-20200625001655-4c5254603344 h1:vGXIOMxbNfDTk/aXCmfdLgkrSV+Z2tcbze+pEc3v5W4=
golang.org/x/net v0.0.0-20200625001655-4c5254603344/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20200317015054-43a5402ce75a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208 h1:qwRHBd0NqMbJxfbotnDhm2ByMI1Shq4Y6oRJo21SGJA=
golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20181107165924-66b7b1311ac8/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
Expand All @@ -158,6 +164,8 @@ golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200622214017-ed371f2e16b4 h1:5/PjkGUjvEU5Gl6BxmvKRPpqo2uNMv4rcHBMwzk/st8=
golang.org/x/sys v0.0.0-20200622214017-ed371f2e16b4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae h1:Ih9Yo4hSPImZOpfGuA4bR/ORKTAbhZo2AbWNRCnevdo=
golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
Expand All @@ -169,6 +177,8 @@ golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3
golang.org/x/tools v0.0.0-20190425150028-36563e24a262/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20200622203043-20e05c1c8ffa/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
golang.org/x/tools v0.0.0-20200626171337-aa94e735be7f h1:JcoF/bowzCDI+MXu1yLqQGNO3ibqWsWq+Sk7pOT218w=
golang.org/x/tools v0.0.0-20200626171337-aa94e735be7f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
Expand Down
6 changes: 6 additions & 0 deletions netint/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,12 @@ func Bandwidth(intNewData *InterfaceDetails, intOldData *InterfaceDetails, timeD
log.Debug("No IfOutOctets counter available, skip...")
}
}

//Force 0% bandwidth usage for interfaces named vlanxxx
if strings.Contains(strings.ToLower(*intNewData.IfName), "vlan") || strings.Contains(strings.ToLower(*intNewData.IfDescr), "vlan") {
intNewData.IfInPrct = nil
intNewData.IfOutPrct = nil
}
if intNewData.IfInRate != nil {
//We suppress the UOM to be compatible with the Nagvis weathermap feature (value expressed in bps)
chk.AddPerfData("in", strconv.FormatFloat(*intNewData.IfInRate, 'f', 2, 64), "", 0, 0, 0, *intNewData.SpeedInbit)
Expand Down
Loading

0 comments on commit 273d796

Please sign in to comment.