Skip to content

Commit

Permalink
Filtered disk types
Browse files Browse the repository at this point in the history
  • Loading branch information
toberd committed Mar 8, 2021
1 parent 21d8a4d commit b54d41d
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 30 deletions.
9 changes: 8 additions & 1 deletion core/communicator/device_class_communicator.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,14 @@ func (o *deviceClassCommunicator) GetDiskComponentStorages(ctx context.Context)
if err != nil {
return nil, errors.Wrap(err, "failed to decode property into storage struct")
}
return storages, nil
// ignore non-physical storage types
var filtered []device.DiskComponentStorage
for _, storage := range storages {
if *storage.Type != "Other" && *storage.Type != "RAM" && *storage.Type != "Virtual Memory" {
filtered = append(filtered, storage)
}
}
return filtered, nil
}

func (o *deviceClassCommunicator) GetUPSComponentAlarmLowVoltageDisconnect(ctx context.Context) (int, error) {
Expand Down
55 changes: 26 additions & 29 deletions core/request/check_disk_request_process.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,35 +21,32 @@ func (r *CheckDiskRequest) process(ctx context.Context) (Response, error) {

for _, storage := range disk.Storages {
if storage.Type != nil && storage.Description != nil && storage.Available != nil && storage.Used != nil {
// ignore non-physical storage types
if *storage.Type != "Other" && *storage.Type != "RAM" && *storage.Type != "Virtual Memory" {
p := monitoringplugin.NewPerformanceDataPoint("disk_available", *storage.Available, "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
}

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))
}
p := monitoringplugin.NewPerformanceDataPoint("disk_available", *storage.Available, "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
}

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 b54d41d

Please sign in to comment.