Erlang -- snmp

User's Guide
Reference Manual
Release Notes
PDF
Top

Simple Network Management Protocol (SNMP)
Reference Manual
Version 4.22.1

Expand All
Contract All

Table of Contents

- snmp
  - Top of manual page
  - config/0
  - start/0
  - start/1
  - start_agent/0
  - start_agent/1
  - start_manager/0
  - start_manager/1
  - date_and_time/0
  - date_and_time_to_universal_time_dst/1
  - date_and_time_to_string/1
  - date_and_time_to_string/2
  - date_and_time_to_string2/1
  - local_time_to_date_and_time_dst/1
  - universal_time_to_date_and_time/1
  - validate_date_and_time/1
  - validate_date_and_time/2
  - passwd2localized_key/3
  - octet_string_to_bits/1
  - bits_to_octet_string/1
  - read_mib/1
  - log_to_txt/5
  - log_to_txt/6
  - log_to_txt/7
  - log_to_io/4
  - log_to_io/5
  - log_to_io/6
  - change_log_size/2
  - print_version_info/0
  - print_version_info/1
  - versions1/0
  - versions2/0
  - print_versions/1
  - print_versions/2
  - enable_trace/0
  - disable_trace/0
  - set_trace/1
  - reset_trace/1
  - set_trace/2
- snmp (App)
- snmpa
  - Top of manual page
  - add_agent_caps/2
  - del_agent_caps/1
  - get_agent_caps/0
  - get/2
  - get/3
  - get_next/2
  - get_next/3
  - backup/1
  - backup/2
  - info/0
  - info/1
  - old_info_format/1
  - load_mibs/1
  - load_mibs/2
  - unload_mibs/1
  - unload_mibs/2
  - which_mibs/0
  - which_mibs/1
  - whereis_mib/1
  - whereis_mib/2
  - current_request_id/0
  - current_context/0
  - current_community/0
  - current_address/0
  - enum_to_int/2
  - enum_to_int/3
  - int_to_enum/2
  - int_to_enum/3
  - name_to_oid/1
  - name_to_oid/2
  - oid_to_name/1
  - oid_to_name/2
  - which_aliasnames/0
  - which_tables/0
  - which_variables/0
  - which_notifications/0
  - log_to_txt/1
  - log_to_txt/2
  - log_to_txt/3
  - log_to_txt/4
  - log_to_txt/5
  - log_to_txt/6
  - log_to_txt/7
  - log_to_io/1
  - log_to_io/2
  - log_to_io/3
  - log_to_io/4
  - log_to_io/5
  - log_to_io/6
  - change_log_size/1
  - set_log_type/1
  - set_log_type/2
  - mib_of/1
  - mib_of/2
  - me_of/1
  - me_of/2
  - invalidate_mibs_cache/0
  - invalidate_mibs_cache/1
  - enable_mibs_cache/0
  - enable_mibs_cache/1
  - disable_mibs_cache/0
  - disable_mibs_cache/1
  - which_mibs_cache_size/0
  - which_mibs_cache_size/1
  - gc_mibs_cache/0
  - gc_mibs_cache/1
  - gc_mibs_cache/1
  - gc_mibs_cache/2
  - gc_mibs_cache/2
  - gc_mibs_cache/3
  - enable_mibs_cache_autogc/0
  - enable_mibs_cache_autogc/1
  - disable_mibs_cache_autogc/0
  - disable_mibs_cache_autogc/1
  - update_mibs_cache_age/1
  - update_mibs_cache_age/2
  - update_mibs_cache_gclimit/1
  - update_mibs_cache_gclimit/2
  - register_notification_filter/3
  - register_notification_filter/4
  - register_notification_filter/4
  - register_notification_filter/5
  - unregister_notification_filter/1
  - unregister_notification_filter/2
  - which_notification_filter/0
  - which_notification_filter/1
  - set_request_limit/1
  - set_request_limit/2
  - register_subagent/3
  - unregister_subagent/2
  - send_notification2/3
  - send_notification/3
  - send_notification/4
  - send_notification/5
  - send_notification/6
  - send_notification/7
  - discovery/2
  - discovery/3
  - discovery/3
  - discovery/4
  - discovery/4
  - discovery/5
  - discovery/6
  - convert_config/1
  - restart_worker/0
  - restart_worker/1
  - restart_set_worker/0
  - restart_set_worker/1
  - print_mib_info/0
  - print_mib_tables/0
  - print_mib_variables/0
  - verbosity/2
- snmpa_conf
  - Top of manual page
  - agent_entry/2
  - write_agent_config/2
  - write_agent_config/3
  - append_agent_config/2
  - read_agent_config/1
  - standard_entry/2
  - write_standard_config/2
  - write_standard_config/3
  - append_standard_config/2
  - read_standard_config/1
  - context_entry/1
  - write_context_config/2
  - write_context_config/3
  - append_context_config/2
  - read_context_config/1
  - community_entry/1
  - community_entry/5
  - write_community_config/2
  - write_community_config/3
  - append_community_config/2
  - read_community_config/1
  - target_addr_entry/5
  - target_addr_entry/6
  - target_addr_entry/8
  - target_addr_entry/10
  - target_addr_entry/11
  - write_target_addr_config/2
  - write_target_addr_config/3
  - append_target_addr_config/2
  - read_target_addr_config/1
  - target_params_entry/2
  - target_params_entry/4
  - target_params_entry/5
  - write_target_params_config/2
  - write_target_params_config/3
  - append_target_params_config/2
  - read_target_params_config/1
  - vacm_s2g_entry/3
  - vacm_acc_entry/8
  - vacm_vtf_entry/2
  - vacm_vtf_entry/4
  - write_vacm_config/2
  - write_vacm_config/3
  - append_vacm_config/2
  - read_vacm_config/1
  - usm_entry/1
  - usm_entry/13
  - write_usm_config/2
  - write_usm_config/3
  - append_usm_config/2
  - read_usm_config/1
  - notify_entry/3
  - write_notify_config/2
  - write_notify_config/3
  - append_notify_config/2
  - read_notify_config/1
- snmpa_discovery_handler
  - Top of manual page
  - stage1_finish/3
- snmpa_error_report
  - Top of manual page
  - config_err/2
  - user_err/2
- snmpa_error
  - Top of manual page
  - config_err/2
  - user_err/2
- snmpa_error_io
  - Top of manual page
  - config_err/2
  - user_err/2
- snmpa_error_logger
  - Top of manual page
  - config_err/2
  - user_err/2
- snmpa_local_db
  - Top of manual page
  - dump/0
  - match/2
  - print/0
  - print/1
  - print/2
  - table_create/1
  - table_create_row/3
  - table_delete/1
  - table_delete_row/2
  - table_exists/1
  - table_get_row/2
- snmpa_mpd
  - Top of manual page
  - init/1
  - process_packet/6
  - process_packet/7
  - generate_response_msg/5
  - generate_response_msg/6
  - generate_msg/5
  - generate_msg/6
  - discarded_pdu/1
- snmpa_network_interface
  - Top of manual page
  - start_link/4
  - info/1
  - verbosity/2
  - get_log_type/1
  - set_log_type/2
- snmpa_network_interface_filter
  - Top of manual page
  - accept_recv/2
  - accept_send/2
  - accept_recv_pdu/3
  - accept_send_pdu/2
- snmpa_notification_delivery_info_receiver
  - Top of manual page
  - delivery_targets/3
  - delivery_info/4
- snmpa_notification_filter
  - Top of manual page
  - handle_notification/2
- snmpa_supervisor
  - Top of manual page
  - start_sub_sup/1
  - start_master_sup/1
  - start_sub_agent/3
  - stop_sub_agent/1
- snmp_community_mib
  - Top of manual page
  - configure/1
  - reconfigure/1
  - add_community/5
  - add_community/6
  - delete_community/1
- snmp_framework_mib
  - Top of manual page
  - configure/1
  - init/0
  - add_context/1
  - delete_context/1
- snmp_generic
  - Top of manual page
  - get_status_col/2
  - get_status_col/2
  - get_index_types/1
  - get_table_info/2
  - table_func/2
  - table_func/4
  - table_get_elements/3
  - table_next/2
  - table_row_exists/2
  - table_set_elements/3
  - variable_func/2
  - variable_func/3
  - variable_get/1
  - variable_set/2
- snmp_index
  - Top of manual page
  - delete/1
  - delete/2
  - get/2
  - get_last/1
  - get_next/2
  - insert/3
  - key_to_oid/2
  - new/1
- snmp_notification_mib
  - Top of manual page
  - configure/1
  - reconfigure/1
  - add_notify/3
  - delete_notify/1
- snmp_pdus
  - Top of manual page
  - dec_message/1
  - dec_message_only/1
  - dec_pdu/1
  - dec_scoped_pdu/1
  - dec_scoped_pdu_data/1
  - dec_usm_security_parameters/1
  - enc_encrypted_scoped_pdu/1
  - enc_message/1
  - enc_message_only/1
  - enc_pdu/1
  - enc_scoped_pdu/1
  - enc_usm_security_parameters/1
- snmp_standard_mib
  - Top of manual page
  - configure/1
  - inc/1
  - inc/2
  - reconfigure/1
  - reset/0
  - sys_up_time/0
- snmp_target_mib
  - Top of manual page
  - configure/1
  - reconfigure/1
  - set_target_engine_id/2
  - add_addr/10
  - add_addr/11
  - delete_addr/1
  - add_params/5
  - delete_params/1
- snmp_user_based_sm_mib
  - Top of manual page
  - configure/1
  - reconfigure/1
  - add_user/13
  - delete_user/1
- snmp_view_based_acm_mib
  - Top of manual page
  - configure/1
  - reconfigure/1
  - add_sec2group/3
  - delete_sec2group/1
  - add_access/8
  - delete_access/1
  - add_view_tree_fam/4
  - delete_view_tree_fam/1
- snmpc
  - Top of manual page
  - compile/1
  - compile/2
  - is_consistent/1
  - mib_to_hrl/1
- snmpc(command)
- snmpm
  - Top of manual page
  - monitor/0
  - demonitor/1
  - notify_started/1
  - cancel_notify_started/1
  - register_user/3
  - register_user/4
  - register_user_monitor/3
  - register_user_monitor/4
  - unregister_user/1
  - which_users/0
  - register_agent/3
  - unregister_agent/2
  - agent_info/2
  - update_agent_info/3
  - update_agent_info/4
  - which_agents/0
  - which_agents/1
  - register_usm_user/3
  - unregister_usm_user/2
  - usm_user_info/3
  - update_usm_user_info/4
  - which_usm_users/0
  - which_usm_users/1
  - sync_get2/3
  - sync_get2/4
  - sync_get/3
  - sync_get/4
  - sync_get/4
  - sync_get/5
  - sync_get/6
  - async_get2/3
  - async_get2/4
  - async_get/3
  - async_get/4
  - async_get/4
  - async_get/5
  - async_get/6
  - sync_get_next2/3
  - sync_get_next2/4
  - sync_get_next/3
  - sync_get_next/4
  - sync_get_next/4
  - sync_get_next/5
  - sync_get_next/6
  - async_get_next2/3
  - async_get_next2/4
  - async_get_next/3
  - async_get_next/4
  - async_get_next/4
  - async_get_next/5
  - async_get_next/6
  - sync_set2/3
  - sync_set2/4
  - sync_set/3
  - sync_set/4
  - sync_set/4
  - sync_set/5
  - sync_set/6
  - async_set2/3
  - async_set2/4
  - async_set/3
  - async_set/4
  - async_set/4
  - async_set/5
  - async_set/6
  - sync_get_bulk2/5
  - sync_get_bulk2/6
  - sync_get_bulk/5
  - sync_get_bulk/6
  - sync_get_bulk/6
  - sync_get_bulk/7
  - sync_get_bulk/8
  - async_get_bulk2/5
  - async_get_bulk2/6
  - async_get_bulk/5
  - async_get_bulk/6
  - async_get_bulk/6
  - async_get_bulk/7
  - async_get_bulk/8
  - cancel_async_request/2
  - log_to_txt/2
  - log_to_txt/3
  - log_to_txt/4
  - log_to_txt/5
  - log_to_txt/6
  - log_to_txt/7
  - log_to_io/1
  - log_to_io/2
  - log_to_io/2
  - log_to_io/3
  - log_to_io/4
  - log_to_io/5
  - log_to_io/6
  - change_log_size/1
  - set_log_type/1
  - load_mib/1
  - unload_mib/1
  - which_mibs/0
  - name_to_oid/1
  - oid_to_name/1
  - oid_to_type/1
  - backup/1
  - info/0
  - verbosity/2
  - format_reason/1
  - format_reason/2
