Skip to content

Commit

Permalink
Merge pull request prometheus-community#99 from prometheus-community/…
Browse files Browse the repository at this point in the history
…superq/web_config

Add TLS/auth config
  • Loading branch information
bitfehler authored Feb 24, 2022
2 parents a3d8f40 + 3962217 commit bb59b21
Show file tree
Hide file tree
Showing 15 changed files with 90 additions and 43 deletions.
10 changes: 10 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
issues:
exclude-rules:
- path: _test.go
linters:
- errcheck

linters-settings:
errcheck:
exclude: scripts/errcheck_excludes.txt
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,14 @@ The [configuration](docs/configuration.md) document describes both the
configuration of the IPMI exporter itself as well as providing some guidance
for configuring the Prometheus server to scrape it.
## TLS and basic authentication
The IPMI Exporter supports TLS and basic authentication.
To use TLS and/or basic authentication, you need to pass a configuration file
using the `--web.config.file` parameter. The format of the file is described
[in the exporter-toolkit repository](https://github.com/prometheus/exporter-toolkit/blob/master/docs/web-configuration.md).
## Exported data
For a description of the metrics that this exporter provides, see the
Expand Down
4 changes: 2 additions & 2 deletions collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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", "target", target.host, "collector", collector.Name())
level.Debug(logger).Log("msg", "Running collector", "target", target.host, "collector", collector.Name())

fqcmd := path.Join(*executablesPath, collector.Cmd())
args := collector.Args()
Expand Down
6 changes: 3 additions & 3 deletions collector_bmc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion collector_chassis.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion collector_dcmi.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
6 changes: 3 additions & 3 deletions collector_ipmi.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ func (c IPMICollector) Collect(result freeipmi.Result, ch chan<- prometheus.Metr
targetHost := targetName(target.host)
results, err := freeipmi.GetSensorData(result, excludeIds)
if err != nil {
_ = level.Error(logger).Log("msg", "Failed to collect sensor data", "target", targetHost, "error", err)
level.Error(logger).Log("msg", "Failed to collect sensor data", "target", targetHost, "error", err)
return 0, err
}
for _, data := range results {
Expand All @@ -163,11 +163,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", "target", targetHost, "state", data.State)
level.Error(logger).Log("msg", "Unknown sensor state", "target", targetHost, "state", data.State)
state = math.NaN()
}

_ = level.Debug(logger).Log("msg", "Got values", "target", targetHost, "data", fmt.Sprintf("%+v", data))
level.Debug(logger).Log("msg", "Got values", "target", targetHost, "data", fmt.Sprintf("%+v", data))

switch data.Unit {
case "RPM":
Expand Down
4 changes: 2 additions & 2 deletions collector_sel.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
6 changes: 3 additions & 3 deletions collector_sm_lan_mode.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}

Expand All @@ -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])
}

Expand Down
8 changes: 4 additions & 4 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
}
Expand All @@ -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))
}
}

Expand All @@ -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
}
}
Expand Down
8 changes: 4 additions & 4 deletions freeipmi/freeipmi.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
}
}()

Expand All @@ -140,7 +140,7 @@ func Execute(cmd string, args []string, config string, target string, logger log
args = append(args, "-h", target)
}

_ = 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)
Expand Down
5 changes: 3 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ go 1.13

require (
github.com/go-kit/log v0.2.0
github.com/prometheus/client_golang v1.11.0
github.com/prometheus/common v0.30.0
github.com/prometheus/client_golang v1.12.1
github.com/prometheus/common v0.32.1
github.com/prometheus/exporter-toolkit v0.7.1
gopkg.in/alecthomas/kingpin.v2 v2.2.6
gopkg.in/yaml.v2 v2.4.0
)
Loading

0 comments on commit bb59b21

Please sign in to comment.