SnmpKit.SnmpMgr.Notify (snmpkit v2.0.1)

Sends SNMP notifications: v2c/v1 traps (fire and forget) and v2c informs (acknowledged by the receiver).

Reachable through SnmpKit.SNMP.send_trap/4 and SnmpKit.SNMP.send_inform/4. The counterpart that receives them is SnmpKit.Trap.

Trap OIDs and varbinds

trap_oid is an OID list, a dotted string, or a name known to the MIB registry ("linkDown", "coldStart", ...). Varbinds are {oid, type, value} tuples whose OID may likewise be a list, string or name. The mandatory sysUpTime.0 and snmpTrapOID.0 varbinds of an SNMPv2 notification are added for you.

Options

  • :community - default from SnmpKit.SnmpMgr.Config
  • :version - :v2c (default) or :v1; anything else (SNMPv3 notifications are not supported) is {:error, {:unsupported_operation, :notification_requires_v1_or_v2c}}
  • :uptime - sysUpTime in centiseconds; defaults to the VM's uptime
  • :timeout, :retries - inform acknowledgement wait (default 5000 ms, 1 retry)
  • :request_id - request id for v2c notifications; random by default

SNMPv1 traps carry different fields. They are derived from the trap OID per RFC 3584 (1.3.6.1.6.3.1.1.5.N becomes generic trap N - 1; anything else is enterprise-specific with the enterprise OID and specific trap taken from the OID) and can be overridden with :enterprise, :generic_trap, :specific_trap and :agent_addr (an IPv4 tuple, default {127, 0, 0, 1}).

Summary

Functions

Builds the message (%{version, community, pdu}) for a trap or inform without sending it. Useful for tests and for agents with their own socket.

Sends an inform and waits for the receiver's acknowledgement. Returns :ok on acknowledgement, {:error, :timeout} when none arrives within timeout: across retries: attempts.

Sends a trap to target (host, "host:port", or {host, port}; port defaults to 162). Returns :ok once the datagram is handed to the socket.

The BEAM's uptime in SNMP TimeTicks (centiseconds), used when no :uptime is given.

Types

varbind()

@type varbind() :: {term(), atom(), term()}

Functions

build_notification(kind, trap_oid, varbinds, opts \\ [])

@spec build_notification(:trap | :inform, term(), [varbind()], keyword()) ::
  {:ok, SnmpKit.SnmpLib.PDU.message()} | {:error, term()}

Builds the message (%{version, community, pdu}) for a trap or inform without sending it. Useful for tests and for agents with their own socket.

send_inform(target, trap_oid, varbinds \\ [], opts \\ [])

@spec send_inform(term(), term(), [varbind()], keyword()) :: :ok | {:error, term()}

Sends an inform and waits for the receiver's acknowledgement. Returns :ok on acknowledgement, {:error, :timeout} when none arrives within timeout: across retries: attempts.

send_trap(target, trap_oid, varbinds \\ [], opts \\ [])

@spec send_trap(term(), term(), [varbind()], keyword()) :: :ok | {:error, term()}

Sends a trap to target (host, "host:port", or {host, port}; port defaults to 162). Returns :ok once the datagram is handed to the socket.

vm_uptime_ticks()

@spec vm_uptime_ticks() :: non_neg_integer()

The BEAM's uptime in SNMP TimeTicks (centiseconds), used when no :uptime is given.