Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add generator HELP override
Browse files Browse the repository at this point in the history
Allow override of the metric HELP text in the generator. Allows for
altering generated MIB documentation.
* Update example help text for `st4TempSensorValue` to match scale override.

Fixes: #1105

Signed-off-by: SuperQ <[email protected]>
SuperQ committed Feb 4, 2024
1 parent 9daacd5 commit 5b7e724
Showing 7 changed files with 14 additions and 4 deletions.
3 changes: 3 additions & 0 deletions generator/FORMAT.md
Original file line number Diff line number Diff line change
@@ -23,6 +23,9 @@ modules:
- name: sysUpTime
oid: 1.3.6.1.2.1.1.3
type: gauge
# The HELP text included with the scrape metrics.
help: The value of sysUpTime on the most recent occasion at which any one or
more of this entry's counters suffered a discontinuity - 1.3.6.1.4.1.30065.3.1.1.1.1.46
# See README.md type override for a list of valid types
# Non-numeric types are represented as a gauge with value 1, and the rendered value
# as a label value on that gauge.
1 change: 1 addition & 0 deletions generator/README.md
Original file line number Diff line number Diff line change
@@ -148,6 +148,7 @@ modules:
overrides: # Allows for per-module overrides of bits of MIBs
metricName:
ignore: true # Drops the metric from the output.
help: "string" # Override the generated HELP text provided by the MIB Description.
regex_extracts:
Temp: # A new metric will be created appending this to the metricName to become metricNameTemp.
- regex: '(.*)' # Regex to extract a value from the returned SNMP walks's value.
1 change: 1 addition & 0 deletions generator/config.go
Original file line number Diff line number Diff line change
@@ -32,6 +32,7 @@ type MetricOverrides struct {
Offset float64 `yaml:"offset,omitempty"`
Scale float64 `yaml:"scale,omitempty"`
Type string `yaml:"type,omitempty"`
Help string `yaml:"help,omitempty"`
}

// UnmarshalYAML implements the yaml.Unmarshaler interface.
1 change: 1 addition & 0 deletions generator/generator.yml
Original file line number Diff line number Diff line change
@@ -162,6 +162,7 @@ modules:
overrides:
st4TempSensorValue:
scale: 0.1
help: The measured temperature on the sensor in degrees using the scale selected by st4TempSensorScale - 1.3.6.1.4.1.1718.4.1.9.3.1.1

# Palo Alto Firewalls
#
3 changes: 3 additions & 0 deletions generator/tree.go
Original file line number Diff line number Diff line change
@@ -530,6 +530,9 @@ func generateConfigModule(cfg *ModuleConfig, node *Node, nameToNode map[string]*
metric.RegexpExtracts = params.RegexpExtracts
metric.Offset = params.Offset
metric.Scale = params.Scale
if params.Help != "" {
metric.Help = params.Help
}
}
}
}
5 changes: 3 additions & 2 deletions generator/tree_test.go
Original file line number Diff line number Diff line change
@@ -182,14 +182,15 @@ func TestGenerateConfigModule(t *testing.T) {
overrides := make(map[string]MetricOverrides)
overrides["root"] = MetricOverrides{
RegexpExtracts: strMetrics,
Help: "help override",
}

cases := []struct {
node *Node
cfg *ModuleConfig // SNMP generator config.
out *config.Module // SNMP exporter config.
}{
// Simple metric with Regexp override.
// Simple metric with Regexp and Help override.
{
node: &Node{Oid: "1", Access: "ACCESS_READONLY", Type: "INTEGER", Label: "root"},
cfg: &ModuleConfig{
@@ -203,7 +204,7 @@ func TestGenerateConfigModule(t *testing.T) {
Name: "root",
Oid: "1",
Type: "gauge",
Help: " - 1",
Help: "help override",
RegexpExtracts: strMetrics,
},
},
4 changes: 2 additions & 2 deletions snmp.yml
Original file line number Diff line number Diff line change
@@ -23309,8 +23309,8 @@ modules:
- name: st4TempSensorValue
oid: 1.3.6.1.4.1.1718.4.1.9.3.1.1
type: gauge
help: The measured temperature on the sensor in tenth degrees using the scale
selected by st4TempSensorScale - 1.3.6.1.4.1.1718.4.1.9.3.1.1
help: The measured temperature on the sensor in degrees using the scale selected
by st4TempSensorScale - 1.3.6.1.4.1.1718.4.1.9.3.1.1
indexes:
- labelname: st4UnitIndex
type: gauge

0 comments on commit 5b7e724

Please sign in to comment.