Skip to content

Commit

Permalink
Merge pull request #1236 from atc0005/fix-gosec-g115-linting-errors-s…
Browse files Browse the repository at this point in the history
…table-branch

Fix gosec G115 linting errors
  • Loading branch information
atc0005 authored Sep 1, 2024
2 parents a84b3f2 + 44913fd commit bafa34c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 20 deletions.
28 changes: 14 additions & 14 deletions cmd/check_vmware_vcpus/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,32 +157,32 @@ func main() {

// here we diverge from VMware Tools plugin

var vCPUsAllocated int32
var vCPUsAllocated int64
for _, vm := range vmsFilterResults.VMsAfterFiltering() {
vCPUsAllocated += vm.Summary.Config.NumCpu
vCPUsAllocated += int64(vm.Summary.Config.NumCpu)
log.Debug().
Str("vm_name", vm.Name).
Int32("num_vcpu", vm.Summary.Config.NumCpu).
Msg("")
}

log.Debug().
Int32("vcpus_allocated", vCPUsAllocated).
Int64("vcpus_allocated", vCPUsAllocated).
Msg("Finished counting vCPUs")

vCPUsPercentageUsedOfAllowed := float32(vCPUsAllocated) / float32(cfg.VCPUsMaxAllowed) * 100
var vCPUsRemaining int32
vCPUsPercentageUsedOfAllowed := float64(vCPUsAllocated) / float64(cfg.VCPUsMaxAllowed) * 100
var vCPUsRemaining int64

switch {
case vCPUsAllocated > int32(cfg.VCPUsMaxAllowed):
case vCPUsAllocated > int64(cfg.VCPUsMaxAllowed):
vCPUsRemaining = 0
default:
vCPUsRemaining = int32(cfg.VCPUsMaxAllowed) - vCPUsAllocated
vCPUsRemaining = int64(cfg.VCPUsMaxAllowed) - vCPUsAllocated
}

log.Debug().
Float32("vcpus_usage", vCPUsPercentageUsedOfAllowed).
Int32("vcpus_remaining", vCPUsRemaining).
Float64("vcpus_usage", vCPUsPercentageUsedOfAllowed).
Int64("vcpus_remaining", vCPUsRemaining).
Msg("")

log.Debug().Msg("Compiling Performance Data details")
Expand Down Expand Up @@ -234,14 +234,14 @@ func main() {
Int("vms_after_filtering", vmsFilterResults.NumVMsAfterFiltering()).
Int("vms_excluded_by_name", vmsFilterResults.NumVMsExcludedByName()).
Int("vms_excluded_by_power_state", vmsFilterResults.NumVMsExcludedByPowerState()).
Float32("vcpus_usage", vCPUsPercentageUsedOfAllowed).
Int32("vcpus_used", vCPUsAllocated).
Int32("vcpus_remaining", vCPUsRemaining).
Float64("vcpus_usage", vCPUsPercentageUsedOfAllowed).
Int64("vcpus_used", vCPUsAllocated).
Int64("vcpus_remaining", vCPUsRemaining).
Logger()

log.Debug().Msg("Evaluating vCPU usage")
switch {
case vCPUsPercentageUsedOfAllowed > float32(cfg.VCPUsAllocatedCritical):
case vCPUsPercentageUsedOfAllowed > float64(cfg.VCPUsAllocatedCritical):

log.Error().Msg("vCPUs allocation CRITICAL")

Expand All @@ -266,7 +266,7 @@ func main() {

return

case vCPUsPercentageUsedOfAllowed > float32(cfg.VCPUsAllocatedWarning):
case vCPUsPercentageUsedOfAllowed > float64(cfg.VCPUsAllocatedWarning):

log.Error().Msg("vCPUs allocation WARNING")

Expand Down
12 changes: 6 additions & 6 deletions internal/vsphere/vcpus.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ var ErrVCPUsUsageThresholdCrossed = errors.New("vCPUS allocation exceeds specifi
func VirtualCPUsOneLineCheckSummary(
stateLabel string,
vmsFilterResults VMsFilterResults,
vCPUsAllocated int32,
vCPUsAllocated int64,
vCPUsMax int,
) string {

Expand All @@ -41,12 +41,12 @@ func VirtualCPUsOneLineCheckSummary(
)
}()

vCPUsPercentageUsed := float32(vCPUsAllocated) / float32(vCPUsMax) * 100
vCPUsPercentageUsed := float64(vCPUsAllocated) / float64(vCPUsMax) * 100

switch {

case vCPUsAllocated > int32(vCPUsMax):
vCPUsOverage := vCPUsAllocated - int32(vCPUsMax)
case vCPUsAllocated > int64(vCPUsMax):
vCPUsOverage := vCPUsAllocated - int64(vCPUsMax)
return fmt.Sprintf(
"%s: %d vCPUs allocated (%.1f%%); %d more allocated than %d allowed"+
" (evaluated %d VMs, %d Resource Pools)",
Expand All @@ -60,7 +60,7 @@ func VirtualCPUsOneLineCheckSummary(
)

default:
vCPUsRemaining := int32(vCPUsMax) - vCPUsAllocated
vCPUsRemaining := int64(vCPUsMax) - vCPUsAllocated
return fmt.Sprintf(
"%s: %d vCPUs allocated (%.1f%%); %d more remaining from %d allowed"+
" (evaluated %d VMs, %d Resource Pools)",
Expand All @@ -85,7 +85,7 @@ func VirtualCPUsReport(
c *vim25.Client,
vmsFilterOptions VMsFilterOptions,
vmsFilterResults VMsFilterResults,
vCPUsAllocated int32,
vCPUsAllocated int64,
vCPUsMax int,
) string {

Expand Down

0 comments on commit bafa34c

Please sign in to comment.