Satisfy linter

I don't see what else to do with the messages at this point if logging
were to fail...
This commit is contained in:
Conrad Hoffmann 2021-12-09 20:57:09 +01:00
parent 2c787083a3
commit e1906fa46c
10 changed files with 31 additions and 31 deletions

View File

@ -81,7 +81,7 @@ func (c metaCollector) Collect(ch chan<- prometheus.Metric) {
start := time.Now()
defer func() {
duration := time.Since(start).Seconds()
level.Debug(logger).Log("msg", "Scrape duration", "target", targetName(c.target), "duration", duration)
_ = level.Debug(logger).Log("msg", "Scrape duration", "target", targetName(c.target), "duration", duration)
ch <- prometheus.MustNewConstMetric(
durationDesc,
prometheus.GaugeValue,
@ -97,7 +97,7 @@ func (c metaCollector) Collect(ch chan<- prometheus.Metric) {
for _, collector := range config.GetCollectors() {
var up int
level.Debug(logger).Log("msg", "Running collector", "collector", collector.Name())
_ = level.Debug(logger).Log("msg", "Running collector", "collector", collector.Name())
fqcmd := path.Join(*executablesPath, collector.Cmd())
args := collector.Args()

View File

@ -50,18 +50,18 @@ func (c BMCCollector) Args() []string {
func (c BMCCollector) Collect(result freeipmi.Result, ch chan<- prometheus.Metric, target ipmiTarget) (int, error) {
firmwareRevision, err := freeipmi.GetBMCInfoFirmwareRevision(result)
if err != nil {
level.Error(logger).Log("msg", "Failed to collect BMC data", "target", targetName(target.host), "error", err)
_ = level.Error(logger).Log("msg", "Failed to collect BMC data", "target", targetName(target.host), "error", err)
return 0, err
}
manufacturerID, err := freeipmi.GetBMCInfoManufacturerID(result)
if err != nil {
level.Error(logger).Log("msg", "Failed to collect BMC data", "target", targetName(target.host), "error", err)
_ = level.Error(logger).Log("msg", "Failed to collect BMC data", "target", targetName(target.host), "error", err)
return 0, err
}
systemFirmwareVersion, err := freeipmi.GetBMCInfoSystemFirmwareVersion(result)
if err != nil {
// This one is not always available.
level.Debug(logger).Log("msg", "Failed to parse bmc-info data", "target", targetName(target.host), "error", err)
_ = level.Debug(logger).Log("msg", "Failed to parse bmc-info data", "target", targetName(target.host), "error", err)
systemFirmwareVersion = "N/A"
}
ch <- prometheus.MustNewConstMetric(

View File

@ -50,7 +50,7 @@ func (c ChassisCollector) Args() []string {
func (c ChassisCollector) Collect(result freeipmi.Result, ch chan<- prometheus.Metric, target ipmiTarget) (int, error) {
currentChassisPowerState, err := freeipmi.GetChassisPowerState(result)
if err != nil {
level.Error(logger).Log("msg", "Failed to collect chassis data", "target", targetName(target.host), "error", err)
_ = level.Error(logger).Log("msg", "Failed to collect chassis data", "target", targetName(target.host), "error", err)
return 0, err
}
ch <- prometheus.MustNewConstMetric(

View File

@ -50,7 +50,7 @@ func (c DCMICollector) Args() []string {
func (c DCMICollector) Collect(result freeipmi.Result, ch chan<- prometheus.Metric, target ipmiTarget) (int, error) {
currentPowerConsumption, err := freeipmi.GetCurrentPowerConsumption(result)
if err != nil {
level.Error(logger).Log("msg", "Failed to collect DCMI data", "target", targetName(target.host), "error", err)
_ = level.Error(logger).Log("msg", "Failed to collect DCMI data", "target", targetName(target.host), "error", err)
return 0, err
}
ch <- prometheus.MustNewConstMetric(

View File

@ -139,7 +139,7 @@ func (c IPMICollector) Collect(result freeipmi.Result, ch chan<- prometheus.Metr
excludeIds := target.config.ExcludeSensorIDs
results, err := freeipmi.GetSensorData(result, excludeIds)
if err != nil {
level.Error(logger).Log("msg", "Failed to collect sensor data", "target", targetName(target.host), "error", err)
_ = level.Error(logger).Log("msg", "Failed to collect sensor data", "target", targetName(target.host), "error", err)
return 0, err
}
for _, data := range results {
@ -155,11 +155,11 @@ func (c IPMICollector) Collect(result freeipmi.Result, ch chan<- prometheus.Metr
case "N/A":
state = math.NaN()
default:
level.Error(logger).Log("msg", "Unknown sensor state", "state", data.State)
_ = level.Error(logger).Log("msg", "Unknown sensor state", "state", data.State)
state = math.NaN()
}
level.Debug(logger).Log("msg", "Got values", "data", fmt.Sprintf("%+v", data))
_ = level.Debug(logger).Log("msg", "Got values", "data", fmt.Sprintf("%+v", data))
switch data.Unit {
case "RPM":

View File

@ -57,12 +57,12 @@ func (c SELCollector) Args() []string {
func (c SELCollector) Collect(result freeipmi.Result, ch chan<- prometheus.Metric, target ipmiTarget) (int, error) {
entriesCount, err := freeipmi.GetSELInfoEntriesCount(result)
if err != nil {
level.Error(logger).Log("msg", "Failed to collect SEL data", "target", targetName(target.host), "error", err)
_ = level.Error(logger).Log("msg", "Failed to collect SEL data", "target", targetName(target.host), "error", err)
return 0, err
}
freeSpace, err := freeipmi.GetSELInfoFreeSpace(result)
if err != nil {
level.Error(logger).Log("msg", "Failed to collect SEL data", "target", targetName(target.host), "error", err)
_ = level.Error(logger).Log("msg", "Failed to collect SEL data", "target", targetName(target.host), "error", err)
return 0, err
}
ch <- prometheus.MustNewConstMetric(

View File

@ -53,11 +53,11 @@ func (c SMLANModeCollector) Args() []string {
func (c SMLANModeCollector) Collect(result freeipmi.Result, ch chan<- prometheus.Metric, target ipmiTarget) (int, error) {
octets, err := freeipmi.GetRawOctets(result)
if err != nil {
level.Error(logger).Log("msg", "Failed to collect LAN mode data", "target", targetName(target.host), "error", err)
_ = level.Error(logger).Log("msg", "Failed to collect LAN mode data", "target", targetName(target.host), "error", err)
return 0, err
}
if len(octets) != 3 {
level.Error(logger).Log("msg", "Unexpected number of octets", "target", targetName(target.host), "octets", octets)
_ = level.Error(logger).Log("msg", "Unexpected number of octets", "target", targetName(target.host), "octets", octets)
return 0, fmt.Errorf("unexpected number of octects in raw response: %d", len(octets))
}
@ -66,7 +66,7 @@ func (c SMLANModeCollector) Collect(result freeipmi.Result, ch chan<- prometheus
value, _ := strconv.Atoi(octets[2])
ch <- prometheus.MustNewConstMetric(lanModeDesc, prometheus.GaugeValue, float64(value))
default:
level.Error(logger).Log("msg", "Unexpected lan mode status (ipmi-raw)", "target", targetName(target.host), "sgatus", octets[2])
_ = level.Error(logger).Log("msg", "Unexpected lan mode status (ipmi-raw)", "target", targetName(target.host), "sgatus", octets[2])
return 0, fmt.Errorf("unexpected lan mode status: %s", octets[2])
}

View File

@ -224,7 +224,7 @@ func (sc *SafeConfig) ReloadConfig(configFile string) error {
if configFile != "" {
config, err = ioutil.ReadFile(configFile)
if err != nil {
level.Error(logger).Log("msg", "Error reading config file", "error", err)
_ = level.Error(logger).Log("msg", "Error reading config file", "error", err)
return err
}
} else {
@ -240,7 +240,7 @@ func (sc *SafeConfig) ReloadConfig(configFile string) error {
sc.Unlock()
if configFile != "" {
level.Info(logger).Log("msg", "Loaded config file", "path", configFile)
_ = level.Info(logger).Log("msg", "Loaded config file", "path", configFile)
}
return nil
}
@ -266,7 +266,7 @@ func (sc *SafeConfig) ConfigForTarget(target, module string) IPMIConfig {
if module != "default" {
config, ok = sc.C.Modules[module]
if !ok {
level.Error(logger).Log("msg", "Requested module not found, using default", "module", module, "target", targetName(target))
_ = level.Error(logger).Log("msg", "Requested module not found, using default", "module", module, "target", targetName(target))
}
}
@ -275,7 +275,7 @@ func (sc *SafeConfig) ConfigForTarget(target, module string) IPMIConfig {
config, ok = sc.C.Modules["default"]
if !ok {
// This is probably fine for running locally, so not making this a warning
level.Debug(logger).Log("msg", "Needed default config for, but none configured, using FreeIPMI defaults", "target", targetName(target))
_ = level.Debug(logger).Log("msg", "Needed default config for, but none configured, using FreeIPMI defaults", "target", targetName(target))
config = defaultConfig
}
}

View File

@ -114,10 +114,10 @@ func freeipmiConfigPipe(config string, logger log.Logger) (string, error) {
go func(file string, data []byte) {
f, err := os.OpenFile(file, os.O_WRONLY|os.O_CREATE|os.O_APPEND, os.ModeNamedPipe)
if err != nil {
level.Error(logger).Log("msg", "Error opening pipe", "error", err)
_ = level.Error(logger).Log("msg", "Error opening pipe", "error", err)
}
if _, err := f.Write(data); err != nil {
level.Error(logger).Log("msg", "Error writing config to pipe", "error", err)
_ = level.Error(logger).Log("msg", "Error writing config to pipe", "error", err)
}
f.Close()
}(pipe, content)
@ -131,7 +131,7 @@ func Execute(cmd string, args []string, config string, target string, logger log
}
defer func() {
if err := os.Remove(pipe); err != nil {
level.Error(logger).Log("msg", "Error deleting named pipe", "error", err)
_ = level.Error(logger).Log("msg", "Error deleting named pipe", "error", err)
}
}()
@ -142,7 +142,7 @@ func Execute(cmd string, args []string, config string, target string, logger log
target = "[local]"
}
level.Debug(logger).Log("msg", "Executing", "command", cmd, "args", fmt.Sprintf("%+v", args))
_ = level.Debug(logger).Log("msg", "Executing", "command", cmd, "args", fmt.Sprintf("%+v", args))
out, err := exec.Command(cmd, args...).CombinedOutput()
if err != nil {
err = fmt.Errorf("error running %s: %s", cmd, err)

16
main.go
View File

@ -69,7 +69,7 @@ func remoteIPMIHandler(w http.ResponseWriter, r *http.Request) {
return
}
level.Debug(logger).Log("msg", "Scraping target", "target", target, "module", module)
_ = level.Debug(logger).Log("msg", "Scraping target", "target", target, "module", module)
registry := prometheus.NewRegistry()
remoteCollector := metaCollector{target: target, module: module, config: sc}
@ -87,7 +87,7 @@ func updateConfiguration(w http.ResponseWriter, r *http.Request) {
http.Error(w, fmt.Sprintf("failed to reload config: %s", err), http.StatusInternalServerError)
}
default:
level.Error(logger).Log("msg", "Only POST requests allowed", "url", r.URL)
_ = level.Error(logger).Log("msg", "Only POST requests allowed", "url", r.URL)
w.Header().Set("Allow", "POST")
http.Error(w, "Only POST requests allowed", http.StatusMethodNotAllowed)
}
@ -98,11 +98,11 @@ func main() {
kingpin.HelpFlag.Short('h')
kingpin.Version(version.Print("ipmi_exporter"))
kingpin.Parse()
level.Info(logger).Log("msg", "Starting ipmi_exporter", "version", version.Info())
_ = level.Info(logger).Log("msg", "Starting ipmi_exporter", "version", version.Info())
// Bail early if the config is bad.
if err := sc.ReloadConfig(*configFile); err != nil {
level.Error(logger).Log("msg", "Error parsing config file", "error", err)
_ = level.Error(logger).Log("msg", "Error parsing config file", "error", err)
os.Exit(1)
}
@ -114,11 +114,11 @@ func main() {
select {
case <-hup:
if err := sc.ReloadConfig(*configFile); err != nil {
level.Error(logger).Log("msg", "Error reloading config", "error", err)
_ = level.Error(logger).Log("msg", "Error reloading config", "error", err)
}
case rc := <-reloadCh:
if err := sc.ReloadConfig(*configFile); err != nil {
level.Error(logger).Log("msg", "Error reloading config", "error", err)
_ = level.Error(logger).Log("msg", "Error reloading config", "error", err)
rc <- err
} else {
rc <- nil
@ -163,10 +163,10 @@ func main() {
</html>`))
})
level.Info(logger).Log("msg", "Listening on", "address", *listenAddress)
_ = level.Info(logger).Log("msg", "Listening on", "address", *listenAddress)
err := http.ListenAndServe(*listenAddress, nil)
if err != nil {
level.Error(logger).Log("msg", "HTTP listener stopped", "error", err)
_ = level.Error(logger).Log("msg", "HTTP listener stopped", "error", err)
os.Exit(1)
}
}