Skip to main content

SnmpConfig

Declare Horizon's whole SNMP configuration in one document: defaults, profiles and definitions from snmp-config.xml, plus the optional trap daemon. Targets /api/v2/snmp-config, and /api/v2/trapd/config when spec.trapd is present. The snmp-config half works on any supported Horizon. The spec.trapd block needs a Horizon build with the Trapd REST API (NMS-19128, the 37.x/develop line).

YAML​

SnmpConfig is a singleton: metadata.name is fixed to default.

FieldTypeDefaultDescription
apiVersionstringrequiredsnmp.opennms.org/v1
kindstringrequiredSnmpConfig
metadata.namestringrequireddefault
spec.defaultsSNMP parametersnoneFallback parameters for any agent no definition matches.
spec.profileslist[]Named parameter templates. A definition adopts one by label.
spec.definitionslist[]Per-target overrides.
spec.trapdobjectnoneTrap-daemon configuration. Omit it and apply never touches the trap endpoint.

Unknown keys at the top level, in metadata and in spec fail the parse. Unknown keys inside defaults, a profile or a definition are ignored, not rejected.

SNMP parameters, shared by defaults, each profile and each definition. Every field is optional. An omitted field inherits the server default, or on a profile or definition the defaults tier (Horizon behaviour).

FieldTypeDefaultDescription
versionstringnonev1, v2c or v3.
portintegernoneAgent UDP port.
timeoutintegernoneRequest timeout.
retriesintegernoneRetry count.
ttlintegernoneTime to live.
proxyHoststringnoneProxy host.
readCommunitysecret referencenonev1/v2c read community.
writeCommunitysecret referencenonev1/v2c write community.
maxRepetitionsintegernoneGETBULK max repetitions.
maxVarsPerPduintegernoneMaximum variables per PDU.
maxRequestSizeintegernoneMaximum request size.
securityNamestringnonev3 user name.
securityLevelstringnonenoAuthNoPriv, authNoPriv or authPriv.
authProtocolstringnonev3 authentication protocol, such as SHA.
authPassphrasesecret referencenonev3 authentication passphrase.
privacyProtocolstringnonev3 privacy protocol, such as AES.
privacyPassphrasesecret referencenonev3 privacy passphrase.
contextNamestringnonev3 context name.
engineIdstringnonev3 engine ID.
contextEngineIdstringnonev3 context engine ID.
enterpriseIdstringnoneEnterprise ID.

Extra fields of a spec.profiles entry:

FieldTypeDefaultDescription
labelstringrequiredProfile name. Definitions reference it through profileLabel.
filterExpressionstringnoneOpenNMS filter expression, evaluated on the server.

Extra fields of a spec.definitions entry:

FieldTypeDefaultDescription
specificslist of IPs[]Exact IPv4 or IPv6 addresses.
rangeslist of {begin, end}[]Inclusive IP ranges. Both ends are required and must be IP addresses.
ipMatcheslist of strings[]IPLIKE patterns, such as 10.12.*.*.
locationstringnoneMonitoring location the definition applies to.
profileLabelstringnoneAdopt a profile. Must name a declared spec.profiles[].label.

A definition needs at least one selector: specifics, ranges or ipMatches. ipMatches cannot be combined with specifics or ranges in the same definition.

Fields of spec.trapd:

FieldTypeDefaultDescription
snmpTrapPortintegerrequiredUDP listen port, 1 to 65535.
newSuspectOnTrapbooleanrequiredCreate a suspect node for a trap from an unknown source.
snmpTrapAddressstringserver defaultListen address. * binds all interfaces.
includeRawMessagebooleanserver defaultKeep the raw trap PDU on the event.
useAddressFromVarbindbooleanserver defaultTake the source address from the trap varbinds when present.
threadsintegerserver defaultTrap-processing threads.
queueSizeintegerserver defaultProcessing queue size.
batchSizeintegerserver defaultMaximum traps per batch.
batchIntervalintegerserver defaultMaximum milliseconds to hold a partial batch.
snmpv3Userslist[]SNMPv3 users the trap daemon accepts. The full set.