- snmpm_conf
  - Top of manual page
  - manager_entry/2
  - write_manager_config/2
  - write_manager_config/3
  - append_manager_config/2
  - read_manager_config/1
  - users_entry/1
  - users_entry/2
  - users_entry/3
  - write_users_config/2
  - write_users_config/3
  - append_users_config/2
  - read_users_config/1
  - agents_entry/12
  - write_agents_config/2
  - write_agents_config/3
  - append_agents_config/2
  - read_agents_config/1
  - usm_entry/6
  - usm_entry/7
  - write_usm_config/2
  - write_usm_config/3
  - append_usm_config/2
  - read_usm_config/1
- snmpm_mpd
  - Top of manual page
  - init_mpd/1
  - process_msg/7
  - generate_msg/5
  - generate_response_msg/4
- snmpm_network_interface
  - Top of manual page
  - start_link/2
  - stop/1
  - send_pdu/7
  - inform_response/4
  - note_store/2
  - info/1
  - verbosity/2
  - get_log_type/1
  - set_log_type/2
- snmpm_user
  - Top of manual page
  - handle_error/3
  - handle_agent/5
  - handle_pdu/4
  - handle_trap/3
  - handle_inform/3
  - handle_report/3
- snmpm_network_interface_filter
  - Top of manual page
  - accept_recv/2
  - accept_send/2
  - accept_recv_pdu/3
  - accept_send_pdu/3

# snmp

### MODULE

snmp

### MODULE SUMMARY

Interface functions to the SNMP toolkit

### DESCRIPTION

The module snmp contains interface functions to the SNMP toolkit.

### Common Data Types

The following data-types are used in the functions below:

- datetime() = {date(), time()}

  See calendar for more info.

### EXPORTS

config() -> ok | {error, Reason}

A simple interactive configuration tool. Simple configuration files can be generated, but more complex configurations still have to be edited manually.

The tool is a textual based tool that asks some questions and generates sys.config and *.conf files.

Note that if the application shall support version 3, then the crypto app must be started before running this function (password generation).

Note also that some of the configuration files for the agent and manager share the same names. This means that they have to be stored in different directories!

start() -> ok | {error, Reason}
start(Type) -> ok | {error, Reason}

Types:

Type = start_type()

Starts the SNMP application.

See application for more info.

start_agent() -> ok | {error, Reason}
start_agent(Type) -> ok | {error, Reason}

Types:

Type = start_type()

The SNMP application consists of several entities, of which the agent is one. This function starts the agent entity of the application.

Note that the only way to actually start the agent in this way is to add the agent related config after starting the application (e.g it cannot be part of the normal application config; sys.config). This is done by calling: application:set_env(snmp, agent, Conf).

The default value for Type is normal.

start_manager() -> ok | {error, Reason}
start_manager(Type) -> ok | {error, Reason}

Types:

Type = start_type()

The SNMP application consists of several entities, of which the manager is one. This function starts the manager entity of the application.

Note that the only way to actually start the manager in this way is to add the manager related config after starting the application (e.g it cannot be part of the normal application config; sys.config). This is done by calling: application:set_env(snmp, manager, Conf).

The default value for Type is normal.

date_and_time() -> DateAndTime

Types:

DateAndTime = [int()]

Returns current date and time as the data type DateAndTime, as specified in RFC1903. This is an OCTET STRING.

date_and_time_to_universal_time_dst(DateAndTime) -> [utc()]

Types:

DateAndTime = [int()]
utc() = {{Y,Mo,D},{H,M,S}}

Converts a DateAndTime list to a list of possible universal time(s). The universal time value on the same format as defined in calendar(3).

date_and_time_to_string(DateAndTime) -> string()
date_and_time_to_string(DateAndTime, Validate) -> string()

Types:

DateAndTime = [int()]
Validate = fun(Kind, Data) -> boolean()

Converts a DateAndTime list to a printable string, according to the DISPLAY-HINT definition in RFC2579.

The validation fun, Validate, allows for a more "flexible" validation of the DateAndTime argument. Whenever the data is found to not follow RFC2579, the fun is called to allow a more "lax" validation. See the validate_date_and_time/2 function for more info on the Validate fun.

date_and_time_to_string2(DateAndTime) -> string()

Types:

DateAndTime = [int()]

Converts a DateAndTime list to a printable string, according to the DISPLAY-HINT definition in RFC2579, with the extension that it also allows the values "hours from UTC" = 14 together with "minutes from UTC" = 0.

local_time_to_date_and_time_dst(Local) -> [DateAndTime]

Types:

Local = {{Y,Mo,D},{H,M,S}}
DateAndTime = [int()]

Converts a local time value to a list of possible DateAndTime list(s). The local time value on the same format as defined in calendar(3).

universal_time_to_date_and_time(UTC) -> DateAndTime

Types:

UTC = {{Y,Mo,D},{H,M,S}}
DateAndTime = [int()]

Converts a universal time value to a DateAndTime list. The universal time value on the same format as defined in calendar(3).

validate_date_and_time(DateAndTime) -> bool()
validate_date_and_time(DateAndTime, Validate) -> bool()

Types:

DateAndTime = term()
Validate = fun(Kind, Data) -> boolean()

Checks if DateAndTime is a correct DateAndTime value, as specified in RFC2579. This function can be used in instrumentation functions to validate a DateAndTime value.

The validation fun, Validate, allows for a more "flexible" validation of the DateAndTime argument. Whenever the data is found to not follow RFC2579, the fun is called to allow a more "lax" validation. The input to the validation fun looks like this:

              Kind             Data
              --------------   ----------------------
              year             {Year1, Year2}
              month            Month
              day              Day
              hour             Hour
              minute           Minute
              seconds          Seconds
              deci_seconds     DeciSeconds
              diff             [Sign, Hour, Minute]
              valid_date       {Year, Month, Day}

passwd2localized_key(Alg, Passwd, EngineID) -> Key

Types:

Alg = algorithm()
algorithm() = md5 | sha
Passwd = string()
EngineID = string()
Key = list()

Generates a key that can be used as an authentication or privacy key using MD5 och SHA. The key is localized for EngineID.

octet_string_to_bits(S) -> Val

Types:

Val = bits()

Utility function for converting a value of type OCTET-STRING to BITS.

bits_to_octet_string(B) -> Val

Types:

Val = octet_string()

Utility function for converting a value of type BITS to OCTET-STRING.

read_mib(FileName) -> {ok, mib()} | {error, Reason}

Types:

FileName = string()
mib() = #mib{}
Reason = term()

Read a compiled mib.

log_to_txt(LogDir, Mibs, OutFile, LogName, LogFile) -> ok | {error, Reason}
log_to_txt(LogDir, Mibs, OutFile, LogName, LogFile, Start) -> ok | {error, Reason}
log_to_txt(LogDir, Mibs, OutFile, LogName, LogFile, Start, Stop) -> ok | {error, Reason}

Types:

LogDir = string()
Mibs = [MibName]
OutFile = string()
MibName = string()
LogName = string()
LogFile = string()
Start = Stop = null | datetime() | {local_time,datetime()} | {universal_time,datetime()}
Reason = term()

Converts an Audit Trail Log to a readable text file, where each item has a trailing TAB character, and any TAB character in the body of an item has been replaced by ESC TAB.

The function can be used on a running system, or by copying the entire log directory and calling this function. SNMP must be running in order to provide MIB information.

LogDir is the name of the directory where the audit trail log is stored. Mibs is a list of Mibs to be used. The function uses the information in the Mibs to convert for example object identifiers to their symbolic name. OutFile is the name of the generated text-file. LogName is the name of the log, LogFile is the name of the log file. Start is the start (first) date and time from which log events will be converted and Stop is the stop (last) date and time to which log events will be converted.

The format of an audit trail log text item is as follows:

Tag Addr - Community [TimeStamp] Vsn
PDU

where Tag is request, response, report, trap or inform; Addr is IP:Port (or comma space separated list of such); Community is the community parameter (SNMP version v1 and v2), or SecLevel:"AuthEngineID":"UserName" (SNMP v3); TimeStamp is a date and time stamp, and Vsn is the SNMP version. PDU is a textual version of the protocol data unit. There is a new line between Vsn and PDU.

