Skip to content

Commit

Permalink
Added warning and critical to disk check
Browse files Browse the repository at this point in the history
  • Loading branch information
toberd committed Mar 8, 2021
1 parent 32e4623 commit 21d8a4d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
4 changes: 4 additions & 0 deletions cmd/check_disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import (
func init() {
addDeviceFlags(checkDiskCMD)
checkCMD.AddCommand(checkDiskCMD)

checkDiskCMD.Flags().Float64("warning", 0, "warning threshold for free disk space")
checkDiskCMD.Flags().Float64("critical", 0, "critical threshold for free disk space")
}

var checkDiskCMD = &cobra.Command{
Expand All @@ -18,6 +21,7 @@ var checkDiskCMD = &cobra.Command{
Run: func(cmd *cobra.Command, args []string) {
r := request.CheckDiskRequest{
CheckDeviceRequest: getCheckDeviceRequest(args[0]),
DiskThresholds: generateCheckThresholds(cmd, "warning", "", "critical", ""),
}
handleRequest(&r)
},
Expand Down
2 changes: 1 addition & 1 deletion cmd/check_memory_usage.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ func init() {
checkCMD.AddCommand(checkMemoryUsage)

checkMemoryUsage.Flags().Float64("warning", 0, "warning threshold for memory usage")
checkMemoryUsage.Flags().Float64("critical", 0, "critical threshold for system voltage")
checkMemoryUsage.Flags().Float64("critical", 0, "critical threshold for memory usage")
}

var checkMemoryUsage = &cobra.Command{
Expand Down
17 changes: 17 additions & 0 deletions core/request/check_disk_request_process.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ package request

import (
"context"
"fmt"
"github.com/inexio/go-monitoringplugin"
"github.com/inexio/thola/core/value"
)

func (r *CheckDiskRequest) process(ctx context.Context) (Response, error) {
Expand All @@ -27,12 +29,27 @@ func (r *CheckDiskRequest) process(ctx context.Context) (Response, error) {
r.mon.PrintPerformanceData(false)
return &CheckResponse{r.mon.GetInfo()}, nil
}

p = monitoringplugin.NewPerformanceDataPoint("disk_used", *storage.Used, "KB").SetLabel(*storage.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
}

// get percentage of free part on the storage
free := fmt.Sprintf("%.2f", 100-float64(*storage.Used)/float64(*storage.Available)*100)
p = monitoringplugin.NewPerformanceDataPoint("disk_free", free, "%").SetLabel(*storage.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
}
val := value.New(free)
if !r.DiskThresholds.isEmpty() {
code := r.DiskThresholds.checkValue(val)
r.mon.UpdateStatusIf(code != monitoringplugin.OK, code, fmt.Sprintf("disk usage at %s is %s%%", *storage.Description, val))
}
}
}
}
Expand Down

0 comments on commit 21d8a4d

Please sign in to comment.