-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/dev' into dev
- Loading branch information
Showing
5 changed files
with
173 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package cmd | ||
|
||
import ( | ||
"github.com/inexio/thola/core/request" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func init() { | ||
addDeviceFlags(checkHardwareHealthCMD) | ||
checkCMD.AddCommand(checkHardwareHealthCMD) | ||
} | ||
|
||
var checkHardwareHealthCMD = &cobra.Command{ | ||
Use: "hardware-health", | ||
Short: "Check hardware-health of a device.", | ||
Long: "Check hardware-health of a device and return various performance data.", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
r := request.CheckHardwareHealthRequest{ | ||
CheckDeviceRequest: getCheckDeviceRequest(), | ||
} | ||
handleRequest(&r) | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package request | ||
|
||
// CheckHardwareHealthRequest | ||
// | ||
// CheckHardwareHealthRequest is a the request struct for the check sbc request. | ||
// | ||
// swagger:model | ||
type CheckHardwareHealthRequest struct { | ||
CheckDeviceRequest | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// +build !client | ||
|
||
package request | ||
|
||
import ( | ||
"context" | ||
"github.com/inexio/go-monitoringplugin" | ||
) | ||
|
||
func (r *CheckHardwareHealthRequest) process(ctx context.Context) (Response, error) { | ||
r.init() | ||
|
||
hhRequest := ReadHardwareHealthRequest{ReadRequest{r.BaseRequest}} | ||
response, err := hhRequest.process(ctx) | ||
if r.mon.UpdateStatusOnError(err, monitoringplugin.UNKNOWN, "error while processing read sbc request", true) { | ||
return &CheckResponse{r.mon.GetInfo()}, nil | ||
} | ||
res := response.(*ReadHardwareHealthResponse) | ||
|
||
if res.EnvironmentMonitorState != nil { | ||
err = r.mon.AddPerformanceDataPoint(monitoringplugin.NewPerformanceDataPoint("environment_monitor_state", *res.EnvironmentMonitorState, "")) | ||
if r.mon.UpdateStatusOnError(err, monitoringplugin.UNKNOWN, "error while adding performance data point", true) { | ||
r.mon.PrintPerformanceData(false) | ||
return &CheckResponse{r.mon.GetInfo()}, nil | ||
} | ||
|
||
// state 2 only works for oracle-acme sbs, this needs to be generalized once check hardware health is made for all device classes | ||
r.mon.UpdateStatusIf(*res.EnvironmentMonitorState != 2, monitoringplugin.CRITICAL, "environment monitor state is critical") | ||
} | ||
|
||
for _, fan := range res.Fans { | ||
if r.mon.UpdateStatusIf(fan.State == nil || fan.Description == nil, monitoringplugin.UNKNOWN, "description or state is missing for fan") { | ||
r.mon.PrintPerformanceData(false) | ||
return &CheckResponse{r.mon.GetInfo()}, nil | ||
} | ||
p := monitoringplugin.NewPerformanceDataPoint("fan_state", *fan.State, "").SetLabel(*fan.Description) | ||
err = r.mon.AddPerformanceDataPoint(p) | ||
if r.mon.UpdateStatusOnError(err, monitoringplugin.UNKNOWN, "error while adding performance data point", true) { | ||
r.mon.PrintPerformanceData(false) | ||
return &CheckResponse{r.mon.GetInfo()}, nil | ||
} | ||
} | ||
|
||
for _, powerSupply := range res.PowerSupply { | ||
if r.mon.UpdateStatusIf(powerSupply.State == nil || powerSupply.Description == nil, monitoringplugin.UNKNOWN, "description or state is missing for power supply") { | ||
r.mon.PrintPerformanceData(false) | ||
return &CheckResponse{r.mon.GetInfo()}, nil | ||
} | ||
p := monitoringplugin.NewPerformanceDataPoint("power_supply_state", *powerSupply.State, "").SetLabel(*powerSupply.Description) | ||
err = r.mon.AddPerformanceDataPoint(p) | ||
if r.mon.UpdateStatusOnError(err, monitoringplugin.UNKNOWN, "error while adding performance data point", true) { | ||
r.mon.PrintPerformanceData(false) | ||
return &CheckResponse{r.mon.GetInfo()}, nil | ||
} | ||
} | ||
|
||
return &CheckResponse{r.mon.GetInfo()}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters