---
name: "snmpm_user"
section: "3erl"
platform: "linux"
package: "erlang-manpages"
version: "1:25.2.3+dfsg-1+deb12u4"
release: "Debian 12 (Bookworm)"
platforms: ["linux"]
url: "https://new.carta.tech/snmpm_user"
---

# snmpm\_user(3erl)

Behaviour module for the SNMP manager user.

## NAME

snmpm\_user - Behaviour module for the SNMP manager user.

## DESCRIPTION

This module defines the behaviour of the manager user. A *snmpm\_user* compliant module must export the following functions:

- \*

  handle\_error/3

- \*

  handle\_agent/4

- \*

  handle\_pdu/4

- \*

  handle\_trap/3

- \*

  handle\_inform/3

- \*

  handle\_report/3

- \*

  handle\_invalid\_result/2

The semantics of them and their exact signatures are explained below.

Some of the function has no defined return value (*void()*), they can of course return anything. But the functions that do have specified return value(s) *must* adhere to this. None of the functions can use exit of throw to return.

If the manager is not configured to use any particular transport domain, the behaviour *handle\_agent/4* will for backwards copmpatibility reasons be called with the old *IpAddr* and *PortNumber* arguments

## DATA TYPES

```
snmp_gen_info() = {ErrorStatus :: atom(),
                   ErrorIndex  :: pos_integer(),
                   Varbinds    :: [snmp:varbind()]}
snmp_v1_trap_info() :: {Enteprise :: snmp:oid(),
                        Generic   :: integer(),
                        Spec      :: integer(),
                        Timestamp :: integer(),
                        Varbinds  :: [snmp:varbind()]}
```

## EXPORTS

**handle\_error(ReqId, Reason, UserData) -\> void()**\

Types:

ReqId = netif \| integer()\
 Reason = {unexpected\_pdu, SnmpInfo} \| {invalid\_sec\_info, SecInfo, SnmpInfo} \| {empty\_message, Addr, Port} \| term()\
 SnmpInfo = snmp\_gen\_info()\
 SecInfo = term()\
 Addr = ip\_address()\
 Port = integer()\
 UserData = term()\

This function is called when the manager needs to communicate an "asynchronous" error to the user: e.g. failure to send an asynchronous message (i.e. encoding error), a received message was discarded due to security error, the manager failed to generate a response message to a received inform-request, or when receiving an unexpected PDU from an agent (could be an expired async request).

If *ReqId* is less then 0, it means that this information was not available to the manager (that info was never retrieved before the message was discarded).

For *SnmpInfo* see handle\_agent below.

Note that there is a special case when the value of *ReqId* has the value of the atom *netif*. This means that the NetIF process has suffered a "fatal" error and been restarted. With possible loss of traffic!

**handle\_agent(Domain, Addr, Type, SnmpInfo, UserData) -\> Reply**\

Types:

Domain = transportDomainUdpIpv4 \| transportDomainUdpIpv6\
 Addr = {inet:ip\_address(), inet:port\_number()} \
 Type = pdu \| trap \| report \| inform\
 SnmpInfo = SnmpPduInfo \| SnmpTrapInfo \| SnmpReportInfo \| SnmpInformInfo\
 SnmpPduInfo = snmp\_gen\_info()\
 SnmpTrapInfo = snmp\_v1\_trap\_info()\
 SnmpReportInfo = snmp\_gen\_info()\
 SnmpInformInfo = snmp\_gen\_info()\
 UserData = term()\
 Reply = ignore \| {register, UserId, TargetName, AgentConfig}\
 UserId = term()\
 TargetName = target\_name()\
 AgentConfig = \[agent\_config()\]\

This function is called when a message is received from an unknown agent.

Note that this will always be the default user that is called.

For more info about the *agent\_config()*, see register\_agent.

The arguments *Type* and *SnmpInfo* relates in the following way:

- \*

  *pdu* - *SnmpPduInfo* (see handle\_pdu for more info).

- \*

  *trap* - *SnmpTrapInfo* (see handle\_trap for more info).

- \*

  *report* - *SnmpReportInfo* (see handle\_report for more info).

- \*

  *inform* - *SnmpInformInfo* (see handle\_inform for more info).

The only user which would return *{register, UserId, TargetName, AgentConfig}* is the *default user*.

**handle\_pdu(TargetName, ReqId, SnmpPduInfo, UserData) -\> void()**\

Types:

TargetName = target\_name()\
 ReqId = term()\
 SnmpPduInfo = snmp\_gen\_info()\
 UserData = term()\

Handle the reply to an asynchronous request, such as async\_get, async\_get\_next or async\_set.

It could also be a late reply to a synchronous request.

*ReqId* is returned by the asynchronous request function.

**handle\_trap(TargetName, SnmpTrapInfo, UserData) -\> Reply**\

Types:

TargetName = TargetName2 = target\_name()\
 SnmpTrapInfo = snmp\_v1\_trap\_info() \| snmp\_gen\_info()\
 UserData = term()\
 Reply = ignore \| unregister \| {register, UserId, TargetName2, AgentConfig}\
 UserId = term()\
 AgentConfig = \[agent\_config()\]\

Handle a trap/notification message from an agent.

For more info about the *agent\_config()*, see register\_agent

The only user which would return *{register, UserId, TargetName2, agent\_info()}* is the *default user*.

**handle\_inform(TargetName, SnmpInformInfo, UserData) -\> Reply**\

Types:

TargetName = TargetName2 = target\_name()\
 SnmpInformInfo = snmp\_gen\_info()\
 UserData = term()\
 Reply = ignore \| no\_reply \| unregister \| {register, UserId, TargetName2, AgentConfig}\
 UserId = term()\
 AgentConfig = \[agent\_config()\]\

Handle a inform message.

For more info about the *agent\_config()*, see register\_agent

The only user which would return *{register, UserId, TargetName2, AgentConfig}* is the *default user*.

If the inform request behaviour configuration option is set to *user* or *{user, integer()}*, the response (acknowledgment) to this inform-request will be sent when this function returns.

**handle\_report(TargetName, SnmpReportInfo, UserData) -\> Reply**\

Types:

TargetName = TargetName2 = target\_name()\
 Addr = ip\_address()\
 Port = integer()\
 SnmpReportInfo = snmp\_gen\_info()\
 UserData = term()\
 Reply = ignore \| unregister \| {register, UserId, TargetName2, AgentConfig}\
 UserId = term()\
 AgentConfig = \[agent\_config()\]\

Handle a report message.

For more info about the *agent\_config()*, see register\_agent

The only user which would return *{register, UserId, TargetName2, AgentConfig}* is the *default user*.

**handle\_invalid\_result(IN, OUT) -\> void()**\

Types:

IN = {Func, Args}\
 Func = atom()\
 Args = list()\
 OUT = {crash, CrashInfo} \| {result, InvalidResult}\
 CrashInfo = {ErrorType, Error, Stacktrace}\
 ErrorType = atom()\
 Error = term()\
 Stacktrace = list()\
 InvalidResult = term()\

If *any* of the *other* callback functions crashes (exit, throw or a plain crash) or return an invalid result (if a valid return has been specified), this function is called. The purpose is to allow the user handle this error (for instance to issue an error report).

*IN* reprecents the function called (and its arguments). *OUT* represents the unexpected/invalid result.