The server rejects a trap-daemon update without snmpTrapPort or newSuspectOnTrap, so a bare trapd: {} fails validation.

Fields of a spec.trapd.snmpv3Users entry:

FieldTypeDefaultDescription
securityNamestringrequiredv3 user name. Must not be empty. Unique within the list.
securityLevelstringnonenoAuthNoPriv, authNoPriv or authPriv.
engineIdstringnoneEngine ID.
authProtocolstringnoneAuthentication protocol.
authPassphrasesecret referencenoneAuthentication passphrase.
privacyProtocolstringnonePrivacy protocol.
privacyPassphrasesecret referencenonePrivacy passphrase.
snmpv3Users replaces the whole list

Apply sends the declared users as the complete set. A user on the server that the list omits is removed. Omitting snmpv3Users from a present trapd block removes every trap user. Run snmp export first and carry the existing users over.

Secrets are write-only. A community or passphrase names exactly one source, the same shape as the User kind's passwordRef:

  • { fromFile: /run/secrets/snmp-ro } reads the file, minus one trailing newline.
  • { fromEnv: ONMS_SNMP_RO } reads the environment variable.
  • { fromKeyring: { service: onmsctl, account: snmp-auth } } reads the OS keyring entry.

An inline literal such as readCommunity: public fails the parse. A reference with two sources fails the parse. An empty resolved value fails the apply.

Apply​

onmsctl apply -f examples/snmp-config.yaml --dry-run --diff
onmsctl apply -f examples/snmp-config.yaml
onmsctl apply -f examples/snmp-config.yaml --force

Expected output:

$ onmsctl apply -f examples/snmp-config.yaml --dry-run --diff
snmp-config: whole-config replace via upload
defaults: changed
definitions: changed (0 deployed -> 2 desired)
profiles: changed (0 deployed -> 1 desired)

trapd: trap-daemon config update
port: 1162 -> 162
v3 users: 0 deployed -> 1 desired
+------------+---------+--------+---------+-----------------------------------------------+
| kind | name | action | status | message |
+=========================================================================================+
| SnmpConfig | default | update | Skipped | snmp-config would replace; trapd would update |
+------------+---------+--------+---------+-----------------------------------------------+
  • Apply reads the deployed config, compares it with the document, and re-uploads the whole config only when it differs.
  • A field the document omits is not compared. The server fills its default after a replace, so a minimal document stays in sync.
  • Removing a field from the document to fall back to the server default is not detected as a change.
  • Definitions and profiles compare as sets. Reordering them, or the selectors inside a definition, is no change.
  • Adding or removing a definition or profile is a change.
  • The upload replaces the whole snmp-config. A definition or profile the document omits is removed from the server.
  • Omitting spec.trapd leaves the trap daemon untouched.
  • The snmp-config half uploads first, then the trap-daemon half. There is no transaction across the two, so a trap-daemon failure leaves the snmp-config change in place.

Secrets and --force. Secrets are never compared, so a plain apply reports a secret-only change as in sync and uploads nothing. Pass --force to push a rotated secret: each in-sync half is re-sent with its resolved secrets. Without --force, new secrets go out with the next apply that also changes a non-secret field. Secrets resolve on the real apply only, so --dry-run does not detect a missing variable, file or keyring entry.

Plan gates: apply refuses more than one SnmpConfig document, and validates the document before any request. The Trapd version check fires only on the write: an older server returns 404 or 405 to the trap-daemon update. --dry-run does not detect it, because the plan reads a missing endpoint as an empty trap-daemon config.

Order: SnmpConfig applies after ThreshdPackage and before Requisition, so a co-located directory configures SNMP before importing nodes. An SNMP change does not rescan nodes already imported (Horizon behaviour). Follow with onmsctl requisition import <fs> --rescan-existing.

Diff​

