chore: fix staticcheck SA warnings

- Fix SA4006 unused value issues in ssh.go, validation.go, generator.go
- Replace deprecated ioutil with io/os in config.go
- Replace deprecated tar.TypeRegA with tar.TypeReg
- Remove deprecated rand.Seed calls (auto-seeded in Go 1.20+)
- Fix always-true nil check in main.go
- Fix impossible nil comparison in tempproxy/client.go
- Add nil check for config in monitor.New()
This commit is contained in:
rcourtman 2025-11-27 09:16:53 +00:00
parent 4fd3bdbc04
commit e25e1af8cb
9 changed files with 23 additions and 27 deletions

View file

@ -1023,8 +1023,7 @@ func (p *Proxy) getTemperatureLocal(ctx context.Context) (string, error) {
if err != nil {
// Try without -j flag as fallback
cmd = exec.CommandContext(ctx, "sensors")
output, err = cmd.Output()
if err != nil {
if _, err = cmd.Output(); err != nil {
return "", fmt.Errorf("failed to run sensors: %w", err)
}
// Return empty JSON object for non-JSON output

View file

@ -412,12 +412,9 @@ func (v *nodeValidator) Validate(ctx context.Context, node string) error {
return nil
}
func (v *nodeValidator) validateAsLocalhost(ctx context.Context, node string) error {
func (v *nodeValidator) validateAsLocalhost(_ context.Context, node string) error {
// When cluster validation is unavailable, only allow access to localhost
// This maintains security while allowing self-monitoring
if ctx == nil {
ctx = context.Background()
}
// Try to discover local host addresses
localAddrs, err := discoverLocalHostAddresses()

View file

@ -4,7 +4,7 @@ import (
"bufio"
"encoding/base64"
"fmt"
"io/ioutil"
"io"
"net/http"
"net/url"
"os"
@ -86,7 +86,7 @@ var configExportCmd = &cobra.Command{
// Write to file or stdout
if exportFile != "" {
if err := ioutil.WriteFile(exportFile, []byte(exportedData), 0600); err != nil {
if err := os.WriteFile(exportFile, []byte(exportedData), 0600); err != nil {
return fmt.Errorf("failed to write export file: %w", err)
}
fmt.Printf("Configuration exported to %s\n", exportFile)
@ -117,7 +117,7 @@ var configImportCmd = &cobra.Command{
}
// Read import file
data, err := ioutil.ReadFile(importFile)
data, err := os.ReadFile(importFile)
if err != nil {
return fmt.Errorf("failed to read import file: %w", err)
}
@ -245,7 +245,7 @@ var configAutoImportCmd = &cobra.Command{
return fmt.Errorf("failed to fetch configuration from URL: %s", resp.Status)
}
body, err := ioutil.ReadAll(resp.Body)
body, err := io.ReadAll(resp.Body)
if err != nil {
return fmt.Errorf("failed to read configuration response: %w", err)
}

View file

@ -253,12 +253,10 @@ func runServer() {
configWatcher.ReloadConfig()
}
if reloadFunc != nil {
if err := reloadFunc(); err != nil {
log.Error().Err(err).Msg("Failed to reload monitor after SIGHUP")
} else {
log.Info().Msg("Runtime configuration reloaded")
}
if err := reloadFunc(); err != nil {
log.Error().Err(err).Msg("Failed to reload monitor after SIGHUP")
} else {
log.Info().Msg("Runtime configuration reloaded")
}
case <-sigChan:

View file

@ -236,7 +236,7 @@ func extractHostAgentBinaries(archivePath, targetDir string) error {
continue
}
if header.Typeflag != tar.TypeReg && header.Typeflag != tar.TypeRegA && header.Typeflag != tar.TypeSymlink {
if header.Typeflag != tar.TypeReg && header.Typeflag != tar.TypeSymlink {
continue
}
@ -252,7 +252,7 @@ func extractHostAgentBinaries(archivePath, targetDir string) error {
destPath := filepath.Join(targetDir, base)
switch header.Typeflag {
case tar.TypeReg, tar.TypeRegA:
case tar.TypeReg:
if err := writeHostAgentFile(destPath, tr, header.FileInfo().Mode()); err != nil {
return err
}

View file

@ -226,7 +226,7 @@ func generateVirtualDisks() ([]models.Disk, models.Disk) {
}
func GenerateMockData(config MockConfig) models.StateSnapshot {
rand.Seed(time.Now().UnixNano())
// rand is automatically seeded in Go 1.20+
data := models.StateSnapshot{
Nodes: generateNodes(config),
@ -273,8 +273,7 @@ func GenerateMockData(config MockConfig) models.StateSnapshot {
}
// Calculate VM count based on node role
vmCount := config.VMsPerNode
lxcCount := config.LXCsPerNode
var vmCount, lxcCount int
switch nodeRole {
case "vm-heavy":

View file

@ -59,6 +59,4 @@ func TestMetricsHistoryConcurrentAccess(t *testing.T) {
wg.Wait()
}
func init() {
rand.Seed(time.Now().UnixNano())
}
// rand is automatically seeded in Go 1.20+

View file

@ -3700,6 +3700,10 @@ func checkContainerizedTempMonitoring() {
// New creates a new Monitor instance
func New(cfg *config.Config) (*Monitor, error) {
if cfg == nil {
return nil, fmt.Errorf("config cannot be nil")
}
// Initialize temperature collector with sensors SSH key
// Will use root user for now - can be made configurable later
homeDir := os.Getenv("HOME")
@ -3712,7 +3716,7 @@ func New(cfg *config.Config) (*Monitor, error) {
// Security warning if running in container with SSH temperature monitoring
checkContainerizedTempMonitoring()
if cfg != nil && cfg.TemperatureMonitoringEnabled {
if cfg.TemperatureMonitoringEnabled {
isContainer := os.Getenv("PULSE_DOCKER") == "true" || system.InContainer()
if isContainer && tempCollector != nil && !tempCollector.SocketProxyAvailable() {
log.Warn().Msg("Temperature monitoring is enabled but the container does not have access to pulse-sensor-proxy. Install the proxy on the host or disable temperatures until it is available.")

View file

@ -278,8 +278,9 @@ func (c *Client) callWithContext(ctx context.Context, method string, params map[
return resp, proxyErr
}
lastErr = proxyErr
if lastErr == nil {
if proxyErr != nil {
lastErr = proxyErr
} else {
lastErr = err
}