log_to_io(LogDir, Mibs, LogName, LogFile) -> ok | {error, Reason}
log_to_io(LogDir, Mibs, LogName, LogFile, Start) -> ok | {error, Reason}
log_to_io(LogDir, Mibs, LogName, LogFile, Start, Stop) -> ok | {error, Reason}

Types:

LogDir = string()
Mibs = [MibName]
MibName = string()
LogName = string()
LogFile = string()
Start = Stop = null | datetime() | {local_time,datetime()} | {universal_time,datetime()}
Reason = term()

Converts an Audit Trail Log to a readable format and prints it on stdio. See log_to_txt above for more info.

change_log_size(LogName, NewSize) -> ok | {error, Reason}

Types:

LogName = string()
NewSize = {MaxBytes, MaxFiles}
MaxBytes = integer()
MaxFiles = integer()
Reason = term()

Changes the log size of the Audit Trail Log. The application must be configured to use the audit trail log function. Please refer to disk_log(3) in Kernel Reference Manual for a description of how to change the log size.

The change is permanent, as long as the log is not deleted. That means, the log size is remembered across reboots.

print_version_info() -> void()
print_version_info(Prefix) -> void()

Types:

Prefix = string() | integer()

Utility function(s) to produce a formatted printout of the versions info generated by the versions1 function

This is the same as doing, e.g.:

               {ok, V} = snmp:versions1(),
               snmp:print_versions(V).

versions1() -> {ok, Info} | {error, Reason}
versions2() -> {ok, Info} | {error, Reason}

Types:

Info = [info()]
info() = term()
Reason = term()

Utility functions used to retrieve some system and application info.

The difference between the two functions is in how they get the modules to check. versions1 uses the app-file and versions2 uses the function application:get_key.

print_versions(VersionInfo) -> void()
print_versions(Prefix, VersionInfo) -> void()

Types:

VersionInfo = [version_info()]
version_info() = term()
Prefix = string() | integer()

Utility function to produce a formatted printout of the versions info generated by the versions1 and versions2 functions

Example:

               {ok, V} = snmp:versions1(),
               snmp:print_versions(V).

enable_trace() -> void()

Starts a dbg tracer that prints trace events to stdout (using plain io:format after a minor formatting).

disable_trace() -> void()

Stop the tracer.

set_trace(Targets) -> void()

Types:

Targets = target() | targets()
target() = module()
module() = atom()
targets() = [target() | {target(), target_options()}]
target_options() = [target_option()]
target_option() = {return_trace, boolean()} | {scope, scope()}
scope() = all_functions | exported_functions | function_name() | {function_name(), function_arity()}
function_name() = atom()
function_arity() = integer() >= 0

This function is used to set up default trace on function(s) for the given module or modules. The scope of the trace will be all exported functions (both the call info and the return value). Timestamp info will also be included.

reset_trace(Targets) -> void()

Types:

Targets = module() | modules()
modules() = [module()]
module() = atom()

This function is used to reset (disable) trace for the given module(s).

set_trace(Targets, Opts) -> void()

Types:

Targets = target() | targets()
target() = module()
module() = atom()
targets() = [target() | {target(), target_options()}]
target_options() = [target_option()]
target_option() = {return_trace, boolean()} | {scope, scope()}
scope() = all_functions | exported_functions | function_name() | {function_name(), function_arity()}
function_name() = atom()
function_arity() = integer() >= 0
Opts = disable | trace_options()
trace_options() = [trace_option()]
trace_option() = {timestamp, boolean()} | target_option()

This function is used to set up trace on function(s) for the given module or modules.

The example below sets up trace on the exported functions (default) of module snmp_generic and all functions of module snmp_generic_mnesia. With return values (which is default) and timestamps in both cases (which is also default):

    	  snmp:enable_trace(),
    	  snmp:set_trace([snmp_generic,
                              {snmp_generic_mnesia, [{scope, all_functions}]}]),
    	  .
    	  .
    	  .
              snmp:set_trace(snmp_generic, disable),
    	  .
    	  .
    	  .
    	  snmp:disable_trace(),

### See Also

calendar(3)