Skip to content

Commit

Permalink
Log a warning if ups.status is not in the variables requested to be e…
Browse files Browse the repository at this point in the history
…xported
  • Loading branch information
DRuggeri committed Jan 10, 2025
1 parent ea71c7f commit 2720965
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ Therefore, these are all enabled in the default value for `--nut.statuses`.
The exporter allows for per-scrape overrides of command line parameters by passing query string parameters. This enables a single nut_exporter to scrape multiple NUT servers

The following query string parameters can be passed to the `/ups_metrics` path:
* `ups` - Required if more than one UPS is present in NUT)
* `ups` - Required if more than one UPS is present in NUT
* `server` - Overrides the command line parameter `--nut.server`
* `username` - Overrides the command line parameter `--nut.username`
* `password` - Overrides the environment variable NUT_EXPORTER_PASSWORD. It is **strongly** recommended to avoid passing credentials over http unless the exporter is configured with TLS
Expand Down
12 changes: 11 additions & 1 deletion nut_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,13 +162,23 @@ func main() {
}

variables := []string{}
hasUpsStatusVariable := false
for _, varName := range strings.Split(*enableFilter, ",") {
// Be nice and clear spaces for those that like them
variable := strings.Trim(varName, " ")
if variable == "" {
continue
}
variables = append(variables, strings.Trim(varName, " "))
variables = append(variables, variable)

// Special handling because this is an important and commonly needed variable
if variable == "ups.status" {
hasUpsStatusVariable = true
}
}

if !hasUpsStatusVariable {
level.Warn(logger).Log("msg", "Exporter has been started without `ups.status` variable to be exported with --nut.vars_enable. Online/offline/etc statuses will not be reported!")
}

statuses := []string{}
Expand Down

0 comments on commit 2720965

Please sign in to comment.