ct_snmp(3erl)
π NAME β ct_snmp(3erl) π
ct_snmp is the Common Test user interface module for the SNMP application. Thatβs the whole NAME vibe, bestie β now letβs get into it. π«Ά
β¨ DESCRIPTION β¨
Okay so hereβs the tea: the whole point of this module is to simplify SNMP configuration for the test case writer. π
Many test cases can use default values for common operations, and then no SNMP configuration files need to be supplied. When it is necessary to change particular configuration parameters, a subset of the relevant SNMP configuration files can be passed to ct_snmp by Common Test configuration files. For more specialized configuration parameters, a simple SNMP configuration file can be placed in the test suite data directory. To simplify the test suite, Common Test keeps track of some of the SNMP manager information. This way the test suite does not have to handle as many input parameters as if it had to interface with the OTP SNMP manager directly. π
ποΈ Configurable SNMP Manager and Agent Parameters ποΈ
π§βπ» Manager configuration π§βπ»
{start_manager, boolean()}β Optional. Default istrue.{users, [{user_name(), [call_back_module(), user_data()]}]}β Optional.{usm_users, [{usm_user_name(), [usm_config()]}]}β Optional. SNMPv3 only.{managed_agents,[{agent_name(), [user_name(), agent_ip(), agent_port(), [agent_config()]]}]}βmanaged_agentsis optional.{max_msg_size, integer()}β Optional. Default is484.{mgr_port, integer()}β Optional. Default is5000.{engine _id, string()}β Optional. Default is"mgrEngine".
π€ Agent configuration π€
{start_agent, boolean()}β Optional. Default isfalse.{agent_sysname, string()}β Optional. Default is"ct_test".{agent_manager_ip, manager_ip()}β Optional. Default is localhost.{agent_vsns, list()}β Optional. Default is[v2].{agent_trap_udp, integer()}β Optional. Default is5000.{agent_udp, integer()}β Optional. Default is4000.{agent_notify_type, atom()}β Optional. Default istrap.{agent_sec_type, sec_type()}β Optional. Default isnone.{agent_passwd, string()}β Optional. Default is"".{agent_engine_id, string()}β Optional. Default is"agentEngine".{agent_max_msg_size, string()}β Optional. Default is484.
The following parameters represent the SNMP configuration files context.conf, standard.conf, community.conf, vacm.conf, usm.conf, notify.conf, target_addr.conf, and target_params.conf. Notice that all values in agent.conf can be modified by the parameters listed above. All these configuration files have default values set by the SNMP application. These values can be overridden by supplying a list of valid configuration values or a file located in the test suiteβs data directory, which can produce a list of valid configuration values if you apply function file:consult/1 to the file. π
{agent_contexts, [term()] | {data_dir_file, rel_path()}}β Optional.{agent_community, [term()] | {data_dir_file, rel_path()}}β Optional.{agent_sysinfo, [term()] | {data_dir_file, rel_path()}}β Optional.{agent_vacm, [term()] | {data_dir_file, rel_path()}}β Optional.{agent_usm, [term()] | {data_dir_file, rel_path()}}β Optional.{agent_notify_def, [term()] | {data_dir_file, rel_path()}}β Optional.{agent_target_address_def, [term()] | {data_dir_file, rel_path()}}β Optional.{agent_target_param_def, [term()] | {data_dir_file, rel_path()}}β Optional.
Parameter MgrAgentConfName in the functions is to be a name you allocate in your test suite using a require statement. Example, where MgrAgentConfName = snmp_mgr_agent:
suite() -> [{require, snmp_mgr_agent, snmp}].
or
ct:require(snmp_mgr_agent, snmp).
π Heads up, bestie: USM users are needed for SNMPv3 configuration and are not to be confused with users.
SNMP traps, inform, and report messages are handled by the user callback module. For details, see the SNMP application. π¦
It is recommended to use the .hrl files created by the Erlang/OTP MIB compiler to define the Object Identifiers (OIDs). For example, to get the Erlang node name from erlNodeTable in the OTP-MIB:
Oid = ?erlNodeEntry ++ [?erlNodeName, 1]
Furthermore, values can be set for SNMP application configuration parameters, config, server, net_if, and so on (for a list of valid parameters and types, see the Userβs Guide for the SNMP application). This is done by defining a configuration data variable on the following form:
{snmp_app, [{manager, [snmp_app_manager_params()]},
{agent, [snmp_app_agent_params()]}]}.
A name for the data must be allocated in the suite using require (see the example above). Pass this name as argument SnmpAppConfName to ct_snmp:start/3. ct_snmp specifies default values for some SNMP application configuration parameters (such as {verbosity,trace} for parameter config). This set of defaults is merged with the parameters specified by the user. The user values override ct_snmp defaults. π
π§ DATA TYPES π§
Type buffet, served exact β no cap:
agent_config() = {Item, Value}
agent_ip() = ip()
agent_name() = atom()
agent_port() = integer()
call_back_module() = atom()
error_index() = integer()
error_status() = noError | atom()
ip() = string() | {integer(), integer(), integer(), integer()}
manager_ip() = ip()
oid() = [byte()]
oids() = [oid()]
rel_path() = string()
sec_type() = none | minimum | semi
snmp_app_agent_params() = term()
snmp_app_manager_params() = term()
snmpreply() = {error_status(), error_index(), varbinds()}
user_data() = term()
user_name() = atom()
usm_config() = {Item, Value}
usm_user_name() = string()
value_type() = o('OBJECT IDENTIFIER') | i('INTEGER') | u('Unsigned32') | g('Unsigned32') | s('OCTET STRING')
var_and_val() = {oid(), value_type(), value()}
varbind() = term()
varbinds() = [varbind()]
varsandvals() = [var_and_val()]
These data types are described in the documentation for the SNMP application. π«Ά
β¨ EXPORTS β¨
Ok bestie, this is the part where we actually do stuff π Every function here is a little sync'd-up request or a config move, and yes, the types are all listed so you never have to guess. Let's go π«Ά
get_next_values(Agent, Oids, MgrAgentConfName) -> SnmpReply
Types:
Agent = agent_name()
Oids = oids()
MgrAgentConfName = atom()
SnmpReply = snmpreply()
Issues a synchronous SNMP get next request. That's it, that's the whole vibe β it fires off the request and waits, no cap πΈ
get_values(Agent, Oids, MgrAgentConfName) -> SnmpReply
Types:
Agent = agent_name()
Oids = oids()
MgrAgentConfName = atom()
SnmpReply = snmpreply()
Issues a synchronous SNMP get request. Same synchronous energy, just a plain get instead of a get next π
load_mibs(Mibs) -> ok | {error, Reason}
Types:
Mibs = [MibName]
MibName = string()
Reason = term()
Loads the MIBs into agent snmp_master_agent. Like, the agent's whole thing is MIBs and you're feeding it π§
register_agents(MgrAgentConfName, ManagedAgents) -> ok | {error, Reason}
Types:
MgrAgentConfName = atom()
ManagedAgents = [agent()]
Reason = term()
Explicitly instructs the manager to handle this agent. Corresponds to making an entry in agents.conf π
This function tries to register the specified managed agents, without checking if any of them exist. To change a registered managed agent, the agent must first be unregistered. So yeah β unregister first, then re-register. Don't skip that step, bestie π
register_users(MgrAgentConfName, Users) -> ok | {error, Reason}
Types:
MgrAgentConfName = atom()
Users = [user()]
Reason = term()
Registers the manager entity (=user) responsible for specific agent(s). Corresponds to making an entry in users.conf π
This function tries to register the specified users, without checking if any of them exist. To change a registered user, the user must first be unregistered. Same rule as above, fr fr π
register_usm_users(MgrAgentConfName, UsmUsers) -> ok | {error, Reason}
Types:
MgrAgentConfName = atom()
UsmUsers = [usm_user()]
Reason = term()
Explicitly instructs the manager to handle this USM user. Corresponds to making an entry in usm.conf π₯
This function tries to register the specified users, without checking if any of them exist. To change a registered user, the user must first be unregistered. (Yes, it's the same caveat a third time β the pattern is real π)
set_info(Config) -> [{Agent, OldVarsAndVals, NewVarsAndVals}]
Types:
Config = [{Key, Value}]
Agent = agent_name()
OldVarsAndVals = varsandvals()
NewVarsAndVals = varsandvals()
Returns a list of all successful set requests performed in the test case, in reverse order. The list contains the involved user and agent, the value before set, and the new value π
This is intended to simplify the cleanup in function end_per_testcase β that is, the undoing of the set requests and their possible side-effects. Honestly kind of iconic of it to hand you the receipts so you can undo everything later π§Ύβ¨
set_values(Agent, VarsAndVals, MgrAgentConfName, Config) -> SnmpReply
Types:
Agent = agent_name()
Oids = oids()
MgrAgentConfName = atom()
Config = [{Key, Value}]
SnmpReply = snmpreply()
Issues a synchronous SNMP set request. Set it and wait for the reply, periodt π
start(Config, MgrAgentConfName) -> ok
Equivalent to ct_snmp:start(Config, MgrAgentConfName, undefined). Shorthand! Cute! π
start(Config, MgrAgentConfName, SnmpAppConfName) -> ok
Types:
Config = [{Key, Value}]
Key = atom()
Value = term()
MgrAgentConfName = atom()
SnmpConfName = atom()
Starts an SNMP manager and/or agent. In the manager case, registrations of users and agents, as specified by the configuration MgrAgentConfName, are performed. When using SNMPv3, called USM users are also registered π―ββοΈ
Users, usm_users, and managed agents can also be registered later using ct_snmp:register_users/2, ct_snmp:register_agents/2, and ct_snmp:register_usm_users/2. So you don't have to do it all up front, no pressure π
The agent started is called snmp_master_agent. Use ct_snmp:load_mibs/1 to load MIBs into the agent. (Main character agent, honestly π)
With SnmpAppConfName SNMP applications can be configured with parameters config, mibs, net_if, and so on. The values are merged with (and possibly override) default values set by ct_snmp. So your settings can absolutely swoop in and take over the defaults πβ¨
stop(Config) -> ok
Types:
Config = [{Key, Value}]
Key = atom()
Value = term()
Stops the SNMP manager and/or agent, and removes all files created. Clean slate, no leftovers, we love a tidy queen π§Ήπ
unload_mibs(Mibs) -> ok | {error, Reason}
Types:
Mibs = [MibName]
MibName = string()
Reason = term()
Unloads the MIBs from agent snmp_master_agent. Reverse of load, obviously π¦
unregister_agents(MgrAgentConfName) -> ok
Types:
MgrAgentConfName = atom()
Reason = term()
Unregisters all managed agents. All of them. Gone. Bye π
unregister_agents(MgrAgentConfName, ManagedAgents) -> ok
Types:
MgrAgentConfName = atom()
ManagedAgents = [agent_name()]
Reason = term()
Unregisters the specified managed agents. Just the ones you list β surgical π
unregister_users(MgrAgentConfName) -> ok
Types:
MgrAgentConfName = atom()
Reason = term()
Unregisters all users. Everyone out πΈ
unregister_users(MgrAgentConfName, Users) -> ok
Types:
MgrAgentConfName = atom()
Users = [user_name()]
Reason = term()
Unregisters the specified users. Only the named ones π
unregister_usm_users(MgrAgentConfName) -> ok
Types:
MgrAgentConfName = atom()
Reason = term()
Unregisters all USM users. Full clear-out π₯
unregister_usm_users(MgrAgentConfName, UsmUsers) -> ok
Types:
MgrAgentConfName = atom()
UsmUsers = [usm_user_name()]
Reason = term()
Unregisters the specified USM users. Pick and choose, bestie β¨
Lowkey the whole theme of this page: register stuff explicitly, and unregister before you re-register. The manpage says it three separate times so you know it matters ππ
And that's the whole page, bestie β you ate that πβ¨ Written by Ericsson AB, this is common_test 1.24.0.1, and you're reading ct_snmp(3erl). Go forth and SNMP responsibly π
π«Ά
π¦ where this page comes from
- ubuntu noble: erlang-manpages 1:25.3.2.8+dfsg-1ubuntu4 Β· Apache-2.0
- ubuntu noble: erlang-manpages 1:25.3.2.8+dfsg-1ubuntu4.8 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms