Skip to content

Commit

Permalink
Merge pull request #238 from prometheus-community/superq/revive
Browse files Browse the repository at this point in the history
Enable revive linter
  • Loading branch information
bitfehler authored Feb 6, 2025
2 parents c3821d9 + 74fda97 commit 6668f69
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 40 deletions.
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
linters:
enable:
- misspell
- revive
- sloglint

issues:
Expand Down
2 changes: 1 addition & 1 deletion collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ var (
)

// Describe implements Prometheus.Collector.
func (c metaCollector) Describe(ch chan<- *prometheus.Desc) {
func (c metaCollector) Describe(_ chan<- *prometheus.Desc) {
// all metrics are described ad-hoc
}

Expand Down
6 changes: 3 additions & 3 deletions collector_bmc.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,17 @@ func (c BMCCollector) Collect(result freeipmi.Result, ch chan<- prometheus.Metri
logger.Debug("Failed to parse bmc-info data", "target", targetName(target.host), "error", err)
systemFirmwareVersion = "N/A"
}
bmcUrl, err := freeipmi.GetBMCInfoBmcUrl(result)
bmcURL, err := freeipmi.GetBMCInfoBmcURL(result)
if err != nil {
// This one is not always available.
logger.Debug("Failed to parse bmc-info data", "target", targetName(target.host), "error", err)
bmcUrl = "N/A"
bmcURL = "N/A"
}
ch <- prometheus.MustNewConstMetric(
bmcInfoDesc,
prometheus.GaugeValue,
1,
firmwareRevision, manufacturerID, systemFirmwareVersion, bmcUrl,
firmwareRevision, manufacturerID, systemFirmwareVersion, bmcURL,
)
return 1, nil
}
4 changes: 2 additions & 2 deletions collector_ipmi.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,9 @@ func (c IPMICollector) Args() []string {
}

func (c IPMICollector) Collect(result freeipmi.Result, ch chan<- prometheus.Metric, target ipmiTarget) (int, error) {
excludeIds := target.config.ExcludeSensorIDs
excludeIDs := target.config.ExcludeSensorIDs
targetHost := targetName(target.host)
results, err := freeipmi.GetSensorData(result, excludeIds)
results, err := freeipmi.GetSensorData(result, excludeIDs)
if err != nil {
logger.Error("Failed to collect sensor data", "target", targetHost, "error", err)
return 0, err
Expand Down
3 changes: 2 additions & 1 deletion collector_sel_events.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,12 @@ func (c SELEventsCollector) Collect(result freeipmi.Result, ch chan<- prometheus
selEventByNameCount[metricConfig.Name] = 0
}

var newTimestamp float64
for _, data := range events {
for _, metricConfig := range selEventConfigs {
match := metricConfig.Regex.FindStringSubmatch(data.Event)
if match != nil {
var newTimestamp float64 = 0
newTimestamp = 0.0
datetime := data.Date + " " + data.Time
t, err := time.Parse(SELDateTimeFormat, datetime)
// ignore errors with invalid date or time
Expand Down
54 changes: 27 additions & 27 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ type CollectorName string
// ConfiguredCollector wraps an existing collector implementation,
// potentially altering its default settings.
type ConfiguredCollector struct {
collector collector
command string
default_args []string
custom_args []string
collector collector
command string
defaultArgs []string
customArgs []string
}

func (c ConfiguredCollector) Name() CollectorName {
Expand All @@ -52,13 +52,13 @@ func (c ConfiguredCollector) Cmd() string {

func (c ConfiguredCollector) Args() []string {
args := []string{}
if c.custom_args != nil {
if c.customArgs != nil {
// custom args come first, this way it is quite easy to
// override a collector to use e.g. sudo
args = append(args, c.custom_args...)
args = append(args, c.customArgs...)
}
if c.default_args != nil {
args = append(args, c.default_args...)
if c.defaultArgs != nil {
args = append(args, c.defaultArgs...)
} else {
args = append(args, c.collector.Args()...)
}
Expand Down Expand Up @@ -185,42 +185,42 @@ func (s *IPMIConfig) UnmarshalYAML(unmarshal func(interface{}) error) error {
return nil
}

func (c IPMIConfig) GetCollectors() []collector {
func (s *IPMIConfig) GetCollectors() []collector {
result := []collector{}
for _, co := range c.Collectors {
for _, co := range s.Collectors {
// At this point validity has already been checked
i, _ := co.GetInstance()
cc := ConfiguredCollector{
collector: i,
command: c.CollectorCmd[i.Name()],
default_args: c.CollectorArgs[i.Name()],
custom_args: c.CustomArgs[i.Name()],
collector: i,
command: s.CollectorCmd[i.Name()],
defaultArgs: s.CollectorArgs[i.Name()],
customArgs: s.CustomArgs[i.Name()],
}
result = append(result, cc)
}
return result
}

func (c IPMIConfig) GetFreeipmiConfig() string {
func (s *IPMIConfig) GetFreeipmiConfig() string {
var b strings.Builder
if c.Driver != "" {
fmt.Fprintf(&b, "driver-type %s\n", c.Driver)
if s.Driver != "" {
fmt.Fprintf(&b, "driver-type %s\n", s.Driver)
}
if c.Privilege != "" {
fmt.Fprintf(&b, "privilege-level %s\n", c.Privilege)
if s.Privilege != "" {
fmt.Fprintf(&b, "privilege-level %s\n", s.Privilege)
}
if c.User != "" {
fmt.Fprintf(&b, "username %s\n", c.User)
if s.User != "" {
fmt.Fprintf(&b, "username %s\n", s.User)
}
if c.Password != "" {
fmt.Fprintf(&b, "password %s\n", freeipmi.EscapePassword(c.Password))
if s.Password != "" {
fmt.Fprintf(&b, "password %s\n", freeipmi.EscapePassword(s.Password))
}
if c.Timeout != 0 {
fmt.Fprintf(&b, "session-timeout %d\n", c.Timeout)
if s.Timeout != 0 {
fmt.Fprintf(&b, "session-timeout %d\n", s.Timeout)
}
if len(c.WorkaroundFlags) > 0 {
if len(s.WorkaroundFlags) > 0 {
fmt.Fprintf(&b, "workaround-flags")
for _, flag := range c.WorkaroundFlags {
for _, flag := range s.WorkaroundFlags {
fmt.Fprintf(&b, " %s", flag)
}
fmt.Fprintln(&b)
Expand Down
10 changes: 5 additions & 5 deletions freeipmi/freeipmi.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ var (
bmcInfoFirmwareRevisionRegex = regexp.MustCompile(`^Firmware Revision\s*:\s*(?P<value>[0-9.]*).*`)
bmcInfoSystemFirmwareVersionRegex = regexp.MustCompile(`^System Firmware Version\s*:\s*(?P<value>[0-9.]*).*`)
bmcInfoManufacturerIDRegex = regexp.MustCompile(`^Manufacturer ID\s*:\s*(?P<value>.*)`)
bmcInfoBmcUrlRegex = regexp.MustCompile(`^BMC URL\s*:\s*(?P<value>.*)`)
bmcInfoBmcURLRegex = regexp.MustCompile(`^BMC URL\s*:\s*(?P<value>.*)`)
bmcWatchdogTimerStateRegex = regexp.MustCompile(`^Timer:\s*(?P<value>Running|Stopped)`)
bmcWatchdogTimerUseRegex = regexp.MustCompile(`^Timer Use:\s*(?P<value>.*)`)
bmcWatchdogTimerLoggingRegex = regexp.MustCompile(`^Logging:\s*(?P<value>Enabled|Disabled)`)
Expand Down Expand Up @@ -171,7 +171,7 @@ func Execute(cmd string, args []string, config string, target string, logger *sl
return Result{out, err}
}

func GetSensorData(ipmiOutput Result, excludeSensorIds []int64) ([]SensorData, error) {
func GetSensorData(ipmiOutput Result, excludeSensorIDs []int64) ([]SensorData, error) {
var result []SensorData

if ipmiOutput.err != nil {
Expand All @@ -191,7 +191,7 @@ func GetSensorData(ipmiOutput Result, excludeSensorIds []int64) ([]SensorData, e
if err != nil {
return result, err
}
if contains(excludeSensorIds, data.ID) {
if contains(excludeSensorIDs, data.ID) {
continue
}

Expand Down Expand Up @@ -314,11 +314,11 @@ func GetBMCInfoSystemFirmwareVersion(ipmiOutput Result) (string, error) {
return getValue(ipmiOutput.output, bmcInfoSystemFirmwareVersionRegex)
}

func GetBMCInfoBmcUrl(ipmiOutput Result) (string, error) {
func GetBMCInfoBmcURL(ipmiOutput Result) (string, error) {
if ipmiOutput.err != nil {
return "", fmt.Errorf("%s: %s", ipmiOutput.err, ipmiOutput.output)
}
return getValue(ipmiOutput.output, bmcInfoBmcUrlRegex)
return getValue(ipmiOutput.output, bmcInfoBmcURLRegex)
}

func GetSELInfoEntriesCount(ipmiOutput Result) (float64, error) {
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ func main() {
http.HandleFunc("/ipmi", remoteIPMIHandler) // Endpoint to do IPMI scrapes.
http.HandleFunc("/-/reload", updateConfiguration) // Endpoint to reload configuration.

http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
http.HandleFunc("/", func(w http.ResponseWriter, _ *http.Request) {
_, _ = w.Write([]byte(`<html>
<head>
<title>IPMI Exporter</title>
Expand Down

0 comments on commit 6668f69

Please sign in to comment.