--diff prints to stderr a secret-free summary per half that changes. A whole-config replace has no per-field patch, so the snmp-config half reports each tier and the definition and profile counts.

snmp-config: whole-config replace via upload
defaults: unchanged
definitions: changed (1 deployed -> 2 desired)
profiles: changed (0 deployed -> 1 desired)

trapd: trap-daemon config update
port: 162 -> 1162
v3 users: 2 deployed -> 1 desired

The port shows - when the server has no trap-daemon config yet. A half that is in sync prints nothing, unless --force re-sends it:

SnmpConfig/default: snmp-config unchanged apart from secrets; re-sent with its secrets (--force)

Inspect​

onmsctl snmp export -O snmp-config.yaml
onmsctl snmp lookup 192.168.8.8
onmsctl snmp lookup 192.168.8.8 10.0.0.5 --location labmonkeys-hq --show-secrets

Expected output:

$ onmsctl snmp export -O snmp-config.yaml
Exported snmp-config to snmp-config.yaml
$ onmsctl snmp lookup 192.168.8.8
+-------------+----------+---------+------+---------+---------+------------+---------+
| IP | LOCATION | VERSION | PORT | TIMEOUT | RETRIES | CREDENTIAL | PROFILE |
+====================================================================================+
| 192.168.8.8 | Default | v2c | 161 | 1800 | 1 | **** | - |
+-------------+----------+---------+------+---------+---------+------------+---------+
  • export writes the deployed config as a kind: SnmpConfig document, to stdout or to the file named by -O (--output-file).
  • export includes spec.trapd when the server exposes the trap-daemon config. A 404 leaves it out.
  • export writes each secret as a fromEnv placeholder, never cleartext. Each tier gets its own variable, such as SNMP_READ_COMMUNITY_DEFAULTS or SNMP_AUTH_PASSPHRASE_PROFILE_CORE_V3. Set them, or replace the references, before you apply the export.
  • lookup prints the effective parameters Horizon uses for each IP.
  • Without --location, lookup reports every location whose definition selector matches the IP, and falls back to Default when none match. A location matched only by a profile filterExpression needs --location.
  • lookup masks communities and passphrases unless you pass --show-secrets.

There is no delete verb.

Errors​

MessageProbable causeRecovery
kind: SnmpConfig is a singletonMore than one SnmpConfig document in the apply.Keep one document.
metadata.name must be "default"Any other name.Set metadata.name: default.
data did not match any variant of untagged enum SecretRefAn inline secret, or a reference with zero or two sources.Use exactly one of fromFile, fromEnv or fromKeyring.
has no selector; declare at least one ofA definition without specifics, ranges or ipMatches.Add a selector.
`ipMatches` cannot be combined with `specifics` or `ranges`One definition mixes IPLIKE patterns with addresses or ranges.Split it into two definitions.
invalid specific IPA specifics entry is not an IP address.Fix the address, or move a pattern to ipMatches.
invalid range begin / invalid range endA range end is not an IP address.Fix the address.
names no declared spec.profiles[].labelprofileLabel references an absent profile.Fix the label, or declare the profile.
spec.trapd.snmpTrapPort is requiredA trapd block without snmpTrapPort, such as trapd: {}.Set snmpTrapPort, or remove trapd.
spec.trapd.newSuspectOnTrap is requiredA trapd block without newSuspectOnTrap.Set newSuspectOnTrap.
spec.trapd.snmpTrapPort must be between 1 and 65535Port out of range.Use a valid UDP port.
securityName must not be emptyA trap user with an empty securityName.Name the user.
duplicate securityNameTwo trap users share a name.Keep one entry per user.
secret fromEnv: environment variable "<NAME>" is not setThe variable is missing on the real apply.Export the variable, then re-run.
resolved SNMP secret is empty; refusing to send an empty credentialThe file, variable or keyring entry is empty.Store the secret, then re-run.
does not expose the Trapd config REST APIThe server predates NMS-19128. The snmp-config half still applied.Remove spec.trapd, or upgrade the server.
snmp-config upload rejected by the serverThe server accepted the upload request but rejected its content.Read the reported detail, fix the document, and re-apply.

