Skip to content

Commit

Permalink
Added thresholds to check server
Browse files Browse the repository at this point in the history
  • Loading branch information
toberd committed Mar 19, 2021
1 parent 9adc4dc commit 2b08ca2
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 61 deletions.
7 changes: 7 additions & 0 deletions cmd/check_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ import (
func init() {
addDeviceFlags(checkServerCMD)
checkCMD.AddCommand(checkServerCMD)

checkServerCMD.Flags().Float64("procs-warning", 0, "warning threshold for procs count")
checkServerCMD.Flags().Float64("procs-critical", 0, "critical threshold for procs count")
checkServerCMD.Flags().Float64("users-warning", 0, "warning threshold for users count")
checkServerCMD.Flags().Float64("users-critical", 0, "critical threshold for users count")
}

var checkServerCMD = &cobra.Command{
Expand All @@ -18,6 +23,8 @@ var checkServerCMD = &cobra.Command{
Run: func(cmd *cobra.Command, args []string) {
r := request.CheckServerRequest{
CheckDeviceRequest: getCheckDeviceRequest(args[0]),
UsersThreshold: generateCheckThresholds(cmd, "", "users-warning", "", "users-critical", true),
ProcsThreshold: generateCheckThresholds(cmd, "", "procs-warning", "", "procs-critical", true),
}
handleRequest(&r)
},
Expand Down
10 changes: 8 additions & 2 deletions core/request/check_server_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,18 @@ import (
// swagger:model
type CheckServerRequest struct {
CheckDeviceRequest
ServerThresholds monitoringplugin.Thresholds `json:"serverThresholds" xml:"serverThresholds"`
UsersThreshold monitoringplugin.Thresholds `json:"usersThreshold" xml:"usersThreshold"`
ProcsThreshold monitoringplugin.Thresholds `json:"procsThreshold" xml:"procsThreshold"`
}

func (r *CheckServerRequest) validate(ctx context.Context) error {
if err := r.ServerThresholds.Validate(); err != nil {
if err := r.UsersThreshold.Validate(); err != nil {
return err
}

if err := r.ProcsThreshold.Validate(); err != nil {
return err
}

return r.CheckDeviceRequest.validate(ctx)
}
4 changes: 2 additions & 2 deletions core/request/check_server_request_process.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ func (r *CheckServerRequest) process(ctx context.Context) (Response, error) {
server := response.(*ReadServerResponse)

if server.Server.Procs != nil {
err = r.mon.AddPerformanceDataPoint(monitoringplugin.NewPerformanceDataPoint("procs", *server.Server.Procs))
err = r.mon.AddPerformanceDataPoint(monitoringplugin.NewPerformanceDataPoint("procs", *server.Server.Procs).SetThresholds(r.ProcsThreshold))
if r.mon.UpdateStatusOnError(err, monitoringplugin.UNKNOWN, "error while adding performance data point", true) {
r.mon.PrintPerformanceData(false)
return &CheckResponse{r.mon.GetInfo()}, nil
}
}
if server.Server.Users != nil {
err = r.mon.AddPerformanceDataPoint(monitoringplugin.NewPerformanceDataPoint("users", *server.Server.Users))
err = r.mon.AddPerformanceDataPoint(monitoringplugin.NewPerformanceDataPoint("users", *server.Server.Users).SetThresholds(r.UsersThreshold))
if r.mon.UpdateStatusOnError(err, monitoringplugin.UNKNOWN, "error while adding performance data point", true) {
r.mon.PrintPerformanceData(false)
return &CheckResponse{r.mon.GetInfo()}, nil
Expand Down
131 changes: 74 additions & 57 deletions doc/api_doc.json
Original file line number Diff line number Diff line change
Expand Up @@ -1001,7 +1001,7 @@
"title": "CheckCPULoadRequest",
"properties": {
"cpuLoadThresholds": {
"$ref": "#/definitions/CheckThresholds"
"$ref": "#/definitions/Thresholds"
},
"device_data": {
"$ref": "#/definitions/DeviceData"
Expand Down Expand Up @@ -1057,7 +1057,7 @@
"$ref": "#/definitions/DeviceData"
},
"diskThresholds": {
"$ref": "#/definitions/CheckThresholds"
"$ref": "#/definitions/Thresholds"
},
"json_metrics": {
"type": "boolean",
Expand Down Expand Up @@ -1209,7 +1209,7 @@
"x-go-name": "JSONMetrics"
},
"memoryUsageThresholds": {
"$ref": "#/definitions/CheckThresholds"
"$ref": "#/definitions/Thresholds"
},
"print_performance_data": {
"type": "boolean",
Expand Down Expand Up @@ -1255,7 +1255,7 @@
"performance_data": {
"type": "array",
"items": {
"$ref": "#/definitions/PerformanceDataPointInfo"
"$ref": "#/definitions/PerformanceDataPoint"
},
"x-go-name": "PerformanceData"
},
Expand All @@ -1277,7 +1277,7 @@
"title": "CheckSBCRequest",
"properties": {
"SystemHealthScoreThresholds": {
"$ref": "#/definitions/CheckThresholds"
"$ref": "#/definitions/Thresholds"
},
"device_data": {
"$ref": "#/definitions/DeviceData"
Expand Down Expand Up @@ -1340,14 +1340,17 @@
"type": "boolean",
"x-go-name": "PrintPerformanceData"
},
"serverThresholds": {
"$ref": "#/definitions/CheckThresholds"
"procsThreshold": {
"$ref": "#/definitions/Thresholds"
},
"timeout": {
"description": "Timeout for the request (0 =\u003e no timeout)",
"type": "integer",
"format": "int64",
"x-go-name": "Timeout"
},
"usersThreshold": {
"$ref": "#/definitions/Thresholds"
}
},
"x-go-package": "github.com/inexio/thola/core/request"
Expand All @@ -1373,45 +1376,19 @@
},
"x-go-package": "github.com/inexio/thola/core/request"
},
"CheckThresholds": {
"type": "object",
"properties": {
"criticalMax": {
"type": "number",
"format": "double",
"x-go-name": "CriticalMax"
},
"criticalMin": {
"type": "number",
"format": "double",
"x-go-name": "CriticalMin"
},
"warningMax": {
"type": "number",
"format": "double",
"x-go-name": "WarningMax"
},
"warningMin": {
"type": "number",
"format": "double",
"x-go-name": "WarningMin"
}
},
"x-go-package": "github.com/inexio/thola/core/request"
},
"CheckUPSRequest": {
"description": "CheckUPSRequest is a the request struct for the check ups request.",
"type": "object",
"title": "CheckUPSRequest",
"properties": {
"batteryCurrentThresholds": {
"$ref": "#/definitions/CheckThresholds"
"$ref": "#/definitions/Thresholds"
},
"batteryTemperatureThresholds": {
"$ref": "#/definitions/CheckThresholds"
"$ref": "#/definitions/Thresholds"
},
"currentLoadThresholds": {
"$ref": "#/definitions/CheckThresholds"
"$ref": "#/definitions/Thresholds"
},
"device_data": {
"$ref": "#/definitions/DeviceData"
Expand All @@ -1425,10 +1402,10 @@
"x-go-name": "PrintPerformanceData"
},
"rectifierCurrentThresholds": {
"$ref": "#/definitions/CheckThresholds"
"$ref": "#/definitions/Thresholds"
},
"systemVoltageThresholds": {
"$ref": "#/definitions/CheckThresholds"
"$ref": "#/definitions/Thresholds"
},
"timeout": {
"description": "Timeout for the request (0 =\u003e no timeout)",
Expand Down Expand Up @@ -1458,15 +1435,32 @@
"type": "object",
"title": "DWDMInterface",
"properties": {
"rx_level": {
"channels": {
"type": "array",
"items": {
"$ref": "#/definitions/OpticalChannel"
},
"x-go-name": "Channels"
},
"rx_power": {
"type": "number",
"format": "double",
"x-go-name": "RXLevel"
"x-go-name": "RXPower"
},
"tx_level": {
"rx_power_100_g": {
"type": "number",
"format": "double",
"x-go-name": "TXLevel"
"x-go-name": "RXPower100G"
},
"tx_power": {
"type": "number",
"format": "double",
"x-go-name": "TXPower"
},
"tx_power_100_g": {
"type": "number",
"format": "double",
"x-go-name": "TXPower100G"
}
},
"x-go-package": "github.com/inexio/thola/core/device"
Expand Down Expand Up @@ -1991,10 +1985,10 @@
},
"x-go-package": "github.com/inexio/thola/core/device"
},
"OpticalOPMChannel": {
"description": "OpticalOPMChannel represents an optical opm channel of an optical opm interface.",
"OpticalChannel": {
"description": "OpticalChannel represents an optical channel.",
"type": "object",
"title": "OpticalOPMChannel",
"title": "OpticalChannel",
"properties": {
"channel": {
"type": "string",
Expand All @@ -2004,6 +1998,11 @@
"type": "number",
"format": "double",
"x-go-name": "RXPower"
},
"tx_power": {
"type": "number",
"format": "double",
"x-go-name": "TXPower"
}
},
"x-go-package": "github.com/inexio/thola/core/device"
Expand All @@ -2016,7 +2015,7 @@
"channels": {
"type": "array",
"items": {
"$ref": "#/definitions/OpticalOPMChannel"
"$ref": "#/definitions/OpticalChannel"
},
"x-go-name": "Channels"
},
Expand Down Expand Up @@ -2100,14 +2099,10 @@
},
"x-go-package": "github.com/inexio/go-monitoringplugin"
},
"PerformanceDataPointInfo": {
"description": "PerformanceDataPointInfo has all information to one performance data point as exported variables. It is returned by\nPerformanceDataPoint.GetInfo()",
"PerformanceDataPoint": {
"type": "object",
"title": "PerformanceDataPoint contains all information of one PerformanceDataPoint.",
"properties": {
"crit": {
"type": "object",
"x-go-name": "Crit"
},
"label": {
"type": "string",
"x-go-name": "Label"
Expand All @@ -2124,17 +2119,16 @@
"type": "object",
"x-go-name": "Min"
},
"thresholds": {
"$ref": "#/definitions/Thresholds"
},
"unit": {
"type": "string",
"x-go-name": "Unit"
},
"value": {
"type": "object",
"x-go-name": "Value"
},
"warn": {
"type": "object",
"x-go-name": "Warn"
}
},
"x-go-package": "github.com/inexio/go-monitoringplugin"
Expand Down Expand Up @@ -2555,7 +2549,7 @@
"performance_data": {
"type": "array",
"items": {
"$ref": "#/definitions/PerformanceDataPointInfo"
"$ref": "#/definitions/PerformanceDataPoint"
},
"x-go-name": "PerformanceData"
},
Expand Down Expand Up @@ -2797,6 +2791,29 @@
"title": "Status represents an interface status.",
"x-go-package": "github.com/inexio/thola/core/device"
},
"Thresholds": {
"description": "Thresholds contains all threshold values",
"type": "object",
"properties": {
"criticalMax": {
"type": "object",
"x-go-name": "CriticalMax"
},
"criticalMin": {
"type": "object",
"x-go-name": "CriticalMin"
},
"warningMax": {
"type": "object",
"x-go-name": "WarningMax"
},
"warningMin": {
"type": "object",
"x-go-name": "WarningMin"
}
},
"x-go-package": "github.com/inexio/go-monitoringplugin"
},
"UPSComponent": {
"description": "UPSComponent represents a UPS component.",
"type": "object",
Expand Down

0 comments on commit 2b08ca2

Please sign in to comment.