diff --git a/inputs/ipmi/connection.go b/inputs/ipmi/connection.go deleted file mode 100644 index 3b087309..00000000 --- a/inputs/ipmi/connection.go +++ /dev/null @@ -1,99 +0,0 @@ -package ipmi - -import ( - "fmt" - "net" - "strconv" - "strings" -) - -// Connection properties for a Client -type Connection struct { - Hostname string - Username string - Password string - Port int - Interface string - Privilege string - HexKey string -} - -func NewConnection(server, privilege, hexKey string) *Connection { - conn := &Connection{ - Privilege: privilege, - HexKey: hexKey, - } - inx1 := strings.LastIndex(server, "@") - inx2 := strings.Index(server, "(") - - connstr := server - - if inx1 > 0 { - security := server[0:inx1] - connstr = server[inx1+1:] - up := strings.SplitN(security, ":", 2) - if len(up) == 2 { - conn.Username = up[0] - conn.Password = up[1] - } - } - - if inx2 > 0 { - inx2 = strings.Index(connstr, "(") - inx3 := strings.Index(connstr, ")") - - conn.Interface = connstr[0:inx2] - conn.Hostname = connstr[inx2+1 : inx3] - } - - return conn -} - -func (c *Connection) options() []string { - intf := c.Interface - if intf == "" { - intf = "lan" - } - - options := []string{ - "-H", c.Hostname, - "-U", c.Username, - "-P", c.Password, - "-I", intf, - } - - if c.HexKey != "" { - options = append(options, "-y", c.HexKey) - } - if c.Port != 0 { - options = append(options, "-p", strconv.Itoa(c.Port)) - } - if c.Privilege != "" { - options = append(options, "-L", c.Privilege) - } - return options -} - -// RemoteIP returns the remote (bmc) IP address of the Connection -func (c *Connection) RemoteIP() string { - if net.ParseIP(c.Hostname) == nil { - addrs, err := net.LookupHost(c.Hostname) - if err != nil && len(addrs) > 0 { - return addrs[0] - } - } - return c.Hostname -} - -// LocalIP returns the local (client) IP address of the Connection -func (c *Connection) LocalIP() string { - conn, err := net.Dial("udp", fmt.Sprintf("%s:%d", c.Hostname, c.Port)) - if err != nil { - // don't bother returning an error, since this value will never - // make it to the bmc if we can't connect to it. - return c.Hostname - } - _ = conn.Close() - host, _, _ := net.SplitHostPort(conn.LocalAddr().String()) - return host -} diff --git a/inputs/ipmi/exporter/collector_bmc.go b/inputs/ipmi/exporter/collector_bmc.go index 1a3fde6d..94816957 100644 --- a/inputs/ipmi/exporter/collector_bmc.go +++ b/inputs/ipmi/exporter/collector_bmc.go @@ -1,3 +1,6 @@ +//go:build !windows +// +build !windows + // Copyright 2021 The Prometheus Authors // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/inputs/ipmi/exporter/collector_bmc_watchdog.go b/inputs/ipmi/exporter/collector_bmc_watchdog.go index 0cb3f3ef..0c6269de 100644 --- a/inputs/ipmi/exporter/collector_bmc_watchdog.go +++ b/inputs/ipmi/exporter/collector_bmc_watchdog.go @@ -1,3 +1,6 @@ +//go:build !windows +// +build !windows + // Copyright 2021 The Prometheus Authors // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/inputs/ipmi/exporter/collector_chassis.go b/inputs/ipmi/exporter/collector_chassis.go index f19df6ea..63a221c5 100644 --- a/inputs/ipmi/exporter/collector_chassis.go +++ b/inputs/ipmi/exporter/collector_chassis.go @@ -1,3 +1,6 @@ +//go:build !windows +// +build !windows + // Copyright 2021 The Prometheus Authors // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/inputs/ipmi/exporter/collector_dcmi.go b/inputs/ipmi/exporter/collector_dcmi.go index 8f5f7a14..61a6014b 100644 --- a/inputs/ipmi/exporter/collector_dcmi.go +++ b/inputs/ipmi/exporter/collector_dcmi.go @@ -1,3 +1,6 @@ +//go:build !windows +// +build !windows + // Copyright 2021 The Prometheus Authors // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/inputs/ipmi/exporter/collector_ipmi.go b/inputs/ipmi/exporter/collector_ipmi.go index 85f1bbc3..eda86eed 100644 --- a/inputs/ipmi/exporter/collector_ipmi.go +++ b/inputs/ipmi/exporter/collector_ipmi.go @@ -1,3 +1,6 @@ +//go:build !windows +// +build !windows + // Copyright 2021 The Prometheus Authors // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/inputs/ipmi/exporter/collector.go b/inputs/ipmi/exporter/collector_notwindows.go similarity index 98% rename from inputs/ipmi/exporter/collector.go rename to inputs/ipmi/exporter/collector_notwindows.go index d1e281f3..5b7234f7 100644 --- a/inputs/ipmi/exporter/collector.go +++ b/inputs/ipmi/exporter/collector_notwindows.go @@ -1,3 +1,6 @@ +//go:build !windows +// +build !windows + // Copyright 2021 The Prometheus Authors // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/inputs/ipmi/exporter/collector_sel.go b/inputs/ipmi/exporter/collector_sel.go index be94e99d..feb6cb6e 100644 --- a/inputs/ipmi/exporter/collector_sel.go +++ b/inputs/ipmi/exporter/collector_sel.go @@ -1,3 +1,6 @@ +//go:build !windows +// +build !windows + // Copyright 2021 The Prometheus Authors // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/inputs/ipmi/exporter/collector_sm_lan_mode.go b/inputs/ipmi/exporter/collector_sm_lan_mode.go index d9103f42..028e1a92 100644 --- a/inputs/ipmi/exporter/collector_sm_lan_mode.go +++ b/inputs/ipmi/exporter/collector_sm_lan_mode.go @@ -1,3 +1,6 @@ +//go:build !windows +// +build !windows + // Copyright 2021 The Prometheus Authors // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/inputs/ipmi/exporter/collector_windows.go b/inputs/ipmi/exporter/collector_windows.go new file mode 100644 index 00000000..3756fed1 --- /dev/null +++ b/inputs/ipmi/exporter/collector_windows.go @@ -0,0 +1,16 @@ +//go:build windows +// +build windows + +package exporter + +import ( + "github.com/prometheus/client_golang/prometheus" +) + +type IPMIConfig struct { + Timeout uint32 +} + +func Collect(ch chan<- prometheus.Metric, host, binPath string, config IPMIConfig) { + return +} diff --git a/inputs/ipmi/exporter/config.go b/inputs/ipmi/exporter/config.go index 04cc7944..60f06355 100644 --- a/inputs/ipmi/exporter/config.go +++ b/inputs/ipmi/exporter/config.go @@ -1,3 +1,6 @@ +//go:build !windows +// +build !windows + // Copyright 2021 The Prometheus Authors // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -138,38 +141,6 @@ func checkOverflow(m map[string]interface{}, ctx string) error { return nil } -/* - -// UnmarshalYAML implements the yaml.Unmarshaler interface. -func (s *Config) UnmarshalYAML(unmarshal func(interface{}) error) error { - type plain Config - if err := unmarshal((*plain)(s)); err != nil { - return err - } - if err := checkOverflow(s.XXX, "config"); err != nil { - return err - } - return nil -} -*/ -// UnmarshalYAML implements the yaml.Unmarshaler interface. -func (s *IPMIConfig) UnmarshalYAML(unmarshal func(interface{}) error) error { - *s = defaultConfig - type plain IPMIConfig - if err := unmarshal((*plain)(s)); err != nil { - return err - } - if err := checkOverflow(s.XXX, "modules"); err != nil { - return err - } - for _, c := range s.Collectors { - if err := c.IsValid(); err != nil { - return err - } - } - return nil -} - func (c IPMIConfig) GetCollectors() []Collector { result := []Collector{} for _, co := range c.Collectors { @@ -212,74 +183,3 @@ func (c IPMIConfig) GetFreeipmiConfig() string { } return b.String() } - -/* -// ReloadConfig reloads the config in a concurrency-safe way. If the configFile -// is unreadable or unparsable, an error is returned and the old config is kept. -func (sc *SafeConfig) ReloadConfig(configFile string) error { - var c = &Config{} - var config []byte - var err error - - if configFile != "" { - config, err = os.ReadFile(configFile) - if err != nil { - log.Println("msg", "Error reading config file", "error", err) - return err - } - } else { - config = []byte("# use empty file as default") - } - - if err = yaml.Unmarshal(config, c); err != nil { - return err - } - - sc.Lock() - sc.C = c - sc.Unlock() - - if configFile != "" { - log.Println("msg", "Loaded config file", "path", configFile) - } - return nil -} - -// HasModule returns true if a given module is configured. It is concurrency-safe. -func (sc *SafeConfig) HasModule(module string) bool { - sc.Lock() - defer sc.Unlock() - - _, ok := sc.C.Modules[module] - return ok -} - -// ConfigForTarget returns the config for a given target/module, or the -// default. It is concurrency-safe. -func (sc *SafeConfig) ConfigForTarget(target, module string) IPMIConfig { - sc.Lock() - defer sc.Unlock() - - var config IPMIConfig - var ok = false - - if module != "default" { - config, ok = sc.C.Modules[module] - if !ok { - log.Println("msg", "Requested module not found, using default", "module", module, "target", targetName(target)) - } - } - - // If nothing found, fall back to defaults - if !ok { - config, ok = sc.C.Modules["default"] - if !ok { - // This is probably fine for running locally, so not making this a warning - log.Println("msg", "Needed default config for, but none configured, using FreeIPMI defaults", "target", targetName(target)) - config = defaultConfig - } - } - - return config -} -*/ diff --git a/inputs/ipmi/exporter/freeipmi/freeipmi.go b/inputs/ipmi/exporter/freeipmi/freeipmi.go index e838c5b0..a338048c 100644 --- a/inputs/ipmi/exporter/freeipmi/freeipmi.go +++ b/inputs/ipmi/exporter/freeipmi/freeipmi.go @@ -1,3 +1,6 @@ +//go:build !windows +// +build !windows + // Copyright 2021 The Prometheus Authors // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/inputs/ipmi/instances.go b/inputs/ipmi/instances.go index 805d7f2c..1ac252cd 100644 --- a/inputs/ipmi/instances.go +++ b/inputs/ipmi/instances.go @@ -1,13 +1,15 @@ package ipmi import ( + "log" + + "github.com/prometheus/client_golang/prometheus" + dto "github.com/prometheus/client_model/go" + "flashcat.cloud/categraf/config" "flashcat.cloud/categraf/inputs/ipmi/exporter" util "flashcat.cloud/categraf/pkg/metrics" "flashcat.cloud/categraf/types" - "github.com/prometheus/client_golang/prometheus" - dto "github.com/prometheus/client_model/go" - "log" ) // Instance stores the configuration values for the ipmi_sensor input plugin