Example​

examples/snmp-config.yaml
# yaml-language-server: $schema=https://raw.githubusercontent.com/no42-org/onmsctl/main/schemas/snmp-config.schema.json
#
# kind: SnmpConfig. It holds the whole-server SNMP configuration as one
# declarative document (OpenSpec add-snmp-config-capability). It is a SINGLETON: there is
# one snmp-config per Horizon, so metadata.name is always `default`.
# `onmsctl apply -f` reconciles it by whole-config replace against
# /api/v2/snmp-config:
#
# onmsctl apply -f examples/snmp-config.yaml --dry-run --diff
#
apiVersion: snmp.opennms.org/v1
kind: SnmpConfig
metadata:
name: default
spec:
# Fallback parameters applied to any agent no definition matches.
defaults:
version: v2c
port: 161
timeout: 1800
retries: 1
# Secrets are NEVER inline. A literal string is rejected at parse time.
# Reference exactly one source: fromEnv / fromFile / fromKeyring. They are
# write-only: resolved at apply, never read back, and `snmp export` emits
# them as reference placeholders, never cleartext.
readCommunity: { fromEnv: ONMS_SNMP_READ_COMMUNITY }

# Named, reusable parameter templates. A definition adopts one by label.
profiles:
- label: core-v3
version: v3
securityName: monitor
securityLevel: authPriv # noAuthNoPriv | authNoPriv | authPriv
authProtocol: SHA
authPassphrase: { fromKeyring: { service: onmsctl, account: snmp-auth } }
privacyProtocol: AES
privacyPassphrase: { fromFile: /run/secrets/snmp-priv }
# Optional OpenNMS filter expression (evaluated server-side).
filterExpression: "categoryName == 'Routers'"

# Per-target overrides. Each definition needs at least one selector:
# `specifics` (exact IPs), `ranges` (begin/end), or `ipMatches` (IPLIKE).
# `ipMatches` cannot be combined with `specifics`/`ranges` in the same
# definition.
definitions:
- location: labmonkeys-hq
specifics: [192.168.8.8]
ranges:
- { begin: 10.0.0.1, end: 10.0.0.254 }
# Adopt a profile by its label (must name a declared spec.profiles[].label).
profileLabel: core-v3
- location: nyc-dc
ipMatches: ["10.12.*.*"]
version: v2c
readCommunity: { fromEnv: ONMS_SNMP_NYC_COMMUNITY }

# OPTIONAL: the SNMP trap daemon (Trapd) configuration, reconciled against
# /api/v2/trapd/config in the SAME apply. It is additive. Omit this block and
# apply/export never touch the Trapd endpoint (so older Horizon is unaffected).
#
# REQUIRES a Horizon build with the Trapd REST API (NMS-19128; the 37.x /
# develop line). Against an older server a present `trapd` block fails the
# trap-daemon half with a clear version message while the snmp-config half
# still applies. `snmpTrapPort` and `newSuspectOnTrap` are required.
trapd:
snmpTrapAddress: "*" # listen address; * = all interfaces
snmpTrapPort: 162
newSuspectOnTrap: false
includeRawMessage: false
useAddressFromVarbind: false
# Optional tuning. Omit to keep the server defaults.
# threads: 0
# queueSize: 10000
# batchSize: 1000
# batchInterval: 500
# SNMPv3 trap users (full-replace list: omitting a user removes it).
snmpv3Users:
- securityName: trap-monitor
securityLevel: authPriv # noAuthNoPriv | authNoPriv | authPriv
authProtocol: SHA
authPassphrase: { fromEnv: ONMS_TRAPD_AUTH_PASSPHRASE }
privacyProtocol: AES
privacyPassphrase: { fromKeyring: { service: onmsctl, account: trapd-priv } }